fixed rares event
This commit is contained in:
parent
c418221575
commit
f86ad9a542
6 changed files with 101 additions and 2 deletions
19
main.py
19
main.py
|
|
@ -20,6 +20,7 @@ from db_async import (
|
|||
rare_stats,
|
||||
rare_stats_sessions,
|
||||
spawn_events,
|
||||
rare_events,
|
||||
init_db_async
|
||||
)
|
||||
import asyncio
|
||||
|
|
@ -69,6 +70,14 @@ class SpawnEvent(BaseModel):
|
|||
ns: float
|
||||
z: float = 0.0
|
||||
|
||||
class RareEvent(BaseModel):
|
||||
character_name: str
|
||||
name: str
|
||||
timestamp: datetime
|
||||
ew: float
|
||||
ns: float
|
||||
z: float = 0.0
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def on_startup():
|
||||
|
|
@ -310,6 +319,16 @@ async def ws_receive_snapshots(
|
|||
set_={"session_rares": rare_stats_sessions.c.session_rares + 1},
|
||||
)
|
||||
await database.execute(stmt_sess)
|
||||
# Persist individual rare event for future analysis
|
||||
payload = data.copy()
|
||||
payload.pop("type", None)
|
||||
try:
|
||||
rare_ev = RareEvent.parse_obj(payload)
|
||||
await database.execute(
|
||||
rare_events.insert().values(**rare_ev.dict())
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
continue
|
||||
# Chat message: broadcast to browser clients only (no DB write)
|
||||
if msg_type == "chat":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue