Commit 5a55d17c authored by lcn's avatar lcn

bug修复

parent 0a5140ac
......@@ -125,7 +125,7 @@ async def compy_real_pf(cid):
pids = [r["pid"] for r in await conn.fetchall(sql, (cid,))]
if not pids:
return ""
dt = pendulum.now(tz=CST)
tstamp = dt.int_timestamp // (15 * 60) * (15 * 60)
dt = pendulum.from_timestamp(tstamp, tz=CST)
......@@ -134,12 +134,12 @@ async def compy_real_pf(cid):
sql = f"SELECT pid, create_time, pttl_mean, qttl_mean FROM " \
f"`point_15min_electric` where create_time in " \
f"('{str_dt}', '{end_dt}') and pid in %s;"
total_pttl, total_qttl = 0, 0
for r in await conn.fetchall(sql, (tuple(pids),)):
total_pttl += r["pttl_mean"]
total_qttl += r["qttl_mean"]
std_cos = math.sqrt(total_pttl * total_pttl + total_qttl * total_qttl)
return round(total_pttl / std_cos, 2) if std_cos else ""
......@@ -150,12 +150,13 @@ async def compy_lst_month_pf(cid):
inlids = [r["inlid"] for r in await conn.fetchall(sql, (cid,))]
if not inlids:
return ""
now_dt = pendulum.now(tz=CST)
cal_month = now_dt.subtract(months=1).format("YYYY-MM-DD")
cal_month = now_dt.subtract(months=1).start_of(unit="month").format(
"YYYY-MM-DD")
sql = "SELECT cos FROM algo_power_factor_result " \
"WHERE inlid in %s and month=%s"
cos_lst = [r["cos"] for r in
await conn.fetchall(sql, (inlids, cal_month))]
return min(cos_lst) if cos_lst else ""
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