Skip to content

Commit

Permalink
Restructure, add time studied today
Browse files Browse the repository at this point in the history
  • Loading branch information
jake158 committed Mar 16, 2024
1 parent cf82e0d commit 1c2360c
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions pomodorodiscord/src/stats_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 ''}")

0 comments on commit 1c2360c

Please sign in to comment.