def discovery(): lat = float(request.args.get('lat')) lon = float(request.args.get('lon')) RestaurantsNear = InitialConditions.nearbyRestaurants( lon, lat) #Finds restaurants within 1.5km onlineOfflineSorted = InitialConditions.onlineSort( RestaurantsNear) #Sorts into online and offline onlineOfflineSorted = InitialConditions.offlineFilterer( onlineOfflineSorted[0], onlineOfflineSorted[1]) #Removes offline if 10 or more online Popularity = (Sorts.popularitySort(onlineOfflineSorted[0], onlineOfflineSorted[1]) ) #Popularity sorted Date = (Sorts.dateSort(onlineOfflineSorted[0], onlineOfflineSorted[1])) #Date sorted Nearest = (Sorts.nearestSort(onlineOfflineSorted[0], onlineOfflineSorted[1], lon, lat)) #Nearest sorted listOfSorts = [Popularity, Date, Nearest ] #List of lists of the final results to be displayed titles = ["Popular Restaurants", "New Restaurants", "Nearby Restaurants"] result = {'sections': []} #result to be returned for i in range(3): if len(listOfSorts[i]) > 0: #Makes sure empty lists are not added result['sections'].append({ 'title': titles[i], 'restaurants': listOfSorts[i] }) #Appends non empty list return json.dumps(result) #returns result
RestaurantsNear = InitialConditions.nearbyRestaurants(24.91,60.19) onlineOfflineSorted = InitialConditions.onlineSort(RestaurantsNear) onlineOfflineSorted = InitialConditions.offlineFilterer(onlineOfflineSorted[0],onlineOfflineSorted[1]) Date2 = (Sorts.dateSort(onlineOfflineSorted[0],onlineOfflineSorted[1])) # The date sort function used for the second date sort test NearestTest1 = [{'blurhash': 'UBO1xu~SIWNdUWTun6soDVMltPtMU{n5tQR,', 'launch_date': '2020-04-24', 'location': [24.942847, 60.169778], 'name': 'Fictive Olive Mafia', 'online': True, 'popularity': 0.2233905847654424}, {'blurhash': 'UI97ru%EIvocNMa#t2oc0YIvxnR.-hocIvWF', 'launch_date': '2020-01-20', 'location': [24.938353, 60.172132], 'name': 'Chili Pepper', 'online': True, 'popularity': 0.8934866288893477}, {'blurhash': 'UGB|33~3I;Ic-{%DjcRo0|Ef$%xWIMM-kQxn', 'launch_date': '2020-11-29', 'location': [24.93623, 60.169935], 'name': 'Fake Onion', 'online': True, 'popularity': 0.23036375831315775}, {'blurhash': 'UNDVs2}5JWOFFyt2$eRoGZKPniw[VyRoS}t2', 'launch_date': '2020-05-04', 'location': [24.945715, 60.167827], 'name': 'Real Pizza Factory', 'online': True, 'popularity': 0.5045108175927286}, {'blurhash': 'UGKp#o@uCO#SLwTIrYkBC~X7rsXRduSgb[nP', 'launch_date': '2020-11-24', 'location': [24.950464, 60.170267], 'name': 'Butter Hotel', 'online': True, 'popularity': 0.6251161053931533}, {'blurhash': 'UNB[ly,]JisW%2xHWUju32OTwhSeNGR*s:ju', 'launch_date': '2020-08-19', 'location': [24.938521, 60.166018], 'name': 'Fictive Spinach', 'online': True, 'popularity': 0.032796935023081085}, {'blurhash': 'UNDLy=}iEmRqT1S6nis*7uOnwKW=RDaetKk8', 'launch_date': '2020-04-15', 'location': [24.931383, 60.172675], 'name': 'Papas Burger Party', 'online': True, 'popularity': 0.8212304387029502}, {'blurhash': 'UAN=8k?LS~M:ErJFs%t0MDMWRqo@%BxSV{RX', 'launch_date': '2020-04-20', 'location': [24.938082, 60.17626], 'name': 'Sea Chain', 'online': True, 'popularity': 0.956990414084132}, {'blurhash': 'UHSFWrsTWobEpLX7jajYROWEkCkCZ_n,a$bJ', 'launch_date': '2020-08-04', 'location': [24.943179, 60.176732], 'name': 'Awesome Garlic Mafia', 'online': True, 'popularity': 0.4964753603220507}, {'blurhash': 'UBM[YD{FFvO*YBO$RRw6C#K}rracQ_i+x[b[', 'launch_date': '2020-02-18', 'location': [24.93755, 60.165211], 'name': 'Pineapple Plus', 'online': True, 'popularity': 0.4140474136156465}] # The variable used for the first nearest sort test RestaurantsNear = InitialConditions.nearbyRestaurants(24.941,60.1709) onlineOfflineSorted = InitialConditions.onlineSort(RestaurantsNear) onlineOfflineSorted = InitialConditions.offlineFilterer(onlineOfflineSorted[0],onlineOfflineSorted[1]) Nearest = (Sorts.nearestSort(onlineOfflineSorted[0],onlineOfflineSorted[1],24.941,60.1709)) # The nearest sort function used for the first nearest sort test NearestTest2 = [{'blurhash': 'UKNaZ$xnRXaQO5WEt2f7DfRpo?k8MptKV}ou', 'launch_date': '2020-03-14', 'location': [24.924752, 60.179213], 'name': 'Charming Pepper Emporium', 'online': True, 'popularity': 0.741748846018373}] # The variable used for the second nearest sort test RestaurantsNear = InitialConditions.nearbyRestaurants(24.91,60.19) onlineOfflineSorted = InitialConditions.onlineSort(RestaurantsNear) onlineOfflineSorted = InitialConditions.offlineFilterer(onlineOfflineSorted[0],onlineOfflineSorted[1]) Nearest2 = (Sorts.nearestSort(onlineOfflineSorted[0],onlineOfflineSorted[1],24.91,60.19)) # The nearest sort function used for the second nearest sort test