Skip to content

Commit

Permalink
Track seconds studied on each day separately
Browse files Browse the repository at this point in the history
  • Loading branch information
jake158 committed Mar 16, 2024
1 parent 1c2360c commit 8d1867f
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions pomodorodiscord/src/pomodoro_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
RESET_BTN_COLOR = "#cca508"
RESET_HOVER = "#e3b707"

#TODO: clean everything

class PomodoroFrame(ctk.CTkFrame):
def __init__(self, master):
super().__init__(master)
self.data_file = 'data.json'
config = load_config()

# Rich presence in separate thread
threading.Thread(target=self.init_rpc, daemon=True).start()

# Helper text that appears when a break is running
self.break_text = ctk.StringVar(value="")
self.break_label = ctk.CTkLabel(self, textvariable=self.break_text, font=("Roboto", 15))
Expand Down Expand Up @@ -54,6 +52,9 @@ def __init__(self, master):
self.next_timer_update = None
self.remaining_time = self.pomodoro_time

# For tracking seconds
self.date_started = datetime.now().strftime("%Y-%m-%d")

# Automatic break cycling states
self.auto_break_cycling = config.get("auto_break_cycling", False)
self.short_breaks_before_long = config.get("short_breaks_before_long", DEF_SB_BEFORE_L)
Expand All @@ -65,6 +66,9 @@ def __init__(self, master):
self.end_time_timestamp = None
self.session_counter = 0

# Initialize rich presence in separate thread
threading.Thread(target=self.init_rpc, daemon=True).start()

def init_rpc(self):
self.rpc = RichPresence()
self.rpc_thread = threading.Thread(target=self.update_rpc, daemon=True)
Expand Down Expand Up @@ -92,6 +96,9 @@ def start_timer(self):
self.start_time_timestamp = start_time.timestamp()
self.end_time_timestamp = end_time.timestamp()

# For tracking seconds
self.date_started = datetime.now().strftime("%Y-%m-%d")

self.running = not self.running
btn_text = "Pause" if self.running else "Resume"
btn_fg = "transparent" if self.running else self.start_color
Expand All @@ -110,14 +117,25 @@ def update_timer(self):
self.session_ended()

def track_second(self):
# TODO: I don't like the if check every second
current_date = self.date_started

if os.path.exists(self.data_file):
with open(self.data_file, 'r') as file:
data = json.load(file)
data['total_seconds_studied'] += 1

if 'seconds_by_date' not in data:
data['seconds_by_date'] = {}
if current_date not in data['seconds_by_date']:
data['seconds_by_date'][current_date] = 0

data['seconds_by_date'][current_date] += 1
else:
data = {'total_seconds_studied': 0}

data = {
'total_seconds_studied': 1,
'seconds_by_date': {current_date: 1}
}

with open(self.data_file, 'w') as file:
json.dump(data, file, indent=4)

Expand Down

0 comments on commit 8d1867f

Please sign in to comment.