Commit 9b02f7be authored by lcn's avatar lcn

修复bug

parent 81c24bd9
...@@ -156,6 +156,8 @@ async def location_stats_statics_new15(table_name, cid, start, end): ...@@ -156,6 +156,8 @@ async def location_stats_statics_new15(table_name, cid, start, end):
location_map = {} location_map = {}
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
locations = await conn.fetchall(sql, args=(cid, )) locations = await conn.fetchall(sql, args=(cid, ))
if not locations:
return location_map
for loca in locations: for loca in locations:
location_map[loca["lid"]] = loca location_map[loca["lid"]] = loca
datas_sql = f"SELECT * from {table_name} where lid in %s and create_time" \ datas_sql = f"SELECT * from {table_name} where lid in %s and create_time" \
......
from pot_libs.es_util.es_utils import EsUtil from pot_libs.es_util.es_utils import EsUtil
from pot_libs.mysql_util.mysql_util import MysqlUtil
from pot_libs.utils.pendulum_wrapper import my_pendulum from pot_libs.utils.pendulum_wrapper import my_pendulum
from unify_api.utils.time_format import get_start_end_by_tz_time_new
def convert_es_str(str1: object) -> object: def convert_es_str(str1: object) -> object:
...@@ -64,6 +66,20 @@ async def query_search_kwh_p(cid, start, end, interval): ...@@ -64,6 +66,20 @@ async def query_search_kwh_p(cid, start, end, interval):
return es_re["aggregations"]["quarter_time"]["buckets"] return es_re["aggregations"]["quarter_time"]["buckets"]
async def query_search_kwh_p_new15(cid, start, end):
start, _ = get_start_end_by_tz_time_new(start)
_, end = get_start_end_by_tz_time_new(end)
sql = f"""
select p,kwh,create_time from company_15min_power
where cid = %s and create_time BETWEEN %s and %s
order by create_time asc
"""
async with MysqlUtil() as conn:
datas = await conn.fetchall(sql=sql,
args=(cid, start, end))
return datas
async def query_spfv_price(cid, start, end): async def query_spfv_price(cid, start, end):
query_body = { query_body = {
"query": { "query": {
...@@ -103,3 +119,15 @@ async def query_spfv_price(cid, start, end): ...@@ -103,3 +119,15 @@ async def query_spfv_price(cid, start, end):
es_re = await es.search_origin(body=query_body, es_re = await es.search_origin(body=query_body,
index="poweriot_company_15min_power") index="poweriot_company_15min_power")
return es_re["aggregations"]["charge"]["avg"], es_re["aggregations"]["kwh"]["avg"] return es_re["aggregations"]["charge"]["avg"], es_re["aggregations"]["kwh"]["avg"]
async def query_spfv_price_new15(cid, start, end):
start, _ = get_start_end_by_tz_time_new(start)
_, end = get_start_end_by_tz_time_new(end)
sql = f"""
select avg(charge) charge,avg(kwh) kwh from company_15min_power
where cid = %s and create_time BETWEEN %s and %s
"""
async with MysqlUtil() as conn:
data = await conn.fetchone(sql=sql, args=(cid, start, end))
return data.get('charge', 0), data.get('kwh', 0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment