1010import darkdetect
1111from .styles import *
1212from .note_management import NotesManager
13+ from .achievement import Achievement
1314
1415class DataManager :
1516 def __init__ (self , App , timer_manager , workbook , worksheet ):
@@ -27,10 +28,7 @@ def initialize_variables(self) -> None:
2728 self .date_list = []
2829 self .duration_list = []
2930 self .total_duration = 0
30- self .break_list = []
3131 self .total_break_duration = 0
32- self .hours_list = []
33- self .subject_list = []
3432 self .best_weekday = ""
3533 self .average_time = "00:00"
3634 self .graph_color = "#f38064"
@@ -45,12 +43,12 @@ def initialize_new_file_variables(self) -> None:
4543 self .data_amount = 0
4644 self .notes_amount = 0
4745 self .monday_duration = self .tuesday_duration = self .wednesday_duration = self .thursday_duration = self .friday_duration = self .saturday_duration = self .sunday_duration = 0
46+ self .achievements = []
4847 self .color_name = "Orange"
4948 if darkdetect .isDark ():
5049 self .theme_name = "Dark"
5150 else :
5251 self .theme_name = "Light"
53-
5452 self .customize_excel ()
5553 self .save_color ()
5654 self .save_theme ()
@@ -82,6 +80,9 @@ def data_to_variable(self) -> None:
8280
8381
8482 def create_total_data (self ):
83+ self .break_list = []
84+ self .hours_list = []
85+ self .subject_list = []
8586 def get_sec (time : str ) -> int :
8687 """Get seconds from time."""
8788 h , m = time .split (":" )
@@ -91,8 +92,10 @@ def get_sec(time: str) -> int:
9192 self .break_list .append (float (self .worksheet ["D" + str (data )].value ))
9293 self .hours_list .append (get_sec ((self .worksheet ["A" + str (data )].value .split (" " )[1 ])))
9394 self .subject_list .append (self .worksheet ["E" + str (data )].value )
94-
95- self .total_break_duration = sum (self .break_list )
95+ try :
96+ self .total_break_duration = round (sum (self .break_list ))
97+ except :
98+ self .total_break_duration = 0
9699 try :
97100 self .average_time = str (datetime .timedelta (seconds = (round (sum (self .hours_list ) / len (self .hours_list )))))[:5 ]
98101 except ZeroDivisionError :
@@ -101,6 +104,23 @@ def get_sec(time: str) -> int:
101104 self .most_common_subject = Counter (self .subject_list ).most_common (1 )[0 ][0 ]
102105 except IndexError :
103106 self .most_common_subject = ""
107+ try :
108+ self .most_common_subject_amount = Counter (self .subject_list ).most_common (1 )[0 ][1 ]
109+ except :
110+ self .most_common_subject_amount = 0
111+ try :
112+ self .unique_subjects = set (self .subject_list )
113+ except :
114+ self .unique_subjects = []
115+ try :
116+ self .longest_session = round (max (self .duration_list ))
117+ except :
118+ self .longest_session = 0
119+
120+
121+ self .create_achievements ()
122+
123+
104124 def get_weekday ():
105125 weekdays_dict = {}
106126 for i in range (2 , 9 ):
@@ -309,8 +329,9 @@ def load_autobreak(self):
309329
310330 def set_color (self , color_dropdown ) -> None :
311331 self .color_name = color_dropdown .get ()
312- print ("Color set." )
313- self .save_color ()
332+ if self .color_name != self .worksheet ["T2" ].value :
333+ print ("Color set." )
334+ self .save_color ()
314335
315336
316337 def save_color (self ) -> None :
@@ -336,19 +357,28 @@ def load_color(self) -> None:
336357
337358 def change_color (self ) -> None :
338359 for widget in self .app .widget_list :
339- widget .configure (fg_color = self .color , hover_color = self .highlight_color )
340- self .app .progressbar .configure (progress_color = self .color )
360+ if isinstance (widget , ctk .CTkButton ):
361+ widget .configure (fg_color = self .color , hover_color = self .highlight_color )
362+ else :
363+ if widget .get () != 0 :
364+ widget .configure (progress_color = self .color )
365+ else :
366+ widget .configure (progress_color = (light_border_frame_color , border_frame_color ))
367+ #self.app.progressbar.configure(progress_color = self.color)
341368 self .app .eye_care_checkbox .configure (fg_color = self .color )
342369 self .app .create_graphs ()
343370
371+ self .app .create_achievements ()
372+
344373 self .load_notes ()
345374 print ("Color changed." )
346375
347376
348377 def set_theme (self , theme_dropdown ) -> None :
349378 self .theme_name = theme_dropdown .get ()
350- print ("Theme set." )
351- self .save_theme ()
379+ if self .theme_name != self .worksheet ["U2" ].value :
380+ print ("Theme set." )
381+ self .save_theme ()
352382
353383
354384 def save_theme (self ) -> None :
@@ -407,6 +437,8 @@ def create_new_note(self, title, text):
407437
408438 print ("New note created." )
409439
440+ self .create_achievements ()
441+ self .app .create_achievements ()
410442 self .load_notes ()
411443
412444
@@ -522,4 +554,15 @@ def align_cells(worksheet, cell_range: str):
522554
523555 export_workbook .save (f"{ os .path .join (os .path .expanduser ("~" ), "Desktop" )} /timer_data_{ datetime .datetime .now ().date ().strftime ("%d.%m.%Y" )} .xlsx" )
524556
525- print ("File exported." )
557+ print ("File exported." )
558+
559+
560+ def create_achievements (self ):
561+ self .achievements = [Achievement (name = "Time Titan" , title = "Clock in 1000 minutes of study, mastering the art of time management." , max_value = 1000 , value = self .total_duration ),
562+ Achievement (name = "Goal Getter" , title = "Reach 30 goals, proving dedication to progress." , max_value = 30 , value = self .goal_amount ),
563+ Achievement (name = "Subject Explorer" , title = "Dive into 7 different subjects, broadening your knowledge horizons." , max_value = 7 , value = len (self .unique_subjects )),
564+ Achievement (name = "Focus Maestro" , title = "Master concentration in a 5-hour session, demonstrating exceptional focus." , max_value = 5 , value = round (self .longest_session / 60 , 2 )),
565+ Achievement (name = "Subject Savant" , title = "Study one subject 30 times, becoming a savant in its intricacies." , max_value = 30 , value = self .most_common_subject_amount ),
566+ Achievement (name = "Restful Respite" , title = "Accumulate 200 minutes of break time, rejuvenating your mind and body." , max_value = 200 , value = self .total_break_duration ),
567+ Achievement (name = "Daily Discipline" , title = "Exhibit discipline through diligent study for 30 days." , max_value = 30 , value = len (set (self .date_list ))),
568+ Achievement (name = "Note Scribbler" , title = "Scribble down 10 notes, capturing key insights and ideas." , max_value = 10 , value = self .notes_amount )]
0 commit comments