Metrics only lot
This commit is contained in:
parent
cecbf9d04d
commit
10a1e23a5d
|
@ -1,4 +1,5 @@
|
|||
import csv
|
||||
import json
|
||||
import enum
|
||||
import uuid
|
||||
import time
|
||||
|
@ -150,12 +151,13 @@ class DevicesDocumentView(DeviceView):
|
|||
class ActionsDocumentView(DeviceView):
|
||||
@cache(datetime.timedelta(minutes=1))
|
||||
def find(self, args: dict):
|
||||
query = (x for x in self.query(args))
|
||||
filters = json.loads(request.args.get('filter', {}))
|
||||
ids = filters.get('ids', [])
|
||||
query = self.query(args).filter(Device.id.in_(ids))
|
||||
return self.generate_post_csv(query)
|
||||
|
||||
def generate_post_csv(self, query):
|
||||
"""Get device query and put information in csv format."""
|
||||
# import pdb; pdb.set_trace()
|
||||
data = StringIO()
|
||||
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"')
|
||||
first = True
|
||||
|
@ -170,6 +172,13 @@ class ActionsDocumentView(DeviceView):
|
|||
cw.writerow(d.values())
|
||||
query_trade = Trade.query.filter(Trade.devices.any(Device.id.in_(devs_id))).all()
|
||||
|
||||
lot_id = request.args.get('lot')
|
||||
if lot_id and not query_trade:
|
||||
lot = Lot.query.filter_by(id=lot_id).one()
|
||||
if hasattr(lot, "trade") and lot.trade:
|
||||
if g.user in [lot.trade.user_from, lot.trade.user_to]:
|
||||
query_trade = [lot.trade]
|
||||
|
||||
for trade in query_trade:
|
||||
data_rows = trade.get_metrics()
|
||||
for row in data_rows:
|
||||
|
|
Reference in New Issue