T4g1 / z14

z03 evolved
1 stars 3 forks source link

Command: stats #33

Closed T4g1 closed 3 years ago

T4g1 commented 3 years ago

Functional analysis

Total users

Given by the API discord.py

Messages count tracking

We need to be able to track how many messages were sent per day per users.

This will give us the following features:

Users text/voice online tracking

Every time an user goes online: We track which time the user went online Every time an user goes offline: We compute for how long he was online and stores it

This will give us the following features:

Computations Uptimes are computed for every users and the value of online time is set to the last check on some events:

Bot uptime

When starting, bot will remember the time, when asking for uptime, it will simply give the difference with actual time. This will replace "Server 'age' (uptime)"

Corner cases

Queries "per day" should have one row per day even those without data that day

Entities

2 tables are required for TRACKING daily data:

1 table is required for HISTORICAL past days data:

1 local data is required for UPTIME bot connection time: When the bot goes online

Architecture

We want to react to several events:

Bot goes online

A message is received

Increment the number of message sent for that user today

A voice/test status is changed

Compute uptime for that user

A command stat is received (or bot is closed or arbitrary time passes)

Uptime computation

To compute uptime, we need to know the new user status: For periodic computation, status is unchanged but datetime is updated Having no row in TRACKING for one user mean he's offline

Given a row in TRACKING corresponding to a given user:

last online time is row time
for each day in the interval between now and the row time:
    if the row time is within that day:
       uptime for that day is now - last online
   otherwise:
       uptime for that day is 24h - last online

   last online is the next day at 00h

Remove the tracking row if the new status is offline

Roadmap

Server specific

Leaderboards (top 3/5/10)

User specific

closes #6

T4g1 commented 3 years ago

Todo: format seconds output to more human readable format