-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify, clean, remove update stats button
- Loading branch information
Showing
1 changed file
with
24 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,58 @@ | ||
import customtkinter as ctk | ||
from datetime import datetime | ||
from src.reusable.statistic_display import StatisticDisplay | ||
from src.reusable.stats_reusable import StatisticFrame, ButtonFrame | ||
from src.utils import load_data | ||
from src.logic.graphs import graph_pomodoro_sessions, graph_hours_studied | ||
|
||
|
||
class StatsFrame(ctk.CTkScrollableFrame): | ||
def __init__(self, master): | ||
super().__init__(master) | ||
|
||
self.time_today = StatisticDisplay(self, "Time Studied Today:") | ||
self.pomodoros_today = StatisticDisplay(self, "Pomodoros Today:") | ||
self.total_hours = StatisticDisplay(self, "Total Time Studied:") | ||
self.total_pomodoros = StatisticDisplay(self, "Total Pomodoros:") | ||
|
||
self.update_stats = ctk.CTkButton(self, text="Update", width=90, font=("Roboto", 16), command=self.load_stats) | ||
self.update_stats.pack(pady=(10, 0)) | ||
|
||
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.time_today = StatisticFrame(self, "Time Studied Today:") | ||
self.pomodoros_today = StatisticFrame(self, "Pomodoros Today:") | ||
self.total_hours = StatisticFrame(self, "Total Time Studied:") | ||
self.total_pomodoros = StatisticFrame(self, "Total Pomodoros:") | ||
self.graph_btn_1 = ButtonFrame(self, "Pomodoro Sessions Graph", "Show", self.show_sessions_graph) | ||
self.graph_btn_2 = ButtonFrame(self, "Hours Studied Graph", "Show", self.show_hours_graph) | ||
self.load_stats() | ||
|
||
def load_stats(self): | ||
data = load_data() | ||
if not data: | ||
return | ||
|
||
current_date = datetime.now().strftime("%Y-%m-%d") | ||
self.update_time_today(data, current_date) | ||
self.update_pomodoros_today(data, current_date) | ||
self.update_total_hours(data) | ||
self.update_total_pomodoros(data) | ||
|
||
def update_time_today(self, data, current_date): | ||
total_today_seconds = data.get('seconds_by_date', {}).get(current_date, 0) | ||
total_today_hours = total_today_seconds / 3600 | ||
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") | ||
|
||
|
||
def update_pomodoros_today(self, data, current_date): | ||
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 ''}") | ||
|
||
|
||
def update_total_hours(self, data): | ||
total_seconds = data.get('total_seconds_studied', 0) | ||
total_hours = data.get('total_seconds_studied', 0) / 3600 | ||
total_hours = total_seconds / 3600 | ||
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_hours:.1f} hours") | ||
|
||
|
||
def update_total_pomodoros(self, data): | ||
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()) |