power_cps.py 925 Bytes
Newer Older
lcn's avatar
lcn committed
1 2 3
from pot_libs.mysql_util.mysql_util import MysqlUtil


ZZH's avatar
ZZH committed
4
async def load_cmpy_power(cids):
lcn's avatar
lcn committed
5
    sql = "SELECT sum(kwh) kwh FROM `company_1day_power` where cid in %s"
lcn's avatar
lcn committed
6 7 8 9 10 11 12 13 14
    async with MysqlUtil() as conn:
        data = await conn.fetchone(sql, args=(cids,))
    total_power = round(data.get("kwh") or 0, 2)
    return total_power


async def inline_power_use_info(inline_ids, month_str):
    sql = "SELECT inlid, sum(kwh) kwh, sum(charge) charge, sum(p) p FROM " \
          "`inline_1day_power` where inlid in %s  and " \
lcn's avatar
lcn committed
15 16
          f"DATE_FORMAT(create_time, '%%Y-%%m-%%d')='{month_str}' GROUP BY " \
          f"inlid"
lcn's avatar
lcn committed
17
    async with MysqlUtil() as conn:
ZZH's avatar
ZZH committed
18
        datas = await conn.fetchall(sql, args=(inline_ids,))
lcn's avatar
lcn committed
19 20 21 22 23 24 25 26 27
    inline_power_info_map = {
        i["inlid"]: {
            "kwh": i["kwh"],
            "charge": i["charge"],
            "p": i["p"],
        }
        for i in datas
    }
    return inline_power_info_map