|
@@ -19,6 +19,7 @@ from urwid import (
|
|
|
Text,
|
|
|
)
|
|
|
|
|
|
+from ..data.dataframe_util import get_caption, get_time_range, stats
|
|
|
from ..widgets import (
|
|
|
AutoCompleteEdit,
|
|
|
AutoCompleteFloatEdit,
|
|
@@ -118,31 +119,15 @@ class PriceCheck(FocusWidget):
|
|
|
).truncate(
|
|
|
before=max(0, len(df.index)-self.graph._canvas_width)
|
|
|
)
|
|
|
- data = df[['$/unit','quantity']].apply(
|
|
|
- lambda x: (float(x['$/unit']), float(x['quantity'])),
|
|
|
+ data = df[['price', '$/unit','quantity']].apply(
|
|
|
+ lambda x: (float(x['price']), float(x['$/unit']), float(x['quantity'])),
|
|
|
axis=1, result_type='broadcast'
|
|
|
)
|
|
|
- data['avg'] = (data['$/unit']*data['quantity']).sum()/data['quantity'].sum()
|
|
|
- data_max = data.max()['$/unit']
|
|
|
- assert len(data['avg'].unique()) == 1
|
|
|
norm = [ (x,) for x in data['$/unit'] ]
|
|
|
- self.graph.set_data(norm, data_max,
|
|
|
- vscale=list(map(float, [
|
|
|
- data['$/unit'].min(),
|
|
|
- data['$/unit'].median(),
|
|
|
- data['avg'].iloc[0],
|
|
|
- data_max
|
|
|
- ]))
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
- date_strlen = (self.graph.canvas_width - 20)
|
|
|
- ex = "─" if date_strlen % 2 else ""
|
|
|
- plen = date_strlen//2
|
|
|
- caption = f"{df['ts_raw'].min():%d/%m/%Y}"
|
|
|
- caption += f"{{p:>{plen}}}{ex}{{p:<{plen}}}".format(
|
|
|
- p="─")
|
|
|
- caption += f"{df['ts_raw'].max():%d/%m/%Y}"
|
|
|
+ scale = stats(data, 'price', 'quantity', '$/unit')
|
|
|
+ self.graph.set_data(norm, scale[-1], vscale=scale)
|
|
|
+ time_range = get_time_range(df, 'ts_raw')
|
|
|
+ caption = get_caption(time_range, self.graph.canvas_width)
|
|
|
self.graph.set_caption(caption)
|
|
|
|
|
|
def update_historic_prices(self, data):
|
|
@@ -177,10 +162,11 @@ class PriceCheck(FocusWidget):
|
|
|
]
|
|
|
self.rating.update_rating(_avg, _min, _max, unit, price=price, quantity=quantity)
|
|
|
|
|
|
+ self.update_graph(df)
|
|
|
self.text_fields['dbview'].set_text(
|
|
|
get_historic_prices(df)
|
|
|
)
|
|
|
- self.update_graph(df)
|
|
|
+
|
|
|
|
|
|
def __init__(self,
|
|
|
activity_manager: ActivityManager,
|