1"""Hourly per-member activity counts, for server stats and Hall of Heroes profile charts."""
2
3from datetime import datetime # SQLAlchemy resolves Mapped[] annotations at runtime
4
5from advanced_alchemy.base import UUIDAuditBase
6from advanced_alchemy.types import DateTimeUTC
7from sqlalchemy import BigInteger, Index, Integer, UniqueConstraint
8from sqlalchemy.orm import Mapped, mapped_column
9
10
[docs]
11class MemberActivityHour(UUIDAuditBase):
12 """One member's activity in one UTC hour.
13
14 ``messages`` is XP-eligible chat messages (what the bot sends to the chat-XP route), bumped once per
15 ``award_xp`` call regardless of whether XP was actually paid. ``voice_minutes`` is minutes present under the
16 stats voice rule (any voice/stage channel but the guild's AFK channel, with at least two non-bot members),
17 looser than and separate from the voice-XP rule; it is recorded even while leveling is disabled.
18 ``chat_xp``/``voice_xp`` are the XP actually awarded that hour, which can be less than a full award (or zero)
19 when leveling was off or the chat cooldown was active.
20 """
21
22 __tablename__ = "member_activity_hour"
23 __table_args__ = (
24 UniqueConstraint("guild_id", "user_id", "hour_start", name="uq_member_activity_hour"),
25 Index("ix_member_activity_hour_guild_hour", "guild_id", "hour_start"),
26 {"comment": "Hourly per-member message/voice/XP counts, for stats and Hall of Heroes profiles."},
27 )
28
29 guild_id: Mapped[int] = mapped_column(BigInteger)
30 user_id: Mapped[int] = mapped_column(BigInteger, index=True)
31 hour_start: Mapped[datetime] = mapped_column(DateTimeUTC(timezone=True))
32 messages: Mapped[int] = mapped_column(Integer, default=0)
33 voice_minutes: Mapped[int] = mapped_column(Integer, default=0)
34 chat_xp: Mapped[int] = mapped_column(Integer, default=0)
35 voice_xp: Mapped[int] = mapped_column(Integer, default=0)