From 1c2360ccb64eed982c6d3785d8416a5517be1cd1 Mon Sep 17 00:00:00 2001 From: freeram Date: Sat, 16 Mar 2024 17:11:30 -0600 Subject: [PATCH] Restructure, add time studied today --- pomodorodiscord/src/stats_frame.py | 65 +++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/pomodorodiscord/src/stats_frame.py b/pomodorodiscord/src/stats_frame.py index 3c3a03c..b251f10 100644 --- a/pomodorodiscord/src/stats_frame.py +++ b/pomodorodiscord/src/stats_frame.py @@ -3,25 +3,43 @@ from src.utils import load_data -class StatsFrame(ctk.CTkFrame): +class StatisticDisplay(ctk.CTkFrame): + def __init__(self, master, title, initial_value="0", title_font=18, val_font=24, **kwargs): + super().__init__(master, **kwargs) + self.pack(pady=(10, 15), fill="x") + + # Title Label + self.title_label = ctk.CTkLabel(self, text=title, font=("Helvetica", title_font, "bold"), anchor="n") + self.title_label.pack(fill="x") + + # Value Label + self.value_var = ctk.StringVar(value=initial_value) + self.value_label = ctk.CTkLabel(self, textvariable=self.value_var, font=("Helvetica", val_font), anchor="center") + self.value_label.pack(pady=(5, 0), fill="x") + + def set_value(self, value): + self.value_var.set(value) + + +class StatsFrame(ctk.CTkScrollableFrame): def __init__(self, master): super().__init__(master) - self.data_file = 'data.json' - self.total_today_var = ctk.StringVar(value="Pomodoros Today: 0") - self.total_today = ctk.CTkLabel(self, textvariable=self.total_today_var, font=("Helvetica", 16, "bold"), anchor="w") - self.total_today.pack(padx=20, pady=(20, 0), fill="x") + # Time Studied Today + self.time_today = StatisticDisplay(self, "Time Studied Today:") + + # Pomodoros Today + self.pomodoros_today = StatisticDisplay(self, "Pomodoros Today:") - self.total_hours_var = ctk.StringVar(value="Total Hours Studied: 0") - self.total_hours = ctk.CTkLabel(self, textvariable=self.total_hours_var, font=("Helvetica", 16, "bold"), anchor="w") - self.total_hours.pack(padx=20, pady=(20, 0), fill="x") + # Total Hours Studied + self.total_hours = StatisticDisplay(self, "Total Time Studied:") - self.total_var = ctk.StringVar(value="Total Pomodoros: 0") - self.total = ctk.CTkLabel(self, textvariable=self.total_var, font=("Helvetica", 16, "bold"), anchor="w") - self.total.pack(padx=20, pady=(20, 0), fill="x") + # Total Pomodoros + self.total_pomodoros = StatisticDisplay(self, "Total Pomodoros:") + # Update Button self.update_stats = ctk.CTkButton(self, text="Update", width=90, font=("Roboto", 16), command=self.load_stats) - self.update_stats.pack(pady=40, side=ctk.BOTTOM) + self.update_stats.pack(pady=(20, 0)) self.load_stats() @@ -31,14 +49,25 @@ def load_stats(self): return current_date = datetime.now().strftime("%Y-%m-%d") - total_today = data.get('sessions_by_date', {}).get(current_date, 0) + total_today_seconds = data.get('seconds_by_date', {}).get(current_date, 0) + + total_today_hours = total_today_seconds / 3600 - self.total_today_var.set(f"Pomodoros Today: {total_today}") + if total_today_hours < 1: + self.time_today.set_value(f"{total_today_seconds // 60} minute{'s' if total_today_seconds // 60 != 1 else ''}") + else: + self.time_today.set_value(f"{total_today_hours:.1f} hours") - total_seconds_studied = data.get('total_seconds_studied', 0) - total_hours = total_seconds_studied / 3600 + total_today_pomodoros = data.get('sessions_by_date', {}).get(current_date, 0) + self.pomodoros_today.set_value(f"{total_today_pomodoros} session{'s' if total_today_pomodoros != 1 else ''}") - self.total_hours_var.set(f"Total Hours Studied: {total_hours:.1f}") + total_seconds = data.get('total_seconds_studed', 0) + total_hours = data.get('total_seconds_studied', 0) / 3600 - self.total_var.set(f"Total Pomodoros: {data.get('total_pomodoro_sessions', 0)}") + if total_hours < 1: + self.total_hours.set_value(f"{total_seconds // 60} minute{'s' if total_seconds // 60 != 1 else ''}") + else: + self.total_hours.set_value(f"{total_today_hours:.1f} hours") + total_pomodoros = data.get('total_pomodoro_sessions', 0) + self.total_pomodoros.set_value(f"{total_pomodoros} session{'s' if total_pomodoros != 1 else ''}")