Metrics only lot
This commit is contained in:
parent
cecbf9d04d
commit
10a1e23a5d
|
@ -1,4 +1,5 @@
|
||||||
import csv
|
import csv
|
||||||
|
import json
|
||||||
import enum
|
import enum
|
||||||
import uuid
|
import uuid
|
||||||
import time
|
import time
|
||||||
|
@ -150,12 +151,13 @@ class DevicesDocumentView(DeviceView):
|
||||||
class ActionsDocumentView(DeviceView):
|
class ActionsDocumentView(DeviceView):
|
||||||
@cache(datetime.timedelta(minutes=1))
|
@cache(datetime.timedelta(minutes=1))
|
||||||
def find(self, args: dict):
|
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)
|
return self.generate_post_csv(query)
|
||||||
|
|
||||||
def generate_post_csv(self, query):
|
def generate_post_csv(self, query):
|
||||||
"""Get device query and put information in csv format."""
|
"""Get device query and put information in csv format."""
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
data = StringIO()
|
data = StringIO()
|
||||||
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"')
|
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"')
|
||||||
first = True
|
first = True
|
||||||
|
@ -170,6 +172,13 @@ class ActionsDocumentView(DeviceView):
|
||||||
cw.writerow(d.values())
|
cw.writerow(d.values())
|
||||||
query_trade = Trade.query.filter(Trade.devices.any(Device.id.in_(devs_id))).all()
|
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:
|
for trade in query_trade:
|
||||||
data_rows = trade.get_metrics()
|
data_rows = trade.get_metrics()
|
||||||
for row in data_rows:
|
for row in data_rows:
|
||||||
|
|
Reference in New Issue