def __recalculate_price_classes(self, newShop): # Get all shops in DB and append the newly added shop. shops = Shop.query_book().fetch() shops.append(newShop) prices = [] # Get a list of all prices for shop in shops: prices.append(shop.price) # Sort prices in ascending order prices.sort() # Define low and high price ranges lowPrice = 0.0 highPrice = 0.0 if(len(prices) > 0): minPrice = min(prices) maxPrice = max(prices) diff = maxPrice - minPrice lowPrice = minPrice+0.25*diff highPrice = minPrice+0.75*diff # Assign new price class and price index for every shop priceIndex = 1 for shop in shops: if shop.price < lowPrice: shop.priceClass = 1 elif shop.price > highPrice: shop.priceClass = 3 else: shop.priceClass = 2 shop.put()
def __create_shops_which_are_shown(self): amount_of_shops = 5 orde = 'Halvin' if self.request.get('order'): orde = self.request.get('order') if self.request.get('no_of_shops'): amount_of_shops = int(self.request.get('no_of_shops')) if self.request.get('area'): shops_to_show = Shop.query_book(order=orde, qo=Shop.area == self.request.get('area')).fetch(amount_of_shops) elif self.request.get('postal_code'): shops_to_show = Shop.query_book(order=orde, qo=Shop.postal_code == self.request.get('postal_code')).fetch(amount_of_shops) elif self.request.get('city'): shops_to_show = Shop.query_book(order=orde, qo=Shop.city == self.request.get('city')).fetch(amount_of_shops) else: shops_to_show = Shop.query_book(order=orde).fetch(amount_of_shops) return shops_to_show
def __get_cities_and_postal_codes(self): #TODO: This is nasty and costly one. We are just fetching all shops from the DB. shops = Shop.query_book().fetch(1000) cities = [] postal_codes = [] areas = [] for shop in shops: if shop.city not in cities: cities.append(shop.city) if shop.area not in areas: areas.append(shop.area) if shop.postal_code not in postal_codes: postal_codes.append(shop.postal_code) return sorted(cities), sorted(areas), sorted(postal_codes)