Exemplo n.º 1
0
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
Exemplo n.º 2
0
RestaurantsNear = InitialConditions.nearbyRestaurants(24.91,60.19)  
onlineOfflineSorted = InitialConditions.onlineSort(RestaurantsNear) 
onlineOfflineSorted = InitialConditions.offlineFilterer(onlineOfflineSorted[0],onlineOfflineSorted[1])
Popularity2 = (Sorts.popularitySort(onlineOfflineSorted[0],onlineOfflineSorted[1]))

# The popularity sort function result for popularity test 2

DateTest1 = [{'blurhash': 'UGGb5p^|4@xEESt6xWWD1vS2xGkBQ;NHtixY', 'launch_date': '2020-12-24', 'location': [24.933944, 60.16461], 'name': 'Papas Octopus Factory', 'online': True, 'popularity': 0.3595856939421856}, {'blurhash': 'UFT8lemKgHpAq2cPesi%b.b.f~e?rLikf7f}', 'launch_date': '2020-12-20', 'location': [24.949907, 60.161059], 'name': 'Italian Garden', 'online': True, 'popularity': 0.0847131674543133}, {'blurhash': 'UBP^%T-rNVeoI9M{t8ozKVX1rzWA$-ozX2kB', 'launch_date': '2020-12-07', 'location': [24.929344, 60.162536], 'name': 'Tortilla Place', 'online': True, 'popularity': 0.2389385356741786}, {'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': 'UDSoswyZVqm.p%cRjLaKUgZ+k.kWrFZ%a$kX', 'launch_date': '2020-11-26', 'location': [24.938908, 60.160413], 'name': 'Salt', 'online': True, 'popularity': 0.8954324472876662}, {'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': 'U9O[r*?hI_VN*8yNniVx5^NhxTknY]MmX+tx', 'launch_date': '2020-11-23', 'location': [24.935659, 60.161989], 'name': 'Chili powder', 'online': True, 'popularity': 0.7353250033621942}, {'blurhash': 'UKD:w1{hElS_TsP4S1rv5@JC$MSzVui|ofX7', 'launch_date': '2020-11-17', 'location': [24.943237, 60.181173], 'name': 'Lovely Burger Grill', 'online': True, 'popularity': 0.03804999276898971}, {'blurhash': 'UIDbdj=cNuNH%zENWBxZ1Hb]$PkCD6%1ozt6', 'launch_date': '2020-10-28', 'location': [24.922481, 60.170761], 'name': 'Tempting Lemon Van', 'online': True, 'popularity': 0.7606795592575231}, {'blurhash': 'UKB;Mk]|I^oJ1SJD$ebHESNMj[a}-4xBNeWX', 'launch_date': '2020-10-25', 'location': [24.949733, 60.166172], 
'name': 'Bacon Basket', 'online': True, 'popularity': 0.9482709720911751}]

# The variable used to check first test for date sort

RestaurantsNear = InitialConditions.nearbyRestaurants(24.941,60.1709)  
onlineOfflineSorted = InitialConditions.onlineSort(RestaurantsNear) 
onlineOfflineSorted = InitialConditions.offlineFilterer(onlineOfflineSorted[0],onlineOfflineSorted[1])
Date = (Sorts.dateSort(onlineOfflineSorted[0],onlineOfflineSorted[1]))

# The date sort function used for the first date sort test

DateTest2 = [{'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 date sort test

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':