강상위

Add getAvailableFacilities()

- 사용가능한 시설물 없을 시 처리포함
......@@ -27,7 +27,7 @@ import datetime
# 성공시 : tuple형태로 반환 => ( (1 ,"steven123", 7, "전자정보대학", "136호", 10, datetime.datetime(2018,12,5,12,0,0), datetime.datetime(2018,12,5,12,10,0), ), )
# 순서 : reservations_id, user_id, facility_id, location, location_detail, capacity, start_time, end_time
# 실패시 : tuple형태로 반환 => ( ("SQL Error!", ), )
# 실패시 : result[0][0]="SQL Error!"인 tuple 반환 => ( ("SQL Error!", ), )
# 사용예:
# result = getReservations("khucse123")
# reservation_start_time = result[0][3]
......@@ -50,6 +50,7 @@ def getReservations(user_id):
db.close()
# deleteReservations - 대여현황삭제 함수
# input:
# int reservations_id
......@@ -111,3 +112,49 @@ def addReservations(user_id, facility_id, start_time, end_time):
finally:
db.close()
# getAvailableFacilities - 사용가능시설물 반환함수
# input:
# string location
# int capacity
# datetime.datetime start_time
# datetime.datetime end_time
# output:
# 성공시 : tuple형태로 반환 => ( (1, "전자정보대학", "B01호", 40, "강의실", "빔프로젝터", ), )
# 순서 : facility_id, location, location_detail, capacity, facility_type, equipment
# 사용가능한 시설물이 없을 시 : result[0][0]="NoAvailableFacilites"인 tuple 반환 => ( ("NoAvailableFacilites", ), )
# 실패시 : result[0][0]="SQL Error!"인 tuple 반환 => ( ("SQL Error!", ), )
# 사용예:
# tstart = datetime.datetime(2018,12,5,12,11,12)
# tend = datetime.datetime(2018,12,5,14,20,12)
# result = getAvailableFacilities("전자정보대학", 40, tstart, tend)
# facility_id = result[0][0]
def getAvailableFacilities(location, capacity, start_time, end_time):
try:
db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8')
curs = db.cursor()
curs.execute("select facility_id, location, location_detail, capacity, facility_type, equipment from facilities where (facility_id not in(select facility_id from reservations where (start_time<=%s AND %s<end_time) OR (start_time<%s AND %s<=end_time) OR (%s<=start_time AND end_time<=%s))) AND location=%s AND %s<=capacity;",
(start_time, start_time, end_time, end_time, start_time, end_time, location, capacity))
result = curs.fetchall()
print("Fetch Success!")
# 사용 가능한 시설물이 있을 경우
if(len(result)!=0):
return result
# 사용 가능한 시설물이 없을 경우
else:
print("No Available Facilities")
return (("NoAvailableFacilites",),)
except:
print("SQL Error!")
return (("SQL Error!",),)
finally:
db.close()
......