|
@@ -45,11 +45,14 @@ def cursor_as_dict(cur):
|
|
|
#print(row)
|
|
|
yield row
|
|
|
|
|
|
-def get_data(cursor, statement, display):
|
|
|
+def get_data(cursor, statement, display=None):
|
|
|
cursor.execute(statement)
|
|
|
- yield from map(lambda x: dict([
|
|
|
- (k, display(v, k)) for k,v in x.items()
|
|
|
- ]), cursor_as_dict(cursor))
|
|
|
+ if display is not None:
|
|
|
+ yield from map(lambda x: dict(
|
|
|
+ map(lambda k: (k, display(x[k], k)), x)
|
|
|
+ ), cursor_as_dict(cursor))
|
|
|
+ else:
|
|
|
+ yield from cursor_as_dict(cursor)
|
|
|
|
|
|
def get_session_transactions(cursor, statement, display):
|
|
|
#print(cur.mogrify(statement).decode("utf-8"))
|
|
@@ -130,10 +133,12 @@ class QueryManager(object):
|
|
|
statement = get_historic_prices_statement(unit, sort=None, product=product, category=category, group=group, organic=organic, limit=limit)
|
|
|
#print(self.cursor.mogrify(statement).decode('utf-8'))
|
|
|
#input()
|
|
|
- return pd.DataFrame(get_data(self.cursor, statement, self.display))
|
|
|
+ return get_data(self.cursor, statement)
|
|
|
|
|
|
def get_historic_prices(self, rating_cb, sort, product, unit, organic=None, limit=None):
|
|
|
- df = self.get_historic_prices_data(unit, sort=sort, product=product, organic=organic, limit=limit)
|
|
|
+ df = pd.DataFrame(map(lambda x: dict(
|
|
|
+ map(lambda k: (k, self.display(x[k], k)), x)
|
|
|
+ ), self.get_historic_prices_data(unit, sort=sort, product=product, organic=organic, limit=limit)))
|
|
|
if df.empty:
|
|
|
rating_cb(None, None, None)
|
|
|
return ''
|
|
@@ -141,7 +146,7 @@ class QueryManager(object):
|
|
|
rating_cb(_avg, _min, _max)
|
|
|
|
|
|
return df.drop(labels=[
|
|
|
- 'id', 'avg', 'min', 'max', 'ts_raw', 'product', 'category', 'group'
|
|
|
+ 'id', 'avg', 'min', 'max', 'price', 'quantity', 'ts_raw', 'product', 'category', 'group'
|
|
|
], axis=1).to_string(header=[
|
|
|
'Date', 'Store', '$/unit', 'Org',
|
|
|
], justify='justify-all', max_colwidth=16, index=False)
|