コード例 #1
0
 def filter_by_popularity(self, center, attractions):
     '''
         Filters attractions using knapsack.
         weights = a weighted average of estimated time spent at location and distance from center
         values = a weighted average of num checkins and overall star rating
     '''
     places, weights, values = [], [], []
     for attraction in attractions:
         place = \
             Place(attraction["name"], \
                 attraction["location"]["latitude"], \
                 attraction["location"]["longitude"], \
                 attraction)
         val = place.calculate_value(attraction["checkins"],
                                     attraction["overall_star_rating"])
         weight = place.calculate_weight(center)
         values.append(val)
         weights.append(weight)
         places.append(place)
     return self.knapsack(5000000, weights, values, len(places), places)