修复错误
All checks were successful
ci/woodpecker/push/check_format Pipeline was successful

This commit is contained in:
fuyn101 2024-10-11 20:52:18 +08:00
parent 403128d0af
commit 8795924c99

View file

@ -1,6 +1,6 @@
from datetime import datetime
from sqlalchemy import Column, ForeignKey, Integer, String, Text, create_engine
from sqlalchemy import Column, ForeignKey, Integer, String, Text, create_engine, func
from sqlalchemy.orm import declarative_base, relationship, sessionmaker
from mower.data import key_mapping
@ -242,29 +242,42 @@ class DepotManager:
def get_latest_counts_as_json():
with self.Session() as session: # 使用上下文管理器
# 你的读取逻辑
overall_max_time = (session.query(func.max(Count.time))).scalar()
self.read_time = int(overall_max_time)
top_two_times = (
session.query(Count.time)
.distinct()
.order_by(Count.time.desc()) # 按 time 降序排序
.limit(2) # 限制结果为前两行
).all()
# 提取出具体的时间值
top_two_times = [time[0] for time in top_two_times]
# 查询并筛选出 time 等于 top_two_times 中任意一个的行
counts = (
session.query(Translation, Count)
.outerjoin(Count, Translation.itemId == Count.itemId)
.filter(
Count.time.in_(top_two_times)
) # 只保留 time 在前两个最大的记录
.all()
)
result = {}
for translation, count in counts:
print(int(count.time))
category = translation.category
if category not in result:
result[category] = {}
if not count or count.count is None:
latest_count = 0
else:
latest_count = int(count.count)
self.read_time = (
int(count.time) if count.time else self.read_time
)
if category == "K未分类" and latest_count == 0:
continue
result[category][translation.name] = {
"number": latest_count,
"sort": translation.sortId,