|
@@ -229,8 +229,8 @@ class PriceCheck(urwid.WidgetPlaceholder):
|
|
|
def update_rating(self, _avg, _min, _max, price=None, quantity=None):
|
|
|
if None in (_avg, _min, _max):
|
|
|
return
|
|
|
- current = None if None in (price, quantity) else float(price/quantity)
|
|
|
- size = 16
|
|
|
+ current = None if None in (price, quantity or None) else float(price/quantity)
|
|
|
+ size = 14
|
|
|
chars = ['|', *['-']*(size - 2), '|' ]
|
|
|
rating = [' ']*len(chars)
|
|
|
_min, _max = min(_min, current or _min), max(_max, current or _max)
|
|
@@ -238,16 +238,17 @@ class PriceCheck(urwid.WidgetPlaceholder):
|
|
|
|
|
|
for idx, (e, a) in enumerate(zip(ls, ls[1:])):
|
|
|
if e <= _avg < a:
|
|
|
- chars[max(idx-4,0)] = '['
|
|
|
- chars[min(idx+4,len(chars)-1)] = ']'
|
|
|
- for _idx, c in enumerate(f'{_avg:>7.2f}'):
|
|
|
- chars[max(idx-3+_idx,0)] = c
|
|
|
+ for c, (_idx,_) in zip('[{}]'.format(''.join(list(f'{_avg:>5.2f}')[:idx-3+5])), filter(lambda x: idx-3 < x[0], enumerate(chars))):
|
|
|
+ chars[_idx] = c
|
|
|
+ chars[0] = '|'
|
|
|
+ chars[-1] = '|'
|
|
|
|
|
|
if current is not None and e <= current < a:
|
|
|
rating[idx] = '^'
|
|
|
-
|
|
|
- self.text_fields['spread'].set_text(f"{_min:>7.2f}{''.join(chars)}{_max:<7.2f}")
|
|
|
- self.text_fields['rating'].set_text(f"{' '*7}{''.join(rating)}{' '*7}")
|
|
|
+ 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}")
|
|
|
|
|
|
|
|
|
def update_historic_prices(self):
|
|
@@ -255,14 +256,14 @@ class PriceCheck(urwid.WidgetPlaceholder):
|
|
|
sort = '$/unit' if self.buttons['sort_price'].state else 'ts'
|
|
|
product, unit = self.data['product'] or None, self.data['unit'] or None
|
|
|
try:
|
|
|
- price = Decimal(self.data['price']) or None
|
|
|
+ price = Decimal(self.data['price'])
|
|
|
except InvalidOperation:
|
|
|
price = None
|
|
|
|
|
|
try:
|
|
|
- quantity = Decimal(self.data['quantity']) or None
|
|
|
+ quantity = Decimal(self.data['quantity'])
|
|
|
except InvalidOperation:
|
|
|
- price = None
|
|
|
+ quantity = None
|
|
|
|
|
|
if None not in (sort, product, unit):
|
|
|
self.text_fields['dbview'].set_text(
|