/stat统计数据
This commit is contained in:
parent
2d04b55152
commit
6cb1544c7d
1 changed files with 6 additions and 16 deletions
22
main.py
22
main.py
|
@ -87,21 +87,11 @@ def upload(data: PostData, session: SessionDep) -> int:
|
||||||
return ratio
|
return ratio
|
||||||
|
|
||||||
|
|
||||||
@app.get("/user/today")
|
@app.get("/stat")
|
||||||
def user_today(session: SessionDep) -> dict[str, int]:
|
def user_today(session: SessionDep):
|
||||||
main_set = set()
|
data = {}
|
||||||
fast_set = set()
|
|
||||||
slow_set = set()
|
|
||||||
yesterday = datetime.now(timezone.utc) - timedelta(days=1)
|
yesterday = datetime.now(timezone.utc) - timedelta(days=1)
|
||||||
for system in session.exec(select(System).where(System.upload_time > yesterday)):
|
for system in session.exec(select(System).where(System.upload_time > yesterday)):
|
||||||
if system.branch == "main":
|
if system.branch in ["main", "fast", "slow"]:
|
||||||
main_set.add(system.user_id)
|
data[system.user_id] = [system.branch, system.commit]
|
||||||
elif system.branch == "fast" and system.user_id not in main_set:
|
return list(data.values())
|
||||||
fast_set.add(system.user_id)
|
|
||||||
elif (
|
|
||||||
system.branch == "slow"
|
|
||||||
and system.user_id not in main_set
|
|
||||||
and system.user_id not in fast_set
|
|
||||||
):
|
|
||||||
slow_set.add(system.user_id)
|
|
||||||
return {"main": len(main_set), "fast": len(fast_set), "slow": len(slow_set)}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue