Skip to content

Commit

Permalink
Merge pull request #371 from uclapi/roombookings-classification-str
Browse files Browse the repository at this point in the history
Adds Roombookings Classification String
  • Loading branch information
ChristopherHammond13 committed May 27, 2018
2 parents 54658e4 + af767b9 commit 2acb3a9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
37 changes: 34 additions & 3 deletions backend/uclapi/roombookings/helpers.py
Expand Up @@ -7,7 +7,7 @@
import pytz
import redis

from django.core.exceptions import FieldError, ObjectDoesNotExist
from django.core.exceptions import FieldError
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator

import ciso8601
Expand All @@ -20,6 +20,30 @@

TOKEN_EXPIRY_TIME = 30 * 60

ROOM_TYPE_MAP = {
"AN": "Anechoic Chamber",
"CI": "Clinic Room",
"CF": "Catering Facilities",
"CFE": "Cafe",
"CL": "Cloakroom",
"CR": "Classroom",
"ER": "Equipment Room",
"IN": "Installation",
"LA": "Laboratory",
"LB": "Library",
"LT": "Lecture Theatre",
"MR": "Meeting Room",
"OF": "Office",
"PC1": "Public Cluster",
"PC2": "Public Cluster - Tutorial",
"PC3": "Public Cluster - Students",
"RC": "Reverberation Chamber",
"SS": "Social Space",
"STU": "Studio",
"TH": "Theatre",
}


def _create_page_token(query, pagination):
r = redis.StrictRedis(host=REDIS_UCLAPI_HOST)
page_data = {
Expand Down Expand Up @@ -151,13 +175,20 @@ def _parse_datetime(start_time, end_time, search_date):
def _serialize_rooms(room_set):
rooms = []
for room in room_set:
# Maps room classification to a textual version
# e.g. LT => Lecture Theatre
classification_name = ROOM_TYPE_MAP.get(
room.roomclass,
"Unknown Room Type"
)
room_to_add = {
"roomname": room.roomname,
"roomid": room.roomid,
"siteid": room.siteid,
"sitename": room.sitename,
"capacity": room.capacity,
"classification": room.roomclass,
"classification_name": classification_name,
"automated": room.automated,
"location": {
"address": [
Expand Down Expand Up @@ -308,8 +339,8 @@ def _filter_for_free_rooms(all_rooms, bookings, start, end):
for room in rooms_with_bookings:
roomid, siteid = room["roomid"], room["siteid"]
if (
(roomid, siteid) not in bookings_map
or not bookings_map[(roomid, siteid)]
(roomid, siteid) not in bookings_map or
not bookings_map[(roomid, siteid)]
):
# if room doesn't have any overlapping bookings
free_rooms.append(room)
Expand Down
Expand Up @@ -41,6 +41,7 @@ let response = `{
]
},
"classification": "ER",
"classification_name": "Equipment Room",
"sitename": "Front Lodges",
"roomname": "North Lodge 001",
"automated": "N",
Expand Down
Expand Up @@ -35,6 +35,7 @@ let response = `{
"sitename": "Main Building",
"capacity": 50,
"classification": "SS",
"classification_name": "Social Space",
"automated": "N",
"location": {
"coordinates": {
Expand Down Expand Up @@ -110,9 +111,9 @@ export default class GetRooms extends React.Component {
description="Every site (building) has a name. In some cases this is contained in the roomname as well." />
<Cell
name="classification"
requirement="optional"
example="CR"
description="The type of room. LT = Lecture Theatre, CR = Classroom, SS = Social Space, PC1 = Public Cluster." />
extra="string"
example="SS"
description="The room type ID." />
<Cell
name="capacity"
requirement="optional"
Expand Down Expand Up @@ -160,7 +161,12 @@ export default class GetRooms extends React.Component {
name="classification"
extra="string"
example="SS"
description="The type of room. LT = Lecture Theatre, CR = Classroom, SS = Social Space, PC1 = Public Cluster." />
description="The room type ID." />
<Cell
name="classification_name"
extra="string"
example="Social Space"
description="A human-readable version of the room type. AN = Anechoic Chamber, CI = Clinic Room, CF = Catering Facilities CFE = Cafe, CL = Cloakroom, CR = Classroom, ER = Equipment Room, IN = Installation, LA = Laboratory, LB = Library, LT = Lecture Theatre, MR = Meeting Room, OF = Office, PC1 = Public Cluster, PC2 = Public Cluster - Tutorial, PC3 = Public Cluster - Students, RC = Reverberation Chamber, SS = Social Space, STU = Studio, TH = Theatre. If the room type is unknown, this value will be set to 'Unknown Room Type'." />
<Cell
name="automated"
extra="string"
Expand Down

0 comments on commit 2acb3a9

Please sign in to comment.