feat: 初始化项目并提交一次代码

This commit is contained in:
2025-12-17 20:25:15 +08:00
commit 355098025f
19 changed files with 585 additions and 0 deletions

48
services/statistics.py Normal file
View 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