|
@@ -57,6 +57,9 @@ class PriceCheck(FocusWidget):
|
|
|
self.data[k] = 'mixed'
|
|
|
continue
|
|
|
self.data[k] = ''
|
|
|
+ self.text_fields['rating'].set_text('')
|
|
|
+ self.text_fields['spread'].set_text('')
|
|
|
+ self.text_fields['marker'].set_text('')
|
|
|
self.update()
|
|
|
return self
|
|
|
|
|
@@ -72,7 +75,7 @@ class PriceCheck(FocusWidget):
|
|
|
|
|
|
return self
|
|
|
|
|
|
- def update_rating(self, _avg, _min, _max, price=None, quantity=None):
|
|
|
+ def update_rating(self, _avg, _min, _max, unit, price=None, quantity=None):
|
|
|
if None in (_avg, _min, _max):
|
|
|
return
|
|
|
current = None if None in (price, quantity or None) else float(price/quantity)
|
|
@@ -91,10 +94,18 @@ class PriceCheck(FocusWidget):
|
|
|
|
|
|
if current is not None and e <= current < a:
|
|
|
rating[idx] = '^'
|
|
|
- if current == _max:
|
|
|
- rating[-1] = '^'
|
|
|
- self.text_fields['spread'].set_text(f"{_min:>5.2f}{''.join(chars)}{_max:<5.2f}")
|
|
|
- self.text_fields['rating'].set_text(f"{' '*5}{''.join(rating)}{' '*5}")
|
|
|
+
|
|
|
+ if current is not None:
|
|
|
+ self.text_fields['rating'].set_text(f"{current:>5.2f}/{unit} {current/_avg - 1:>4.0%}")
|
|
|
+
|
|
|
+ if _min != _max:
|
|
|
+ if current == _max:
|
|
|
+ rating[-1] = '^'
|
|
|
+ self.text_fields['spread'].set_text(f"{_min:>5.2f}{''.join(chars)}{_max:<5.2f}")
|
|
|
+ self.text_fields['marker'].set_text(f"{' '*5}{''.join(rating)}{' '*5}")
|
|
|
+ else:
|
|
|
+ self.text_fields['spread'].set_text('')
|
|
|
+ self.text_fields['marker'].set_text('')
|
|
|
|
|
|
|
|
|
def update_historic_prices(self):
|
|
@@ -114,12 +125,12 @@ class PriceCheck(FocusWidget):
|
|
|
if None not in (sort, product, unit):
|
|
|
self.text_fields['dbview'].set_text(
|
|
|
self.query_manager.get_historic_prices(
|
|
|
- lambda *args: self.update_rating(*args, price=price, quantity=quantity),
|
|
|
+ lambda *args: self.update_rating(*args, unit, price=price, quantity=quantity),
|
|
|
sort, product, unit, organic=organic)
|
|
|
)
|
|
|
|
|
|
def __init__(self, query_manager, fields,
|
|
|
- top_pane, left_pane, right_pane, bottom_pane,
|
|
|
+ top_pane, left_pane, right_pane, bottom_pane, badge,
|
|
|
autocomplete_cb):
|
|
|
super().__init__([2,0,1], [
|
|
|
[2,0,0,], [2,0,2], [2,2,0], [2,2,2],
|
|
@@ -133,6 +144,7 @@ class PriceCheck(FocusWidget):
|
|
|
self.left_pane = left_pane
|
|
|
self.right_pane = right_pane
|
|
|
self.bottom_pane = bottom_pane
|
|
|
+ self.badge = badge
|
|
|
self.edit_fields = OrderedDict()
|
|
|
self.text_fields = OrderedDict()
|
|
|
self.data = OrderedDict()
|
|
@@ -170,12 +182,13 @@ class PriceCheck(FocusWidget):
|
|
|
urwid.connect_signal(self.buttons['clear'], 'click', lambda x: self.clear().update())
|
|
|
urwid.connect_signal(self.buttons['exit'], 'click', lambda x: show_or_exit('esc'))
|
|
|
|
|
|
- dbview, spread, rating = [ urwid.Text('') for i in range(0,3) ]
|
|
|
+ dbview, spread, rating, marker = [ urwid.Text('') for i in range(0,4) ]
|
|
|
|
|
|
self.text_fields.update({
|
|
|
'dbview': dbview,
|
|
|
'spread': spread,
|
|
|
'rating': rating,
|
|
|
+ 'marker': marker,
|
|
|
})
|
|
|
|
|
|
self.clear()
|
|
@@ -191,16 +204,16 @@ class PriceCheck(FocusWidget):
|
|
|
fields = dict([
|
|
|
(k, urwid.LineBox(urwid.AttrMap(self.edit_fields[k], 'streak'), title=k.title(), title_align='left')) for k in self.edit_fields
|
|
|
])
|
|
|
- fields['organic'] = urwid.LineBox(urwid.AttrMap(self.organic_checkbox, 'bg'))
|
|
|
+ fields['organic'] = urwid.AttrMap(self.organic_checkbox, 'bg')
|
|
|
fields.update({
|
|
|
'dbview': urwid.LineBox(
|
|
|
urwid.AttrMap(dbview, 'streak'),
|
|
|
title="Historic Prices",
|
|
|
title_align='center',
|
|
|
),
|
|
|
- 'div': urwid.Divider(),
|
|
|
'spread': spread,
|
|
|
'rating': rating,
|
|
|
+ 'marker': marker,
|
|
|
})
|
|
|
|
|
|
right_pane_widget = (16, urwid.Pile(map(
|
|
@@ -209,8 +222,19 @@ class PriceCheck(FocusWidget):
|
|
|
)))
|
|
|
left_pane_widget = (urwid.Pile(map(
|
|
|
lambda x: fields[x] if x is not None else urwid.Divider(),
|
|
|
- self.left_pane
|
|
|
+ self.left_pane,
|
|
|
)))
|
|
|
+ left_pane_widget = (urwid.Pile([
|
|
|
+ left_pane_widget,
|
|
|
+ urwid.LineBox(urwid.AttrMap(
|
|
|
+ urwid.Pile(map(
|
|
|
+ lambda x: fields[x] if x is not None else urwid.Divider(),
|
|
|
+ self.badge,
|
|
|
+ )), 'badge',),
|
|
|
+ title="Current Price",
|
|
|
+ title_align='left',
|
|
|
+ )
|
|
|
+ ]))
|
|
|
|
|
|
widget = urwid.Pile([
|
|
|
banner,
|
|
@@ -233,10 +257,10 @@ class PriceCheck(FocusWidget):
|
|
|
urwid.Divider(),
|
|
|
]))
|
|
|
],
|
|
|
- dividechars=2,
|
|
|
+ dividechars=1,
|
|
|
),
|
|
|
urwid.Columns((left_pane_widget, right_pane_widget),
|
|
|
- dividechars=2,
|
|
|
+ dividechars=1,
|
|
|
),
|
|
|
*[ fields[c] if c is not None else urwid.Divider() for c in self.bottom_pane ],
|
|
|
])
|