Repository: uclapi/uclapi

Issue:
Provide Coordinates of Each Workspaces Survey
This would help apps like UCL Assistant sort libraries by proximity to user, and navigate users to study space buildings.


Discussion:
Just to clarify, this would involve adding location data (lat, lon at least, address etc is a plus) to the survey data returned by the various workspace endpoints (e.g. `/workspaces/sensors/summary`)
Should have this done by tonight, will not be the most elegant solution though, since manual data entry is needed because we don't have any databases containing some of the buildings as they don't use the same room bookings system :( . We could get less accurate results by using the site they are closest to/in however but i'd rather maintain accuracy.

Resolving patch:
diff --git a/backend/uclapi/workspaces/occupeye/api.py b/backend/uclapi/workspaces/occupeye/api.py
--- a/backend/uclapi/workspaces/occupeye/api.py
+++ b/backend/uclapi/workspaces/occupeye/api.py
@@ -55,8 +55,20 @@ def get_surveys(self, survey_filter):
                 "active": strtobool(survey_data["active"]),
                 "start_time": survey_data["start_time"],
                 "end_time": survey_data["end_time"],
-                "staff_survey": strtobool(survey_data["staff_survey"])
-            }
+                "staff_survey": strtobool(survey_data["staff_survey"]),
+                "location": {
+                    "coordinates": {
+                        "lat": survey_data["lat"],
+                        "lng": survey_data["long"]
+                        },
+                    "address": [
+                        survey_data["address1"],
+                        survey_data["address2"],
+                        survey_data["address3"],
+                        survey_data["address4"]
+                        ]
+                    }
+                }
             # If we want to filter out staff surveys and this is a staff
             # one then we skip over it.
             if (
diff --git a/backend/uclapi/workspaces/occupeye/cache.py b/backend/uclapi/workspaces/occupeye/cache.py
--- a/backend/uclapi/workspaces/occupeye/cache.py
+++ b/backend/uclapi/workspaces/occupeye/cache.py
@@ -118,7 +118,12 @@ def cache_survey_data(self):
             staff_survey = str(
                 int(survey["SurveyID"]) in self._const.STAFF_SURVEY_IDS
             )
-
+            if survey["Name"] in self._const.SURVEY_LOCATIONS:
+                location_data = self._const.SURVEY_LOCATIONS[survey["Name"]]
+            else:
+                location_data = {
+                 "lat": "", "long": "", "address": ["", "", "", ""]
+                }
             pipeline.hmset(
                 survey_key,
                 {
@@ -127,7 +132,13 @@ def cache_survey_data(self):
                     "name": survey["Name"],
                     "start_time": survey["StartTime"],
                     "end_time": survey["EndTime"],
-                    "staff_survey": staff_survey
+                    "staff_survey": staff_survey,
+                    "lat": location_data["lat"],
+                    "long": location_data["long"],
+                    "address1": location_data["address"][0],
+                    "address2": location_data["address"][1],
+                    "address3": location_data["address"][2],
+                    "address4": location_data["address"][3]
                 }
             )
             pipeline.lpush(
diff --git a/backend/uclapi/workspaces/occupeye/constants.py b/backend/uclapi/workspaces/occupeye/constants.py
--- a/backend/uclapi/workspaces/occupeye/constants.py
+++ b/backend/uclapi/workspaces/occupeye/constants.py
@@ -84,3 +84,305 @@ class OccupEyeConstants():
     # Set a filter for surveys designed for staff only
     STAFF_SURVEY_IDS = [59]
     VALID_SURVEY_FILTERS = ["all", "staff", "student"]
+
+    # address mapping
+
+    SURVEY_LOCATIONS = {
+        "UCL Torrington 1-19 113": {
+         "lat": "51.521886", "long": "-0.134415",
+         "address": [
+            "1-19 Torrington Pl",
+            "Fitzrovia",
+            "London",
+            "WC1E 7HB"
+         ]
+        },
+        "UCL Student Centre": {
+         "lat": "51.524916", "long": "-0.132371",
+         "address": [
+            "27-28 Gordon Square",
+            "Bloomsbury",
+            "London",
+            "WC1H 0AH"
+         ]
+        },
+        "UCL SSEES Library": {
+         "lat": "51.525342", "long": "-0.131602",
+         "address": [
+            "16 Taviton St",
+            "Bloomsbury",
+            "London",
+            "WC1H 0BW"
+         ]
+        },
+        "UCL SENIT Suite": {
+         "lat": "51.524280", "long": "-0.133026",
+         "address": [
+            "Wilkins Building",
+            "Gower St",
+            "London",
+            "WC1E 6BT"
+         ]
+        },
+        "UCL Senate House Hub": {
+         "lat": "51.521094", "long": "-0.128735",
+         "address": [
+            "Senate House University of London",
+            "Malet St",
+            "London",
+            "WC1E 7HU"
+         ]
+        },
+        "UCL Science Library": {
+         "lat": "51.523556", "long": "-0.132588",
+         "address": [
+            "DMS Watson Building",
+            "Malet Place",
+            "London",
+            "WC1E 6BT"
+         ]
+        },
+        "UCL School of Pharmacy Library": {
+         "lat": "51.524967", "long": "-0.122872",
+         "address": [
+            "29-39 Brunswick Square",
+            "Bloomsbury",
+            "London",
+            "WC1N 1AX"
+         ]
+        },
+        "UCL Main Library": {
+         "lat": "51.524748", "long": "-0.133535",
+         "address": [
+            "Wilkins Building",
+            "Gower St",
+            "London",
+            "WC1E 6BT"
+         ]
+        },
+        "UCL Language & Speech Science Library": {
+         "lat": "51.525847", "long": "-0.122785",
+         "address": [
+            "2 Wakefield St",
+            "Kings Cross",
+            "London",
+            "WC1N 1PJ"
+         ]
+        },
+        "UCL Institute of Orthopaedics Library": {
+         "lat": "51.631529", "long": "-0.306551",
+         "address": [
+            "Sir Herbert Seddon Teaching Centre",
+            "Royal National Orthopaedic Hospital",
+            "Brockley Hill, Stanmore",
+            "HA7 4LP"
+         ]
+        },
+        "UCL Institute of Neurology, Queen Square Library": {
+         "lat": "51.522398", "long": "-0.122973",
+         "address": [
+            "23 Queen Square",
+            "London",
+            "WC1N 3BG",
+            ""
+         ]
+        },
+        "UCL Institute of Education Library": {
+         "lat": "51.522897", "long": "-0.127864",
+         "address": [
+            "20 Bedford Way",
+            "London",
+            "WC1H  0AL",
+            ""
+         ]
+        },
+        "UCL Institute of Archaeology Library": {
+         "lat": "51.524906", "long": "-0.131578",
+         "address": [
+            "31-34 Gordon Square",
+            "WC1H 0PY",
+            "",
+            ""
+         ]
+        },
+        "UCL Great Ormond Street Institute of Child Health Library": {
+         "lat": "51.5232287", "long": "-0.1200982",
+         "address": [
+            "30 Guilford Street",
+            "London",
+            "WC1N 1EH",
+            ""
+         ]
+        },
+        "UCL Eastman Dental Library": {
+         "lat": "51.526314", "long": "-0.117660",
+         "address": [
+            "256 Gray's Inn Road",
+            "King's Cross",
+            "London",
+            "WC1X 8LD"
+         ]
+        },
+        "UCL Ear Institute & Hearing Loss Library": {
+         "lat": "51.529268", "long": "-0.119571",
+         "address": [
+            "330-336 Grays Inn Rd",
+            "Kings Cross",
+            "London",
+            "WC1X 8EE"
+         ]
+        },
+        "UCL Cruciform Hub": {
+         "lat": "51.524054", "long": "-0.135032",
+         "address": [
+            "Cruciform Building, Gower St",
+            "Fitzrovia",
+            "London",
+            "WC1E 6BT"
+         ]
+        },
+        "UCL Christopher Ingold G20": {
+         "lat": "51.525370", "long": "-0.132171",
+         "address": [
+            "20 Gordon St",
+            "Kings Cross",
+            "London",
+            "WC1H 0AJ"
+         ]
+        },
+        "UCL chadwick B04": {
+         "lat": "51.524233", "long": "-0.134336",
+         "address": [
+            "Chadwick building, Gower St",
+            "Bloomsbury",
+            "London",
+            "WC1E 6DE"
+         ]
+        },
+        "UCL Chadwick 223": {
+         "lat": "51.524233", "long": "-0.134336",
+         "address": [
+            "Chadwick building, Gower St",
+            "Bloomsbury",
+            "London",
+            "WC1E 6DE"
+         ]
+        },
+        "UCL Bedfordway G11": {
+         "lat": "51.523857", "long": "-0.128845",
+         "address": [
+            "26 Bedford Way",
+            "Bloomsbury",
+            "London",
+            "WC1H 0AP"
+         ]
+        },
+        "UCL Bedfordway 316": {
+         "lat": "51.523857", "long": "-0.128845",
+         "address": [
+            "26 Bedford Way",
+            "Bloomsbury",
+            "London",
+            "WC1H 0AP"
+         ]
+        },
+        "UCL Bartlett Library": {
+         "lat": "51.526812", "long": "-0.129855",
+         "address": [
+            "14 Upper Woburn Pl",
+            "Bloomsbury",
+            "London",
+            "WC1H 0NN"
+         ]
+        },
+        "UCL Archaeology 501": {
+         "lat": "51.524908", "long": "-0.131575",
+         "address": [
+            "31-34 Gordon Square",
+            "Kings Cross",
+            "London",
+            "WC1H 0PY"
+         ]
+        },
+        "UCL Archaeology 117": {
+         "lat": "51.524908", "long": "-0.131575",
+         "address": [
+            "31-34 Gordon Square",
+            "Kings Cross",
+            "London",
+            "WC1H 0PY"
+         ]
+        },
+        "UCL Anatomy Hub ": {
+         "lat": "51.523625", "long": "-0.133624",
+         "address": [
+            "Anatomy Building",
+            "Gower St",
+            "London",
+            "WC1E 6XA"
+         ]
+        },
+        "UCL 23 Gordon Square  history cluster": {
+         "lat": "51.524497", "long": "-0.132115",
+         "address": [
+            "23 Gordon Square",
+            "London",
+            "WC1H 0AG",
+            ""
+         ]
+        },
+        "The Joint Library of Ophthalmology": {
+         "lat": "51.527235", "long": "-0.091205",
+         "address": [
+            "11-43 Bath Street",
+            "London",
+            "EC1V 9EL",
+            ""
+         ]
+        },
+        "Royal Free Hospital Medical Library": {
+         "lat": "51.552507", "long": "-0.165783",
+         "address": [
+            "Rowland Hill Street",
+            "Hampstead",
+            "London",
+            "NW3 2PF"
+         ]
+        },
+        "Graduate Hub - RP Dev Testing": {
+         "lat": "51.524143", "long": "-0.133525",
+         "address": [
+            "South Wing, Gower St",
+            "Kings Cross",
+            "London",
+            "WC1E 6DE",
+         ]
+        },
+        "Graduate Hub": {
+         "lat": "51.524143", "long": "-0.133525",
+         "address": [
+            "South Wing, Gower St",
+            "Kings Cross",
+            "London",
+            "WC1E 6DE",
+         ]
+        },
+        "Foster Court": {
+         "lat": "51.523555", "long": "-0.132497",
+         "address": [
+            "Foster Court, Gower St",
+            "Bloomsbury",
+            "London",
+            "WC1E 6BT"
+         ]
+        },
+        "1 Saint Martin Le Grand": {
+         "lat": "51.516380", "long": "-0.097666",
+         "address": [
+            "1 St Martin's Le Grand",
+            "London",
+            "EC1A 4NP",
+            ""
+         ]
+        }
+    }


Test patch:
diff --git a/backend/uclapi/workspaces/tests.py b/backend/uclapi/workspaces/tests.py
--- a/backend/uclapi/workspaces/tests.py
+++ b/backend/uclapi/workspaces/tests.py
@@ -91,7 +91,13 @@ def test_get_surveys(self):
                 "name": "test survey 1",
                 "start_time": "10:00",
                 "end_time": "12:00",
-                "staff_survey": str(True)
+                "staff_survey": str(True),
+                "lat": "3.14159",
+                "long": "-0.500100",
+                "address1": "some building",
+                "address2": "some street",
+                "address3": "some city",
+                "address4": "postcode please"
             }
         )
         pipeline.hmset(
@@ -102,7 +108,13 @@ def test_get_surveys(self):
                 "name": "test survey 2",
                 "start_time": "09:00",
                 "end_time": "17:00",
-                "staff_survey": str(False)
+                "staff_survey": str(False),
+                "lat": "2.14159",
+                "long": "-1.500100",
+                "address1": "some building2",
+                "address2": "some street2",
+                "address3": "some city2",
+                "address4": "postcode please2"
             }
         )
         pipeline.expire("occupeye:surveys", 20)
@@ -117,6 +129,10 @@ def test_get_surveys(self):
             len(surveys),
             2
         )
+        self.assertEqual(
+            len(surveys[0]),
+            8
+        )
 
         self.assertEqual(
             surveys[0]["id"],
@@ -138,6 +154,30 @@ def test_get_surveys(self):
         self.assertTrue(
             strtobool(str(surveys[0]["staff_survey"]))
         )
+        self.assertEqual(
+            surveys[0]["location"]["coordinates"]["lat"],
+            "3.14159"
+        )
+        self.assertEqual(
+            surveys[0]["location"]["coordinates"]["lng"],
+            "-0.500100"
+        )
+        self.assertEqual(
+            surveys[0]["location"]["address"][0],
+            "some building"
+        )
+        self.assertEqual(
+            surveys[0]["location"]["address"][1],
+            "some street"
+        )
+        self.assertEqual(
+            surveys[0]["location"]["address"][2],
+            "some city"
+        )
+        self.assertEqual(
+            surveys[0]["location"]["address"][3],
+            "postcode please"
+        )
 
         self.assertEqual(
             surveys[1]["id"],
@@ -159,3 +199,27 @@ def test_get_surveys(self):
         self.assertFalse(
             strtobool(str(surveys[1]["staff_survey"]))
         )
+        self.assertEqual(
+            surveys[1]["location"]["coordinates"]["lat"],
+            "2.14159"
+        )
+        self.assertEqual(
+            surveys[1]["location"]["coordinates"]["lng"],
+            "-1.500100"
+        )
+        self.assertEqual(
+            surveys[1]["location"]["address"][0],
+            "some building2"
+        )
+        self.assertEqual(
+            surveys[1]["location"]["address"][1],
+            "some street2"
+        )
+        self.assertEqual(
+            surveys[1]["location"]["address"][2],
+            "some city2"
+        )
+        self.assertEqual(
+            surveys[1]["location"]["address"][3],
+            "postcode please2"
+        )