Skip to content

Commit

Permalink
Add displaying graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
jake158 committed Mar 17, 2024
1 parent f9473e2 commit e283f1f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pomodorodiscord/src/stats_frame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import customtkinter as ctk
from datetime import datetime
from src.utils import load_data
from src.graphs import graph_pomodoro_sessions, graph_hours_studied


class StatisticDisplay(ctk.CTkFrame):
Expand All @@ -9,7 +10,7 @@ def __init__(self, master, title, initial_value="0", title_font=18, val_font=24,
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 = ctk.CTkLabel(self, text=title, font=("Helvetica", title_font), anchor="n")
self.title_label.pack(fill="x")

# Value Label
Expand All @@ -27,7 +28,7 @@ def __init__(self, master):

# Time Studied Today
self.time_today = StatisticDisplay(self, "Time Studied Today:")

# Pomodoros Today
self.pomodoros_today = StatisticDisplay(self, "Pomodoros Today:")

Expand All @@ -39,7 +40,18 @@ def __init__(self, master):

# Update Button
self.update_stats = ctk.CTkButton(self, text="Update", width=90, font=("Roboto", 16), command=self.load_stats)
self.update_stats.pack(pady=(20, 0))
self.update_stats.pack(pady=(10, 0))

# Graphs
self.graph_label_1 = ctk.CTkLabel(self, text="Pomodoro Sessions Graph", font=("Helvetica", 18))
self.graph_label_1.pack(pady=(32, 8))
self.graph_button_1 = ctk.CTkButton(self, text="Show", width=90, font=("Roboto", 16), command=self.show_sessions_graph)
self.graph_button_1.pack()

self.graph_label_2 = ctk.CTkLabel(self, text="Hours Studied Graph", font=("Helvetica", 18))
self.graph_label_2.pack(pady=(20, 8))
self.graph_button_2 = ctk.CTkButton(self, text="Show", width=90, font=("Roboto", 16), command=self.show_hours_graph)
self.graph_button_2.pack()

self.load_stats()

Expand Down Expand Up @@ -67,7 +79,13 @@ def load_stats(self):
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")
self.total_hours.set_value(f"{total_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 ''}")

def show_sessions_graph(self):
graph_pomodoro_sessions(load_data())

def show_hours_graph(self):
graph_hours_studied(load_data())

0 comments on commit e283f1f

Please sign in to comment.