-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMealMatcher.py
More file actions
65 lines (51 loc) · 1.97 KB
/
MealMatcher.py
File metadata and controls
65 lines (51 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import DBMockUp
import pdb
class MealMatcher(object):
def __init__(self, log):
self.db = DBMockUp.DBMockUp()
self.log = log
def get_meal_offer(self, meal_name, location, cook):
# meal not available
filter_list = {
'meal':meal_name,
'location':location,
'cook':cook
}
orders=self.db.get_orders()
for k,v in filter_list.items():
self.log.debug('filter %s for %s' % (k,v))
orders = self.filter_orders(orders,k,v)
if len(orders)==0:
return []
for i in range(len(orders)):
orders[i]['mealName']=self.db.get_name_of('Meals','description',orders[i]['meal'])
orders[i]['fileName']=self.db.get_name_of('Meals','name',orders[i]['meal'])
orders[i]['cookName']=self.db.get_name_of('Users','name',orders[i]['cook'])
orders[i]['locationName']=self.db.get_name_of('Locations','name',orders[i]['location'])
return orders
return orders
def filter_orders(self, orders, filter_string, filter_id):
self.log.debug('filter %s with %s: %s' %(orders,filter_string, filter_id))
# filter is null
if not filter_id:
return orders
filtered = []
for o in orders:
if filter_string not in o.keys():
continue
elif o[filter_string]!=self.get_meal_id(filter_id):
continue
elif o['buyer']:
continue
filtered.append(o)
return filtered
def get_meal_id(self, meal_name):
meals = [m for m in self.db.get_meals() if m['id']==meal_name]
if len(meals)==0:
return -1
return meals[0]['id']
def get_location_id(self, location_name):
locations = [m for m in self.db.get_locations() if m['id']==location_name]
if len(locations)==0:
return -1
return locations[0]['id']