|
@@ -199,7 +199,6 @@ class RecipeEditor(FocusWidget):
|
|
self.instructions.set_edit_text('')
|
|
self.instructions.set_edit_text('')
|
|
self.fname.set_edit_text('')
|
|
self.fname.set_edit_text('')
|
|
self.notice.set_text('')
|
|
self.notice.set_text('')
|
|
- self.feeds.edit_text = ''
|
|
|
|
return self.update()
|
|
return self.update()
|
|
|
|
|
|
def init_ingredients(self):
|
|
def init_ingredients(self):
|
|
@@ -271,10 +270,9 @@ class RecipeEditor(FocusWidget):
|
|
lambda x: None not in map(lambda x: x or None, x), [
|
|
lambda x: None not in map(lambda x: x or None, x), [
|
|
list(map(lambda x: x.get_edit_text(), x)) for x in self.ingredients
|
|
list(map(lambda x: x.get_edit_text(), x)) for x in self.ingredients
|
|
])))
|
|
])))
|
|
- serves = self.feeds.value()
|
|
|
|
if serves:
|
|
if serves:
|
|
- n, d = serves.as_integer_ratio()
|
|
|
|
- yml['feeds'] = float(self.feeds.value()) if d != 1 else n
|
|
|
|
|
|
+ n, d = self.feeds.as_integer_ratio()
|
|
|
|
+ yml['feeds'] = float(self.feeds) if d != 1 else n
|
|
else:
|
|
else:
|
|
yml['feeds'] = None
|
|
yml['feeds'] = None
|
|
yml['instructions'] = literal_str('\n'.join(map(
|
|
yml['instructions'] = literal_str('\n'.join(map(
|
|
@@ -292,7 +290,6 @@ class RecipeEditor(FocusWidget):
|
|
data = self.data
|
|
data = self.data
|
|
organic = None if data['organic'] == 'mixed' else data['organic']
|
|
organic = None if data['organic'] == 'mixed' else data['organic']
|
|
sort = 'ts'
|
|
sort = 'ts'
|
|
- not_found = '='
|
|
|
|
for r in filter(
|
|
for r in filter(
|
|
lambda x: next(filter(lambda x: x is widget or widget is None, x), None),
|
|
lambda x: next(filter(lambda x: x is widget or widget is None, x), None),
|
|
self.ingredients
|
|
self.ingredients
|
|
@@ -308,15 +305,16 @@ class RecipeEditor(FocusWidget):
|
|
continue
|
|
continue
|
|
|
|
|
|
if None in (sort or None, product or None, unit or None, quantity or None):
|
|
if None in (sort or None, product or None, unit or None, quantity or None):
|
|
- not_found = '>'
|
|
|
|
|
|
+ self.found[None] = '>'
|
|
continue
|
|
continue
|
|
|
|
+ self.found[product] = '='
|
|
|
|
|
|
df = self.query_manager.get_historic_prices_data(unit, sort=sort, product=product, organic=organic)
|
|
df = self.query_manager.get_historic_prices_data(unit, sort=sort, product=product, organic=organic)
|
|
if df.empty:
|
|
if df.empty:
|
|
- not_found = '~' if not_found == '=' else not_found
|
|
|
|
|
|
+ self.found[product] = '~'
|
|
df = self.query_manager.get_historic_prices_data(unit, sort=sort, product=product, organic=None)
|
|
df = self.query_manager.get_historic_prices_data(unit, sort=sort, product=product, organic=None)
|
|
if df.empty:
|
|
if df.empty:
|
|
- not_found = '>'
|
|
|
|
|
|
+ self.found[product] = '>'
|
|
continue
|
|
continue
|
|
|
|
|
|
assert len(df['avg'].unique()) == 1, f"There should be only one average price: {df['avg'].unique()}"
|
|
assert len(df['avg'].unique()) == 1, f"There should be only one average price: {df['avg'].unique()}"
|
|
@@ -324,13 +322,19 @@ class RecipeEditor(FocusWidget):
|
|
_last, _avg, _min, _max = list(
|
|
_last, _avg, _min, _max = list(
|
|
map(Decimal,df[['last', 'avg','min','max']].iloc[0])
|
|
map(Decimal,df[['last', 'avg','min','max']].iloc[0])
|
|
)
|
|
)
|
|
- self.prices[r[0].get_edit_text()] = [
|
|
|
|
|
|
+ self.prices[product] = [
|
|
i*quantity for i in (_last, _min, _avg, _max)
|
|
i*quantity for i in (_last, _min, _avg, _max)
|
|
]
|
|
]
|
|
|
|
|
|
for k in list(self.prices):
|
|
for k in list(self.prices):
|
|
if k not in map(lambda x: x[0].get_edit_text(), self.ingredients):
|
|
if k not in map(lambda x: x[0].get_edit_text(), self.ingredients):
|
|
del self.prices[k]
|
|
del self.prices[k]
|
|
|
|
+ for k in list(self.found):
|
|
|
|
+ if k not in [
|
|
|
|
+ *map(lambda x: x[0].get_edit_text(), self.ingredients),
|
|
|
|
+ None
|
|
|
|
+ ]:
|
|
|
|
+ del self.found[k]
|
|
|
|
|
|
price = [
|
|
price = [
|
|
sum([self.prices[p][i] for p in self.prices]) for i in range(4)
|
|
sum([self.prices[p][i] for p in self.prices]) for i in range(4)
|
|
@@ -339,8 +343,16 @@ class RecipeEditor(FocusWidget):
|
|
lambda x: self.price_as[x[1]].state,
|
|
lambda x: self.price_as[x[1]].state,
|
|
enumerate(self.price_as)
|
|
enumerate(self.price_as)
|
|
))[0]
|
|
))[0]
|
|
|
|
+ not_found = next(
|
|
|
|
+ filter(lambda x: x == '>', self.found.values()), next(
|
|
|
|
+ filter(lambda x: x == '~', self.found.values()), next(
|
|
|
|
+ filter(lambda x: x == '=', self.found.values())
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ )
|
|
self.price.set_text(
|
|
self.price.set_text(
|
|
f'Cost: {not_found}{price[price_as]}'
|
|
f'Cost: {not_found}{price[price_as]}'
|
|
|
|
+ f', Per Serve: {not_found}{price[price_as]/self.feeds}'
|
|
)
|
|
)
|
|
notice = ''
|
|
notice = ''
|
|
ingredients = list(filter(lambda x: x, map(lambda x: x[0].get_edit_text(), self.ingredients)))
|
|
ingredients = list(filter(lambda x: x, map(lambda x: x[0].get_edit_text(), self.ingredients)))
|
|
@@ -381,6 +393,7 @@ class RecipeEditor(FocusWidget):
|
|
connect_signal(b, 'postchange', lambda w,_: self.update(w))
|
|
connect_signal(b, 'postchange', lambda w,_: self.update(w))
|
|
self.fname = Edit('', fname)
|
|
self.fname = Edit('', fname)
|
|
self.prices = dict()
|
|
self.prices = dict()
|
|
|
|
+ self.found = dict()
|
|
self.components = dict()
|
|
self.components = dict()
|
|
self.buttons = {
|
|
self.buttons = {
|
|
'clear': Button(('streak', 'Clear')),
|
|
'clear': Button(('streak', 'Clear')),
|
|
@@ -398,15 +411,16 @@ class RecipeEditor(FocusWidget):
|
|
|
|
|
|
self.organic = NoTabCheckBox(('bg', "Organic"), state='mixed')
|
|
self.organic = NoTabCheckBox(('bg', "Organic"), state='mixed')
|
|
self.instructions = Edit('', edit_text=recipe['instructions'] or u'', multiline=True, allow_tab=True)
|
|
self.instructions = Edit('', edit_text=recipe['instructions'] or u'', multiline=True, allow_tab=True)
|
|
- self.feeds = FloatEdit(f'Serves: ', f"{recipe['feeds']}" or '')
|
|
|
|
- self.price = Text(f"Cost: 0")
|
|
|
|
|
|
+ self.feeds = Decimal(recipe['feeds'])
|
|
|
|
+ self.price = Text('')
|
|
self.notice = Text('')
|
|
self.notice = Text('')
|
|
|
|
+ feeds = FloatEdit(f'Serves: ', self.feeds)
|
|
|
|
|
|
bottom_pane = [
|
|
bottom_pane = [
|
|
self.organic,
|
|
self.organic,
|
|
LineBox(self.instructions, title=f'Instructions'),
|
|
LineBox(self.instructions, title=f'Instructions'),
|
|
- self.feeds,
|
|
|
|
- Columns([self.price, *[(9, w) for _,w in self.price_as.items()], Divider()]),
|
|
|
|
|
|
+ feeds,
|
|
|
|
+ Columns([('weight', 2, self.price), *[(9, w) for _,w in self.price_as.items()], Divider()]),
|
|
LineBox(self.notice, title='Errors', title_align='left'),
|
|
LineBox(self.notice, title='Errors', title_align='left'),
|
|
]
|
|
]
|
|
self.activity_manager = activity_manager
|
|
self.activity_manager = activity_manager
|