Skip to content

Commit 62dfbf2

Browse files
committed
Small Update
1 parent a6d516b commit 62dfbf2

3 files changed

Lines changed: 130 additions & 24 deletions

File tree

Binary file not shown.

Version 1.0.0/Package/data_management.py

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime
33

44
import openpyxl as op
5+
from openpyxl.styles import Font
56

67
class DataManager:
78
def __init__(self, App, timer_manager, workbook, worksheet):
@@ -16,13 +17,21 @@ def initialize_variables(self):
1617
self.date_list = []
1718
self.duration_list = []
1819
self.total_duration = 0
20+
21+
22+
def initialize_new_file_variables(self):
23+
self.goal_amount = 0
24+
self.data_amount = 0
1925

2026

2127
def collect_data(self):
22-
self.data_amount = int(self.worksheet["Z1"].value)
23-
self.goal_amount = int(self.worksheet["R1"].value)
28+
self.data_amount = int(self.worksheet["Z2"].value)
29+
self.goal_amount = int(self.worksheet["R2"].value)
30+
31+
print("Data collected.")
2432

2533

34+
def data_to_variable(self):
2635
for data in range(2, self.data_amount + 2):
2736
if "/" in str(self.worksheet["B" + str(data)].value):
2837
self.date_list.append(datetime.datetime.strptime(str(self.worksheet["B" + str(data)].value).split(" ")[0], "%d/%m/%Y").date())
@@ -31,27 +40,65 @@ def collect_data(self):
3140
self.duration_list.append(round(self.worksheet["C" + str(data)].value))
3241

3342
self.total_duration = sum(self.duration_list)
34-
print("Data collected.")
35-
self.app.update_streak_values()
3643

3744

3845
def save_data(self):
39-
if self.timer_manager.timer_time < 60:
40-
return print("No data to save.")
46+
self.initialize_variables()
47+
48+
self.data_amount += 1
4149

4250
self.timer_time = self.timer_manager.timer_time
4351
self.break_time = self.timer_manager.break_time
4452

53+
self.stop_time = datetime.datetime.now()
54+
4555
self.duration = self.calculate_duration()
4656

47-
self.stop_time = datetime.datetime.now()
57+
self.workbook.save(self.app.data_file)
58+
59+
self.write_to_excel()
4860

4961
print("Data saved.")
5062

5163
self.timer_manager.initialize_variables()
5264
self.app.reset_timers()
5365

5466

67+
def write_to_excel(self):
68+
self.worksheet["A" + str((self.data_amount + 1))].value = self.start_time.strftime("%d/%m/%Y %H:%M")
69+
self.worksheet["B" + str((self.data_amount + 1))].value = self.stop_time.strftime("%d/%m/%Y %H:%M")
70+
self.worksheet["C" + str((self.data_amount + 1))].value = self.duration
71+
self.worksheet["D" + str((self.data_amount + 1))].value = self.break_time/60
72+
self.worksheet["R2"].value = self.goal_amount
73+
self.worksheet["Z2"].value = self.data_amount
74+
self.workbook.save(self.app.data_file)
75+
76+
77+
def customize_excel(self):
78+
self.worksheet["A1"].value = "Start:"
79+
self.worksheet["B1"].value = "End:"
80+
self.worksheet["C1"].value = "Duration:"
81+
self.worksheet["D1"].value = "Break:"
82+
83+
self.worksheet["R1"].value = "Goals reached:"
84+
self.worksheet["R2"].value = self.goal_amount
85+
86+
self.worksheet["A1"].font = Font(bold=True, size=14)
87+
self.worksheet["B1"].font = Font(bold=True, size=14)
88+
self.worksheet["C1"].font = Font(bold=True, size=14)
89+
self.worksheet["D1"].font = Font(bold=True, size=14)
90+
self.worksheet["E1"].font = Font(bold=True, size=14)
91+
92+
self.worksheet["Z1"].value = "Data amount: "
93+
self.worksheet["Z1"].font = Font(bold=True, size=14)
94+
self.worksheet["Z2"].value = self.data_amount
95+
self.workbook.save(self.app.data_file)
96+
print("Excel customized.")
97+
98+
99+
def get_start_time(self):
100+
self.start_time = datetime.datetime.now()
101+
55102

56103
def calculate_duration(self):
57104
duration = self.timer_time - self.break_time
@@ -63,6 +110,17 @@ def calculate_duration(self):
63110

64111

65112
def increase_goal_streak(self):
113+
print("AAA")
66114
self.goal_amount += 1
115+
print(self.goal_amount)
116+
117+
118+
def reset_data(self, workbook, worksheet):
119+
self.workbook = workbook
120+
self.worksheet = worksheet
121+
122+
self.workbook.save(self.app.data_file)
123+
124+
self.initialize_new_file_variables()
67125

68-
126+
print("Data reset.")

Version 1.0.0/main.py

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import random
44

55
import openpyxl as op
6-
from openpyxl.styles import Font
76
import pandas as pd
87
import matplotlib.pyplot as plt
98
import matplotlib.dates as mdates
@@ -25,6 +24,7 @@ def __init__(self):
2524
self.initialize_variables()
2625
self.create_gui()
2726
self.file_setup()
27+
self.settings_gui_setup()
2828

2929

3030
def create_gui(self):
@@ -56,6 +56,7 @@ def file_setup(self):
5656
self.data_manager = DataManager(self, self.timer_manager, self.workbook, self.worksheet)
5757

5858
self.collect_data()
59+
self.update_streak_values()
5960
print("File loaded")
6061

6162
else:
@@ -67,13 +68,15 @@ def file_setup(self):
6768
self.data_manager = DataManager(self, self.timer_manager, self.workbook, self.worksheet)
6869

6970
print("New file created")
70-
#customize_excel(worksheet)
71+
self.data_manager.initialize_new_file_variables()
72+
73+
self.data_manager.customize_excel()
7174

7275

7376
def initialize_variables(self):
7477
self.default_choice = ctk.StringVar(value="1 hour")
7578
self.notification_limit = False
76-
self.goal = 1
79+
self.goal = 60
7780

7881

7982
def window_setup(self):
@@ -139,6 +142,11 @@ def tab_frames_gui_setup(self):
139142
fg_color=tab_color, width=int(tab_frame_width*0.95), height=int(tab_height*0.7), hover_color=tab_highlight_color,
140143
anchor="w", command=lambda: self.switch_tab("history"))
141144
self.history_tab_button.place(relx=0.5, rely=0.5, anchor="center")
145+
self.settings_tab = ctk.CTkFrame(self.tab_frame, width=tab_frame_width, height=tab_height*0.8, fg_color=tab_color)
146+
self.settings_tab.place(relx=0.5, rely=1, anchor="s")
147+
settings_tab_button = ctk.CTkButton(self.settings_tab, text="Settings", font=(tab_font_family, 22*tab_height/50, tab_font_weight), text_color=font_color,
148+
fg_color=tab_color, width=int(tab_frame_width*0.95), height=int(tab_height*0.7), hover_color=tab_highlight_color, anchor="w", command=lambda: self.switch_tab("settings"))
149+
settings_tab_button.place(relx=0.5, rely=0.5, anchor="center")
142150

143151

144152
def secondary_frames_gui_setup(self):
@@ -186,18 +194,20 @@ def progress_gui_setup(self):
186194
def streak_gui_setup(self):
187195
streak_frame = ctk.CTkFrame(self.goal_progress_frame, fg_color=frame_color, width=frame_width, corner_radius=10, height=220)
188196
streak_frame.pack(padx=frame_padding, pady=frame_padding)
197+
189198
streak_label = ctk.CTkLabel(streak_frame, text="Streak", font=(font_family, int(font_size)), text_color=font_color)
190199
streak_label.place(anchor="nw", relx=0.05, rely=0.05)
200+
191201
times_studied_text = ctk.CTkLabel(streak_frame, text="Goal\nreached", font=(font_family, int(font_size/1.25)), text_color=font_color)
192202
times_studied_text.place(anchor="center", relx=0.3, rely=0.4)
193-
self.times_goal_reached = ctk.CTkLabel(streak_frame, text="goal_amount", font=(font_family, int(font_size*2.7)), text_color=font_color)
203+
self.times_goal_reached = ctk.CTkLabel(streak_frame, text=0, font=(font_family, int(font_size*2.7)), text_color=font_color)
194204
self.times_goal_reached.place(anchor="center", relx=0.3, rely=0.6)
195205
times_reached_label = ctk.CTkLabel(streak_frame, text="times", font=(font_family, int(font_size/1.25)), text_color=font_color)
196206
times_reached_label.place(anchor="center", relx=0.3, rely=0.8)
197207

198208
duration_studied_text = ctk.CTkLabel(streak_frame, text="Time\nstudied", font=(font_family, int(font_size/1.25)), text_color=font_color)
199209
duration_studied_text.place(anchor="center", relx=0.7, rely=0.4)
200-
self.streak_duration = ctk.CTkLabel(streak_frame, text="total_duration", font=(font_family, int(font_size*2.7)), text_color=font_color)
210+
self.streak_duration = ctk.CTkLabel(streak_frame, text=0, font=(font_family, int(font_size*2.7)), text_color=font_color)
201211
self.streak_duration.place(anchor="center", relx=0.7, rely=0.6)
202212
duration_minute_label = ctk.CTkLabel(streak_frame, text="minutes", font=(font_family, int(font_size/1.25)), text_color=font_color)
203213
duration_minute_label.place(anchor="center", relx=0.7, rely=0.8)
@@ -239,6 +249,17 @@ def save_data_gui(self):
239249
save_data_btn.place(relx=0.5, anchor="center", rely=0.5)
240250

241251

252+
def settings_gui_setup(self):
253+
reset_frame = ctk.CTkFrame(self.settings_frame, fg_color=tab_color)
254+
reset_frame.place(anchor="s", relx=0.5, rely=0.985)
255+
reset_data_btn = ctk.CTkButton(reset_frame, text="Reset Data", font=(font_family, font_size), fg_color=button_color, text_color=button_font_color,
256+
border_color=frame_border_color, hover_color=button_highlight_color, height=button_height, command=self.reset_data, width=450)
257+
reset_data_btn.pack()
258+
259+
260+
261+
262+
242263
def switch_tab(self, tab = str):
243264
tabs = {
244265
"main": self.main_frame,
@@ -262,6 +283,15 @@ def forget_tabs():
262283

263284
def timer_mechanism(self):
264285
self.timer_manager.timer_mechanism(self.timer_button, self.break_button, self.time_display_label)
286+
if self.timer_manager.timer_time <= 1:
287+
self.data_manager.get_start_time()
288+
289+
290+
def reset_gui_values(self):
291+
self.times_goal_reached.configure(text=0)
292+
self.streak_duration.configure(text=0)
293+
self.progressbar.set(0)
294+
self.reset_timers()
265295

266296

267297
def reset_timers(self):
@@ -284,21 +314,18 @@ def set_goal(self):
284314

285315

286316
def reach_goal(self, timer_time):
287-
if self.goal == 0:
288-
self.goal = 60
289317
if (timer_time/60) < self.goal:
290318
self.progressbar.set((timer_time/60)/self.goal)
291-
elif not self.notification_limit and timer_time/60 >= self.goal:
319+
elif timer_time/60 >= self.goal and not self.notification_limit:
292320
self.progressbar.set(1)
293321

294-
self.data_manager.increase_goal_streak()
295-
296322
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!",
297-
"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.",
298-
"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.",
299-
"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.",
300-
"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!"])
323+
"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.",
324+
"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.",
325+
"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.",
326+
"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!"])
301327
self.send_notification("Study Goal Reached", message)
328+
print(self.notification_limit)
302329

303330
def update_streak_values(self):
304331
self.times_goal_reached.configure(text=self.data_manager.goal_amount)
@@ -311,11 +338,22 @@ def break_mechanism(self):
311338

312339
def collect_data(self):
313340
self.data_manager.collect_data()
341+
self.data_manager.data_to_variable()
314342

315343

316344
def save_data(self):
317-
self.data_manager.save_data(self.timer_button, self.break_button, self.time_display_label, self.break_display_label)
318-
self.progressbar.set(0)
345+
if self.timer_manager.timer_time > 60:
346+
if self.timer_manager.timer_time/60 >= self.goal:
347+
self.data_manager.increase_goal_streak()
348+
349+
self.data_manager.save_data()
350+
self.collect_data()
351+
self.reset_gui_values()
352+
self.update_streak_values()
353+
354+
self.notification_limit = False
355+
else:
356+
print("No data to save. (time less than 1m)")
319357

320358

321359
def send_notification(self, title, message):
@@ -325,6 +363,16 @@ def send_notification(self, title, message):
325363
print("Notification " + title + " sent.")
326364

327365

366+
def reset_data(self):
367+
del self.workbook[self.workbook.active.title]
368+
self.workbook.create_sheet()
369+
self.worksheet = self.workbook.active
370+
371+
self.data_manager.reset_data(self.workbook, self.worksheet)
372+
373+
self.reset_gui_values()
374+
375+
328376
def run(self):
329377
self.WINDOW.mainloop()
330378

0 commit comments

Comments
 (0)