1- from datetime import datetime , time
1+ from datetime import datetime
22
33from flask import Blueprint
44from pony import orm
@@ -15,6 +15,7 @@ def charts_blueprint(_context: Context):
1515 @blueprint .route ("/attribute/<int_list:attribute_ids>/<string:date>" )
1616 @orm .db_session
1717 def attribute (attribute_ids , date ):
18+ print ("Time of request:\t " , datetime .now ().time ())
1819 charts_data = []
1920
2021 date = datetime .fromisoformat (date ).date () if date else datetime .now ().date ()
@@ -24,27 +25,32 @@ def attribute(attribute_ids, date):
2425 lambda data_unit : data_unit .attribute .id == attribute_id and data_unit .date == date
2526 )
2627
28+ print ("Time of query:\t \t " , datetime .now ().time ())
29+
2730 if not data_units :
2831 continue
2932
33+ first_data_unit = data_units .first ()
34+ attr = first_data_unit .attribute
35+
3036 charts_data .append (
3137 {
3238 "id" : attribute_id ,
33- "label" : data_units . first (). attribute . label or data_units . first (). attribute .name ,
34- "unit" : data_units . first (). attribute .unit ,
35- "color" : data_units . first (). attribute .color ,
39+ "label" : attr . label or attr .name ,
40+ "unit" : attr .unit ,
41+ "color" : attr .color ,
3642 "data" : [
3743 {
38- "x" : int (
39- datetime .combine (data_unit .date , time .fromisoformat (str (data_unit .time ))).timestamp ()
40- ),
44+ "x" : datetime .fromisoformat (f"{ data_unit .date } { data_unit .time [:- 7 ]} " ).timestamp (),
4145 "y" : data_unit .value ,
4246 }
4347 for data_unit in data_units
4448 ],
4549 }
4650 )
4751
52+ print ("Time of processing:\t " , datetime .now ().time ())
53+
4854 # Return charts data for Chart.js
4955 return charts_data
5056
0 commit comments