feat: 初始化项目并提交一次代码
This commit is contained in:
48
services/statistics.py
Normal file
48
services/statistics.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import time
|
||||
|
||||
import aiosqlite
|
||||
from database import get_conn
|
||||
|
||||
|
||||
async def get_ammeter_left_ele(limit=24):
|
||||
async with get_conn() as conn:
|
||||
conn.row_factory = aiosqlite.Row
|
||||
cursor = await conn.execute(
|
||||
"""
|
||||
SELECT created_at, left_ele
|
||||
FROM ammeter_usage
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ?
|
||||
""",
|
||||
(limit,),
|
||||
)
|
||||
rows = await cursor.fetchall()
|
||||
|
||||
rows.reverse()
|
||||
|
||||
times = [time.strftime("%H:%M", time.localtime(r[0] / 1000)) for r in rows]
|
||||
values = [r[1] for r in rows]
|
||||
|
||||
return times, values
|
||||
|
||||
|
||||
async def get_water_left(limit=24):
|
||||
async with get_conn() as conn:
|
||||
conn.row_factory = aiosqlite.Row
|
||||
cursor = await conn.execute(
|
||||
"""
|
||||
SELECT created_at, left_water
|
||||
FROM water_usage
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ?
|
||||
""",
|
||||
(limit,),
|
||||
)
|
||||
rows = await cursor.fetchall()
|
||||
|
||||
rows.reverse()
|
||||
|
||||
times = [time.strftime("%H:%M", time.localtime(r[0] / 1000)) for r in rows]
|
||||
values = [r[1] for r in rows]
|
||||
|
||||
return times, values
|
||||
Reference in New Issue
Block a user