/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
|
||||
|
||||
|
||||
@app.get("/user/today")
|
||||
def user_today(session: SessionDep) -> dict[str, int]:
|
||||
main_set = set()
|
||||
fast_set = set()
|
||||
slow_set = set()
|
||||
@app.get("/stat")
|
||||
def user_today(session: SessionDep):
|
||||
data = {}
|
||||
yesterday = datetime.now(timezone.utc) - timedelta(days=1)
|
||||
for system in session.exec(select(System).where(System.upload_time > yesterday)):
|
||||
if system.branch == "main":
|
||||
main_set.add(system.user_id)
|
||||
elif system.branch == "fast" and system.user_id not in main_set:
|
||||
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)}
|
||||
if system.branch in ["main", "fast", "slow"]:
|
||||
data[system.user_id] = [system.branch, system.commit]
|
||||
return list(data.values())
|
||||
|
|
Loading…
Add table
Reference in a new issue