added portals, quest tracking, discord monitor etc etc

This commit is contained in:
erik 2025-06-23 19:26:44 +00:00
parent 72de9b0f7f
commit dffd295091
312 changed files with 4130 additions and 7 deletions

View file

@ -5,6 +5,7 @@ initialization function to set up TimescaleDB hypertable.
"""
import os
import sqlalchemy
from datetime import datetime, timedelta, timezone
from databases import Database
from sqlalchemy import MetaData, Table, Column, Integer, String, Float, DateTime, text
from sqlalchemy import Index, BigInteger, JSON, Boolean, UniqueConstraint
@ -126,6 +127,20 @@ character_inventories = Table(
UniqueConstraint("character_name", "item_id", name="uq_char_item"),
)
# Portal discoveries table for 24-hour live tracking
portal_discoveries = Table(
# Records player portal discoveries with 24-hour retention
"portal_discoveries",
metadata,
Column("id", Integer, primary_key=True),
Column("character_name", String, nullable=False, index=True),
Column("portal_name", String, nullable=False),
Column("timestamp", DateTime(timezone=True), nullable=False, index=True),
Column("ns", Float, nullable=False), # North/South coordinate as float
Column("ew", Float, nullable=False), # East/West coordinate as float
Column("z", Float, nullable=False), # Elevation as float
)
# Server health monitoring tables
server_health_checks = Table(
# Time-series data for server health checks
@ -213,4 +228,22 @@ async def init_db_async():
"SELECT add_compression_policy('telemetry_events', INTERVAL '1 day')"
))
except Exception as e:
print(f"Warning: failed to set retention/compression policies: {e}")
print(f"Warning: failed to set retention/compression policies: {e}")
async def cleanup_old_portals():
"""Clean up portal discoveries older than 24 hours."""
try:
cutoff_time = datetime.now(timezone.utc) - timedelta(hours=24)
# Delete old portal discoveries
result = await database.execute(
"DELETE FROM portal_discoveries WHERE timestamp < :cutoff_time",
{"cutoff_time": cutoff_time}
)
print(f"Cleaned up {result} portal discoveries older than 24 hours")
return result
except Exception as e:
print(f"Warning: failed to cleanup old portals: {e}")
return 0