rewrite: Profile, Stats, Leaderboard.
This commit is contained in:
@@ -5,15 +5,16 @@ import discord
|
||||
|
||||
from meta import LionBot
|
||||
from gui.cards import StatsCard
|
||||
from gui.base import CardMode
|
||||
|
||||
from ..data import StatsData
|
||||
|
||||
|
||||
async def get_stats_card(bot: LionBot, userid: int, guildid: int):
|
||||
async def get_stats_card(bot: LionBot, userid: int, guildid: int, mode: CardMode):
|
||||
data: StatsData = bot.get_cog('StatsCog').data
|
||||
|
||||
# TODO: Workouts
|
||||
# TODO: Leaderboard rankings
|
||||
# TODO: Leaderboard rankings for this season or all time
|
||||
guildid = guildid or 0
|
||||
|
||||
lion = await bot.core.lions.fetch_member(guildid, userid)
|
||||
@@ -31,20 +32,40 @@ async def get_stats_card(bot: LionBot, userid: int, guildid: int):
|
||||
)
|
||||
|
||||
# Extract the study times for each period
|
||||
study_times = await data.VoiceSessionStats.study_times_since(guildid, userid, *period_timestamps)
|
||||
print("Study times", study_times)
|
||||
if mode in (CardMode.STUDY, CardMode.VOICE):
|
||||
model = data.VoiceSessionStats
|
||||
refkey = (guildid, userid)
|
||||
ref_since = model.study_times_since
|
||||
ref_between = model.study_times_between
|
||||
elif mode is CardMode.TEXT:
|
||||
if guildid:
|
||||
model = data.MemberExp
|
||||
refkey = (guildid, userid)
|
||||
else:
|
||||
model = data.UserExp
|
||||
refkey = (userid,)
|
||||
ref_since = model.xp_since
|
||||
ref_between = model.xp_between
|
||||
else:
|
||||
# TODO ANKI
|
||||
model = data.VoiceSessionStats
|
||||
refkey = (guildid, userid)
|
||||
ref_since = model.study_times_since
|
||||
ref_between = model.study_times_between
|
||||
|
||||
study_times = await ref_since(*refkey, *period_timestamps)
|
||||
print("Period study times: ", study_times)
|
||||
|
||||
# Calculate streak data by requesting times per day
|
||||
# First calculate starting timestamps for each day
|
||||
days = list(range(0, today.day + 2))
|
||||
day_timestamps = [month_start + timedelta(days=day - 1) for day in days]
|
||||
study_times = await data.VoiceSessionStats.study_times_between(guildid, userid, *day_timestamps)
|
||||
print("Study times", study_times)
|
||||
study_times_month = await ref_between(*refkey, *day_timestamps)
|
||||
|
||||
# Then extract streak tuples
|
||||
streaks = []
|
||||
streak_start = None
|
||||
for day, stime in zip(days, study_times):
|
||||
for day, stime in zip(days, study_times_month):
|
||||
stime = stime or 0
|
||||
if stime > 0 and streak_start is None:
|
||||
streak_start = day
|
||||
@@ -59,5 +80,6 @@ async def get_stats_card(bot: LionBot, userid: int, guildid: int):
|
||||
list(reversed(study_times)),
|
||||
100,
|
||||
streaks,
|
||||
skin={'mode': mode}
|
||||
)
|
||||
return card
|
||||
|
||||
Reference in New Issue
Block a user