from pot_libs.mysql_util.mysql_util import MysqlUtil


async def get_point_dats_dao(cid, pid):
    if pid:
        sql = f"SELECT pid,ctnum,vc FROM `point` where cid={cid} or pid={pid}"
    else:
        sql = f'SELECT pid,ctnum,vc FROM `point` where cid={cid}'
    async with MysqlUtil() as conn:
        datas = await conn.fetchall(sql)
    return datas


async def get_mean_datas_dao(pids, words, start, end):
    if pids:
        # 为了统一词缀，方便后续取数据
        mid_sql = "pid, avg(%s) ua_mean, avg(%s) freq_mean, " \
                  "avg(%s) ubl_mean,avg(%s) costtl_mean,avg(%s) thdua_mean, " \
                  "avg(%s) lf_mean" % words
        sql = f"select {mid_sql} from point_15min_electric where pid in %s " \
              f"and create_time BETWEEN '{start}' and '{end}' GROUP BY pid"
        async with MysqlUtil() as conn:
            datas = await conn.fetchall(sql, args=(pids,))
        return datas
    return []
