环境监测小数点问题修复

duizhaopin
apan_youxiang@163.com 2 years ago
parent 8f8b7cbf8a
commit 368e3003b8

@ -35,15 +35,6 @@ class Utils(object):
def get_str_datetime():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def data_float_type_convent(data_list):
new_list = []
for i in data_list:
new_dic = {}
for k,v in i.items():
new_dic[k]= v if not isinstance(v, Decimal) else float(v)
new_list.append(new_dic)
return new_list
def sql_paging_assemble(sql_all, page_param):
sql_all += ' limit ' + str((page_param.curPage - 1) * page_param.pageRows) + ',' + str(page_param.pageRows)
return sql_all

@ -34,8 +34,7 @@ def get_day_monitor():
client_id=client_id, start_time=start_time,
end_time=end_time, page_param=page_param
)
data_list = Utils.msyql_table_model(data_list)
return jsonify(Utils.true_return(data={"data_list": Utils.data_float_type_convent(data_list), "total_count": page_param.totalRecords}))
return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords}))
# 获取每日记录详情
@ -54,5 +53,4 @@ def get_day_monitor_info():
end_time=end_time,
page_param=page_param
)
data_list = Utils.msyql_table_model(data_list)
return jsonify(Utils.true_return(data={"data_list": Utils.data_float_type_convent(data_list), "total_count": page_param.totalRecords}))
return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords}))

@ -71,6 +71,7 @@ def register_blueprints(app: New_flask):
from apps.report.views import report_router
from apps.client.views import client_router
from apps.power.views import power_router
from apps.monitor.views import monitor_router
# 主概览相关
app.register_blueprint(home_router, url_prefix="/api/home")
@ -88,6 +89,8 @@ def register_blueprints(app: New_flask):
# 获取用户权限
app.register_blueprint(power_router, url_prefix="/api/power")
# 获取温湿度监控
app.register_blueprint(monitor_router, url_prefix="/api/monitor")
def create_app():

@ -55,7 +55,7 @@ class BllHumitureRecord(Repository):
def get_client_day_log(self, client_id, start_time, end_time, page_param):
filter_base = ""
if client_id:
filter_base += f" clint_id='{client_id}'"
filter_base += f" client_id='{client_id}'"
if start_time and end_time:
if filter_base:
filter_base += " and "
@ -68,8 +68,9 @@ class BllHumitureRecord(Repository):
from (
select client_id, client_name,
DATE_FORMAT(record_date,'%Y-%m-%d') day_date,
avg(temperature) avg_wd, avg(humidity) avg_sd,
avg(voc_content) avg_voc
round(avg(temperature),2) avg_wd,
round(avg(humidity),2) avg_sd,
round(avg(voc_content),2) avg_voc
from rms_humiture_record {filter_base} GROUP BY client_id, DATE_FORMAT(record_date,'%Y-%m-%d')
) a LEFT JOIN rms_client as b on a.client_id=b.client_id ORDER BY day_date desc
"""
@ -90,13 +91,14 @@ class BllHumitureRecord(Repository):
if filter_base:
filter_base += " and "
filter_base += f" record_date>= '{start_time}' and record_date<= '{end_time}' "
if filter_base:
filter_base = f" where {filter_base}"
sql_all = f"""
select
DATE_FORMAT(record_date,'%H:%i:%s') day_date,
FORMAT(temperature,2) as wd,
FORMAT(humidity,2) as sd,
FORMAT(voc_content,2) as voc
round(temperature,2) as wd,
round(humidity,2) as sd,
round(voc_content,2) as voc
from rms_humiture_record {filter_base} ORDER BY record_date
"""
try:

Loading…
Cancel
Save