Skip to content

Commit a6d516b

Browse files
committed
Small Update
Added data collection, streak gui
1 parent 42664dc commit a6d516b

5 files changed

Lines changed: 89 additions & 34 deletions

File tree

Binary file not shown.
-3 Bytes
Binary file not shown.

Version 1.0.0/Package/data_management.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,38 @@
44
import openpyxl as op
55

66
class DataManager:
7-
def __init__(self, timer_manager, workbook, worksheet):
8-
self.initialize_variables()
9-
7+
def __init__(self, App, timer_manager, workbook, worksheet):
8+
self.app = App
109
self.timer_manager = timer_manager
1110
self.workbook = workbook
1211
self.worksheet = worksheet
12+
self.initialize_variables()
1313

1414

1515
def initialize_variables(self):
16-
self.timer_time = 0
17-
self.break_time = 0
18-
self.data_amount = 0
19-
self.stop_time = ""
16+
self.date_list = []
17+
self.duration_list = []
18+
self.total_duration = 0
19+
20+
21+
def collect_data(self):
22+
self.data_amount = int(self.worksheet["Z1"].value)
23+
self.goal_amount = int(self.worksheet["R1"].value)
24+
25+
26+
for data in range(2, self.data_amount + 2):
27+
if "/" in str(self.worksheet["B" + str(data)].value):
28+
self.date_list.append(datetime.datetime.strptime(str(self.worksheet["B" + str(data)].value).split(" ")[0], "%d/%m/%Y").date())
29+
elif "-" in str(self.worksheet["B" + str(data)].value):
30+
self.date_list.append(datetime.datetime.strptime(str(self.worksheet["B" + str(data)].value).split(" ")[0], "%Y-%m-%d").date())
31+
self.duration_list.append(round(self.worksheet["C" + str(data)].value))
2032

33+
self.total_duration = sum(self.duration_list)
34+
print("Data collected.")
35+
self.app.update_streak_values()
2136

22-
def save_data(self, timer_button, break_button, time_display_label, break_display_label):
37+
38+
def save_data(self):
2339
if self.timer_manager.timer_time < 60:
2440
return print("No data to save.")
2541

@@ -30,12 +46,12 @@ def save_data(self, timer_button, break_button, time_display_label, break_displa
3046

3147
self.stop_time = datetime.datetime.now()
3248

33-
timer_button.configure(text="Start")
34-
break_button.configure(text="Start")
35-
time_display_label.configure(text="0:00:00")
36-
break_display_label.configure(text="0:00:00")
37-
print(self.timer_time, self.break_time)
49+
print("Data saved.")
50+
3851
self.timer_manager.initialize_variables()
52+
self.app.reset_timers()
53+
54+
3955

4056
def calculate_duration(self):
4157
duration = self.timer_time - self.break_time
@@ -44,4 +60,9 @@ def calculate_duration(self):
4460
else:
4561
duration /= 60
4662
return duration
63+
64+
65+
def increase_goal_streak(self):
66+
self.goal_amount += 1
67+
4768

Version 1.0.0/Package/timer_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def update_time(self):
3232
if self.timer_running:
3333
self.timer_time += 1
3434
self.time_display_label.configure(text=str(datetime.timedelta(seconds=self.timer_time)))
35-
self.app.update_slider(self.timer_time)
35+
self.app.reach_goal(self.timer_time)
3636
self.window.after(1000, self.update_time)
3737

3838

Version 1.0.0/main.py

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818

1919
class App:
2020
def __init__(self):
21-
self.file_setup()
22-
self.window_setup()
23-
24-
self.timer_manager = TimerManager(self, self.WINDOW)
25-
self.data_manager = DataManager(self.timer_manager, self.workbook, self.worksheet)
21+
self.APPNAME = "Timer App"
22+
self.FILENAME = "Timer Data.xlsx"
2623

24+
self.window_setup()
2725
self.initialize_variables()
2826
self.create_gui()
27+
self.file_setup()
2928

3029

3130
def create_gui(self):
@@ -43,26 +42,30 @@ def create_gui(self):
4342

4443

4544
def file_setup(self):
46-
self.APPNAME = "Timer App"
47-
FILENAME = "Timer Data.xlsx"
48-
4945
self.local_folder = os.path.expandvars(rf"%APPDATA%\{self.APPNAME}")
50-
self.data_file = os.path.expandvars(rf"%APPDATA%\{self.APPNAME}\{FILENAME}")
46+
self.data_file = os.path.expandvars(rf"%APPDATA%\{self.APPNAME}\{self.FILENAME}")
5147

5248
os.makedirs(self.local_folder, exist_ok=True)
5349

50+
self.timer_manager = TimerManager(self, self.WINDOW)
51+
5452
if os.path.isfile(self.data_file):
5553
self.workbook = op.load_workbook(self.data_file)
5654
self.worksheet = self.workbook.active
5755

58-
#collect_data()
56+
self.data_manager = DataManager(self, self.timer_manager, self.workbook, self.worksheet)
57+
58+
self.collect_data()
5959
print("File loaded")
6060

6161
else:
6262
self.workbook = op.Workbook()
6363
self.worksheet = self.workbook.active
6464

6565
self.workbook.save(self.data_file)
66+
67+
self.data_manager = DataManager(self, self.timer_manager, self.workbook, self.worksheet)
68+
6669
print("New file created")
6770
#customize_excel(worksheet)
6871

@@ -156,14 +159,14 @@ def goal_gui_setup(self):
156159
goal_label = ctk.CTkLabel(goal_frame, text="Goal", font=(font_family, font_size), text_color=font_color)
157160
goal_label.place(anchor="nw", relx=0.05, rely=0.05)
158161

159-
goal_dropdown = ctk.CTkComboBox(goal_frame, values=["1 minutes", "30 minutes", "1 hour", "1 hour, 30 minutes", "2 hours", "2 hours, 30 minutes", "3 hours", "3 hours, 30 minutes",
162+
self.goal_dropdown = ctk.CTkComboBox(goal_frame, values=["1 minutes", "30 minutes", "1 hour", "1 hour, 30 minutes", "2 hours", "2 hours, 30 minutes", "3 hours", "3 hours, 30 minutes",
160163
"4 hours", "4 hours, 30 minutes", "5 hours", "5 hours, 30 minutes", "6 hours"], variable=self.default_choice,
161164
state="readonly", width=200, height=30, dropdown_font=(font_family, int(font_size*0.75)),
162165
font=(font_family, int(font_size)), fg_color=border_frame_color, button_color=border_frame_color)
163-
goal_dropdown.place(anchor="center", relx=0.5, rely=0.45)
166+
self.goal_dropdown.place(anchor="center", relx=0.5, rely=0.45)
164167

165168
goal_button = ctk.CTkButton(goal_frame, text="Save", font=(font_family, font_size), text_color=button_font_color, fg_color=button_color, hover_color=button_highlight_color,
166-
height=button_height)
169+
height=button_height, command=self.set_goal)
167170
goal_button.place(anchor="s", relx=0.5, rely=0.9)
168171

169172

@@ -187,17 +190,17 @@ def streak_gui_setup(self):
187190
streak_label.place(anchor="nw", relx=0.05, rely=0.05)
188191
times_studied_text = ctk.CTkLabel(streak_frame, text="Goal\nreached", font=(font_family, int(font_size/1.25)), text_color=font_color)
189192
times_studied_text.place(anchor="center", relx=0.3, rely=0.4)
190-
times_studied_label = ctk.CTkLabel(streak_frame, text="goal_amount", font=(font_family, int(font_size*2.7)), text_color=font_color)
191-
times_studied_label.place(anchor="center", relx=0.3, rely=0.6)
193+
self.times_goal_reached = ctk.CTkLabel(streak_frame, text="goal_amount", font=(font_family, int(font_size*2.7)), text_color=font_color)
194+
self.times_goal_reached.place(anchor="center", relx=0.3, rely=0.6)
192195
times_reached_label = ctk.CTkLabel(streak_frame, text="times", font=(font_family, int(font_size/1.25)), text_color=font_color)
193196
times_reached_label.place(anchor="center", relx=0.3, rely=0.8)
194197

195198
duration_studied_text = ctk.CTkLabel(streak_frame, text="Time\nstudied", font=(font_family, int(font_size/1.25)), text_color=font_color)
196199
duration_studied_text.place(anchor="center", relx=0.7, rely=0.4)
197-
time_studied_label = ctk.CTkLabel(streak_frame, text="total_duration", font=(font_family, int(font_size*2.7)), text_color=font_color)
198-
time_studied_label.place(anchor="center", relx=0.7, rely=0.6)
199-
time_reached_label = ctk.CTkLabel(streak_frame, text="minutes", font=(font_family, int(font_size/1.25)), text_color=font_color)
200-
time_reached_label.place(anchor="center", relx=0.7, rely=0.8)
200+
self.streak_duration = ctk.CTkLabel(streak_frame, text="total_duration", font=(font_family, int(font_size*2.7)), text_color=font_color)
201+
self.streak_duration.place(anchor="center", relx=0.7, rely=0.6)
202+
duration_minute_label = ctk.CTkLabel(streak_frame, text="minutes", font=(font_family, int(font_size/1.25)), text_color=font_color)
203+
duration_minute_label.place(anchor="center", relx=0.7, rely=0.8)
201204

202205

203206
def timer_gui(self):
@@ -261,24 +264,55 @@ def timer_mechanism(self):
261264
self.timer_manager.timer_mechanism(self.timer_button, self.break_button, self.time_display_label)
262265

263266

264-
def update_slider(self, timer_time):
267+
def reset_timers(self):
268+
self.timer_button.configure(text="Start")
269+
self.break_button.configure(text="Start")
270+
self.time_display_label.configure(text="0:00:00")
271+
self.break_display_label.configure(text="0:00:00")
272+
273+
274+
def set_goal(self):
275+
x = 0
276+
choice = self.goal_dropdown.get()
277+
if "hour" in choice:
278+
x += int(choice.split(" ")[0]) * 60
279+
if "minutes" in choice and "hour" in choice:
280+
x += int(choice.split(", ")[1].removesuffix(" minutes"))
281+
if "hour" not in choice:
282+
x += int(choice.split(" ")[0])
283+
self.goal = x
284+
285+
286+
def reach_goal(self, timer_time):
265287
if self.goal == 0:
266288
self.goal = 60
267289
if (timer_time/60) < self.goal:
268290
self.progressbar.set((timer_time/60)/self.goal)
269291
elif not self.notification_limit and timer_time/60 >= self.goal:
270292
self.progressbar.set(1)
293+
294+
self.data_manager.increase_goal_streak()
295+
271296
message = random.choice(["Congratulations! You've reached your study goal. Take a well-deserved break and recharge!", "Study session complete! Great job on reaching your goal. Time for a quick break!",
272297
"You did it! Study session accomplished. Treat yourself to a moment of relaxation!", "Well done! You've met your study goal. Now, take some time to unwind and reflect on your progress.",
273298
"Study session over! You've achieved your goal. Reward yourself with a brief pause before your next task.", "Goal achieved! Take a breather and pat yourself on the back for your hard work.",
274299
"Mission accomplished! You've hit your study target. Enjoy a short break before diving back in.", "Study session complete. Nicely done! Use this time to relax and rejuvenate before your next endeavor.",
275300
"You've reached your study goal! Treat yourself to a well-deserved break. You've earned it!", "Goal achieved! Take a moment to celebrate your success. Your dedication is paying off!"])
276301
self.send_notification("Study Goal Reached", message)
302+
303+
def update_streak_values(self):
304+
self.times_goal_reached.configure(text=self.data_manager.goal_amount)
305+
self.streak_duration.configure(text=self.data_manager.total_duration)
306+
277307

278308
def break_mechanism(self):
279309
self.timer_manager.break_mechanism(self.break_button, self.timer_button, self.break_display_label)
280310

281311

312+
def collect_data(self):
313+
self.data_manager.collect_data()
314+
315+
282316
def save_data(self):
283317
self.data_manager.save_data(self.timer_button, self.break_button, self.time_display_label, self.break_display_label)
284318
self.progressbar.set(0)

0 commit comments

Comments
 (0)