我必须比较两个温度数据帧,并使用烧瓶将其提供给用户。 我的数据在MariaDb数据库中。
所以我收到的请求Get是要比较的两个温度,即start_date,end_date和一个比较值
当我在烧瓶中收到GET请求时,我为第一个温度创建一个第一个数据帧,为第二个温度创建一个第二个数据帧
import flask
import pandas as pd
from sqlalchemy import create_engine,text
# engine creation
engine = create_engine("mysql+pymysql://user:pass@localhost/db",echo=True)
conn_sql_alchemy = engine.connect()
# function to create dataframe for
def create_dataframe(obj,start_date,end_date):
# with obj,start_date and end_date I create a request like this one
sql_sp_query = text("select timestamp,value from db.tldata where pointId = (select Id from db.device_pointList where DeviceId = ( select Id from db.device where device_instance =200) and ObjectId = 9 and object='trendLog') and timestamp between '2019-10-30 00:00:00' and '2019-10-31 23:59:59'")
#creation of dataframe
pd_datas = pd.read_sql_query(sql_sp_query,conn_sql_alchemy,index_col="timestamp")
# return dataframe
return pd_datas
# flask route
@app.route('/analyse_co/<object_sp>/<object_ai>/<start_date>/<end_date>/<difference>')
def analyse_co(object_sp,object_ai,end_date,difference):
print('creation of dataframe for object_ai')
pd_ai_datas = create_dataframe(object_ai,end_date)
print(pd_ai_datas)
print('creation of dataframe for object_sp')
pd_sp_datas = create_dataframe(object_sp,end_date)
print(pd_sp_datas)
return 'finish'
import flask
import pandas as pd
from sqlalchemy import create_engine,end_date)
print(pd_sp_datas)
return 'finish'
当我在开发模式下尝试应用程序时,得到的结果是我在等待
我在控制台上打印了两个数据框,并在网页上看到完成
控制台上的结果:
当我尝试在HTTPS中使用nginx和gunicorn的应用程序时,在日志中,我只看到第一个数据帧的创建,第二个被忽略,并且我的网页上没有错误,我看到了完成...
creation of dataframe for object_ai
2019-11-08 08:34:32,113 INFO sqlalchemy.engine.base.Engine select timestamp,value from db.tldata where pointId = (select Id from db.device_pointList where DeviceId = ( select Id from db.device where device_instance =200) and ObjectId = 7 and object='trendLog') and timestamp between '2019-10-30 00:00:00' and '2019-10-31 23:59:59'
2019-11-08 08:34:32,114 INFO sqlalchemy.engine.base.Engine {}
timestamp value
2019-10-30 00:00:00 10.475613
2019-10-30 00:15:00 8.461939
2019-10-30 00:30:00 5.507755
2019-10-30 00:45:00 8.461939
2019-10-30 01:00:00 5.507755
... ...
2019-10-31 22:45:00 10.641429
2019-10-31 23:00:00 1.556020
2019-10-31 23:15:00 11.016837
2019-10-31 23:30:00 8.576020
2019-10-31 23:45:00 9.379898
[192 rows x 1 columns]
creation of dataframe for object_sp
2019-11-08 08:34:32,222 INFO sqlalchemy.engine.base.Engine select timestamp,value from db.tldata where pointId = (select Id from db.device_pointList where DeviceId = ( select Id from db.device where device_instance =200) and ObjectId = 9 and object='trendLog') and timestamp between '2019-10-30 00:00:00' and '2019-10-31 23:59:59'
2019-11-08 08:34:32,223 INFO sqlalchemy.engine.base.Engine {}
timestamp value
2019-10-30 00:00:00 14.265137
2019-10-30 00:15:00 15.733887
2019-10-30 00:30:00 17.308594
2019-10-30 00:45:00 18.942383
2019-10-30 01:00:00 20.517090
... ...
2019-10-31 22:45:00 03.228516
2019-10-31 23:00:00 04.716309
2019-10-31 23:15:00 06.372070
2019-10-31 23:30:00 07.834961
2019-10-31 23:45:00 09.363281
[192 rows x 1 columns]
10.23.1.41 - - [08/Nov/2019 08:34:32] "GET /analyse_co/200.tl9/200.tl7/2019-10-30/2019-10-31/2 HTTP/1.1" 200 -