3535start_time = ""
3636goal = 0
3737default_choice = ctk .StringVar (value = "1 hour" )
38- color = ""
38+ color = "Orange"
39+ default_color = ctk .StringVar (value = color )
3940
4041
4142main_frame = ctk .CTkFrame (WINDOW , fg_color = main_frame_color , height = HEIGHT + ((widget_padding_x + frame_padding )* 2 ), width = WIDTH , corner_radius = 0 )
@@ -87,6 +88,8 @@ def customize_excel(worksheet):
8788
8889 worksheet ["T1" ].value = color
8990
91+ worksheet ["R1" ].value = goal_amount
92+
9093 worksheet ["A1" ].font = Font (bold = True , size = 14 )
9194 worksheet ["B1" ].font = Font (bold = True , size = 14 )
9295 worksheet ["C1" ].font = Font (bold = True , size = 14 )
@@ -101,31 +104,33 @@ def customize_excel(worksheet):
101104
102105date_list = []
103106duration_list = []
107+ total_duration = 0
104108
105109
106110def create_time_spent_graph (date_list , duration_list ):
111+ global graph_color
107112 data = {"Date" : date_list , "Duration" : duration_list }
108113 df = pd .DataFrame (data )
109114 grouped_data = df .groupby ("Date" )["Duration" ].sum ().reset_index ()
110- fig , ax = plt .subplots ()
111- ax .bar (grouped_data ["Date" ], grouped_data ["Duration" ], color = graph_color )
112- ax .set_xlabel ("Date" , color = font_color )
113- ax .set_ylabel ("Duration in minutes" , color = font_color )
114- ax .set_title ("Time Spent by Date" , color = font_color )
115- ax .tick_params (colors = "white" )
116- ax .set_facecolor (graph_fg_color )
117- fig .set_facecolor (graph_bg_color )
118- ax .spines ["top" ].set_color (spine_color )
119- ax .spines ["bottom" ].set_color (spine_color )
120- ax .spines ["left" ].set_color (spine_color )
121- ax .spines ["right" ].set_color (spine_color )
122- fig .set_size_inches (graph_width / 100 , graph_height / 100 , forward = True )
123- ax .set_xticklabels (grouped_data ["Date" ], rotation = 45 , ha = 'right' )
115+ fig1 , ax1 = plt .subplots ()
116+ ax1 .bar (grouped_data ["Date" ], grouped_data ["Duration" ], color = graph_color )
117+ ax1 .set_xlabel ("Date" , color = font_color )
118+ ax1 .set_ylabel ("Duration in minutes" , color = font_color )
119+ ax1 .set_title ("Time Spent by Date" , color = font_color )
120+ ax1 .tick_params (colors = "white" )
121+ ax1 .set_facecolor (graph_fg_color )
122+ fig1 .set_facecolor (graph_bg_color )
123+ ax1 .spines ["top" ].set_color (spine_color )
124+ ax1 .spines ["bottom" ].set_color (spine_color )
125+ ax1 .spines ["left" ].set_color (spine_color )
126+ ax1 .spines ["right" ].set_color (spine_color )
127+ fig1 .set_size_inches (graph_width / 100 , graph_height / 100 , forward = True )
128+ ax1 .set_xticklabels (grouped_data ["Date" ], rotation = 45 , ha = 'right' )
124129
125130 date_format = mdates .DateFormatter ("%d/%m" )
126- ax .xaxis .set_major_formatter (date_format )
127- ax .xaxis .set_major_locator (MaxNLocator (integer = True , prune = 'both' ))
128- time_spent_frame = FigureCanvasTkAgg (fig , master = statistics_frame )
131+ ax1 .xaxis .set_major_formatter (date_format )
132+ ax1 .xaxis .set_major_locator (MaxNLocator (integer = True , prune = 'both' ))
133+ time_spent_frame = FigureCanvasTkAgg (fig1 , master = statistics_frame )
129134 plt .subplots_adjust (bottom = 0.2 )
130135
131136 time_spent_graph = time_spent_frame .get_tk_widget ()
@@ -207,35 +212,36 @@ def my_format(pct):
207212
208213
209214def create_weekday_graph (day_duration_list , day_name_list ):
215+ global pie_color_1 , pie_color_2 , pie_color_3 , pie_color_4 , pie_color_5 , pie_color_6 , pie_color_7
210216 non_zero_durations = [duration for duration in day_duration_list if duration != 0 ]
211217 non_zero_names = [name for name , duration in zip (day_name_list , day_duration_list ) if duration != 0 ]
212218
213- fig , ax = plt .subplots ()
214- ax .pie (non_zero_durations , labels = non_zero_names , autopct = autopct_format (non_zero_durations ),
215- colors = [pie_color_orange_1 , pie_color_orange_2 , pie_color_orange_3 , pie_color_orange_4 , pie_color_orange_5 , pie_color_orange_6 , pie_color_orange_7 ],
219+ fig2 , ax2 = plt .subplots ()
220+ ax2 .pie (non_zero_durations , labels = non_zero_names , autopct = autopct_format (non_zero_durations ),
221+ colors = [pie_color_1 , pie_color_2 , pie_color_3 , pie_color_4 , pie_color_5 , pie_color_6 , pie_color_7 ],
216222 textprops = {"fontsize" : pie_font_size , "family" : pie_font_family , "color" : font_color }, counterclock = False , startangle = 90 )
217- fig .set_size_inches (graph_width / 100 , graph_height / 100 , forward = True )
218- fig .set_facecolor (graph_bg_color )
219- ax .tick_params (colors = "white" )
220- ax .set_facecolor (graph_fg_color )
221- ax .set_title ("Time Spent by Weekday" , color = font_color )
222- ax .spines ["top" ].set_color (spine_color )
223- ax .spines ["bottom" ].set_color (spine_color )
224- ax .spines ["left" ].set_color (spine_color )
225- ax .spines ["right" ].set_color (spine_color )
226-
227- weekday_frame = FigureCanvasTkAgg (fig , master = statistics_frame )
223+ fig2 .set_size_inches (graph_width / 100 , graph_height / 100 , forward = True )
224+ fig2 .set_facecolor (graph_bg_color )
225+ ax2 .tick_params (colors = "white" )
226+ ax2 .set_facecolor (graph_fg_color )
227+ ax2 .set_title ("Time Spent by Weekday" , color = font_color )
228+ ax2 .spines ["top" ].set_color (spine_color )
229+ ax2 .spines ["bottom" ].set_color (spine_color )
230+ ax2 .spines ["left" ].set_color (spine_color )
231+ ax2 .spines ["right" ].set_color (spine_color )
232+
233+ weekday_frame = FigureCanvasTkAgg (fig2 , master = statistics_frame )
228234
229235 weekday_graph = weekday_frame .get_tk_widget ()
230236 weekday_graph .grid (row = 0 , column = 1 , padx = 10 , pady = 10 )
231237 weekday_graph .config (highlightbackground = frame_border_color , highlightthickness = 2 , background = frame_color )
232238
233239
234240def collect_data ():
235- global data_amount , date_list , duration_list
241+ global data_amount , date_list , duration_list , goal_amount , total_duration , day_duration_list , day_name_list
236242 global monday_amount , tuesday_amount , wednesday_amount , thursday_amount , friday_amount , saturday_amount , sunday_amount
237243 global monday_duration , tuesday_duration , wednesday_duration , thursday_duration , friday_duration , saturday_duration , sunday_duration
238- global color , default_color
244+ global color , default_color , pie_color_1 , pie_color_2 , pie_color_3 , pie_color_4 , pie_color_5 , pie_color_6 , pie_color_7
239245
240246 data_amount = int (worksheet ["Z1" ].value )
241247
@@ -255,10 +261,17 @@ def collect_data():
255261 saturday_duration = int (worksheet ["W6" ].value )
256262 sunday_duration = int (worksheet ["W7" ].value )
257263
264+ goal_amount = int (worksheet ["R1" ].value )
265+
258266 color = worksheet ["T1" ].value
259267 if color == None :
260268 color = "Orange"
261269 default_color = ctk .StringVar (value = color )
270+ pie_colors = {"Orange" : [pie_color_orange_1 , pie_color_orange_2 , pie_color_orange_3 , pie_color_orange_4 , pie_color_orange_5 , pie_color_orange_6 , pie_color_orange_7 ],
271+ "Green" : [pie_color_green_1 , pie_color_green_2 , pie_color_green_3 , pie_color_green_4 , pie_color_green_5 , pie_color_green_6 , pie_color_green_7 ],
272+ "Blue" : [pie_color_blue_1 , pie_color_blue_2 , pie_color_blue_3 , pie_color_blue_4 , pie_color_blue_5 , pie_color_blue_6 , pie_color_blue_7 ]}
273+ pie_color_1 , pie_color_2 , pie_color_3 , pie_color_4 , pie_color_5 , pie_color_6 , pie_color_7 = pie_colors [color ]
274+
262275
263276 day_duration_list = [monday_duration , tuesday_duration , wednesday_duration , thursday_duration , friday_duration , saturday_duration , sunday_duration ]
264277 day_name_list = ["Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" ]
@@ -271,6 +284,9 @@ def collect_data():
271284 elif "-" in str (worksheet ["B" + str (data )].value ):
272285 date_list .append (datetime .datetime .strptime (str (worksheet ["B" + str (data )].value ).split (" " )[0 ], "%Y-%m-%d" ).date ())
273286 duration_list .append (round (worksheet ["C" + str (data )].value ))
287+
288+ total_duration = sum (duration_list )
289+
274290 create_time_spent_graph (date_list , duration_list )
275291 print ("Data collected." )
276292
@@ -284,7 +300,7 @@ def collect_data():
284300 workbook = op .Workbook ()
285301 worksheet = workbook .active
286302
287- data_amount = 0
303+ data_amount , goal_amount = 0 , 0
288304
289305 monday_amount , tuesday_amount , wednesday_amount , thursday_amount , friday_amount , saturday_amount , sunday_amount = 0 , 0 , 0 , 0 , 0 , 0 , 0
290306
@@ -344,10 +360,12 @@ def update_break_time():
344360
345361#------------------------------------------------------------------------------DATA-----------------------------------------------------------------------------#
346362def save_data ():
347- global data_amount , duration_list , date_list
363+ global data_amount , duration_list , date_list , goal_amount , time_studied_label , total_duration , times_studied_label , progressbar
348364 global timer_running , timer_time , start_time , timer_btn , timer_label
349365 global break_running , break_time , break_btn , break_label
350366
367+ progressbar .set (0 )
368+
351369 if timer_time < 60 :
352370 print ("No data to save." )
353371 return
@@ -371,13 +389,21 @@ def save_data():
371389 break_display_label .configure (text = "0:00:00" )
372390 start_time = ""
373391 workbook .save (data_file )
392+
393+ if timer_time / 60 >= goal :
394+ progressbar .set (1 )
395+ goal_amount += 1
396+ worksheet ["R1" ].value = goal_amount
397+ times_studied_label .configure (text = goal_amount )
398+
374399 print ("Data saved." )
375400 save_weekday ()
376401 collect_data ()
402+ time_studied_label .configure (text = total_duration )
377403
378404
379405def reset_data ():
380- global data_amount , duration_list , date_list
406+ global data_amount , duration_list , date_list , goal_amount , total_duration , times_studied_label , time_studied_label
381407 global timer_time , timer_running , time_display_label
382408 global break_time , break_running , break_display_label
383409 global monday_duration , tuesday_duration , wednesday_duration , thursday_duration , friday_duration , saturday_duration , sunday_duration
@@ -397,6 +423,9 @@ def reset_data():
397423 monday_duration , tuesday_duration , wednesday_duration , thursday_duration , friday_duration , saturday_duration , sunday_duration = 0 , 0 , 0 , 0 , 0 , 0 , 0
398424 day_duration_list = [monday_duration , tuesday_duration , wednesday_duration , thursday_duration , friday_duration , saturday_duration , sunday_duration ]
399425 day_name_list = ["Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" ]
426+ goal_amount , total_duration = 0 , 0
427+ time_studied_label .configure (text = "0" )
428+ times_studied_label .configure (text = "0" )
400429 duration_list .clear ()
401430 date_list .clear ()
402431
@@ -450,7 +479,6 @@ def get_goal():
450479 if "hour" not in choice :
451480 x += int (choice .split (" " )[0 ])
452481 goal = x
453- print (goal )
454482
455483
456484def update_slider (timer_time ):
@@ -459,38 +487,47 @@ def update_slider(timer_time):
459487 goal = 60
460488 if (timer_time / 60 ) < goal :
461489 progressbar .set ((timer_time / 60 )/ goal )
462- else :
463- set_streak (goal , timer_time , progressbar )
464490
465- def set_streak (goal , timer_time , progressbar ):
466- if timer_time >= goal :
467- progressbar .set (1 )
468- worksheet ["E" + str ((data_amount + 1 ))].value = 1
469491
470492def load_color (color , widget_list , progressbar ):
493+ global graph_color , pie_color_1 , pie_color_2 , pie_color_3 , pie_color_4 , pie_color_5 , pie_color_6 , pie_color_7
494+ pie_colors = {"Orange" : [pie_color_orange_1 , pie_color_orange_2 , pie_color_orange_3 , pie_color_orange_4 , pie_color_orange_5 , pie_color_orange_6 , pie_color_orange_7 ],
495+ "Green" : [pie_color_green_1 , pie_color_green_2 , pie_color_green_3 , pie_color_green_4 , pie_color_green_5 , pie_color_green_6 , pie_color_green_7 ],
496+ "Blue" : [pie_color_blue_1 , pie_color_blue_2 , pie_color_blue_3 , pie_color_blue_4 , pie_color_blue_5 , pie_color_blue_6 , pie_color_blue_7 ]}
497+ pie_color_1 , pie_color_2 , pie_color_3 , pie_color_4 , pie_color_5 , pie_color_6 , pie_color_7 = pie_colors [color ]
471498 highlight_colors = {"Orange" : orange_highlight_color , "Green" : green_highlight_color , "Blue" : blue_highlight_color }
472499 highlight_color = highlight_colors [color ]
473500 colors = {"Orange" : orange_button_color , "Green" : green_button_color , "Blue" : blue_button_color }
474501 color = colors [color ]
502+ graph_color = color
475503 change_color (color , highlight_color , widget_list , progressbar )
476504
477505
478506def change_color (color , highlight_color , widget_list , progressbar ):
507+ global date_list , duration_list , day_duration_list , day_name_list
508+ colors = {orange_button_color : "Orange" , green_button_color : "Green" , blue_button_color : "Blue" }
509+ worksheet ["T1" ].value = colors [color ]
510+ workbook .save (data_file )
511+ collect_data ()
479512 for widget in widget_list :
480513 widget .configure (fg_color = color , hover_color = highlight_color )
481514 progressbar .configure (progress_color = color )
482515
483-
484516def set_color (widget ):
485- global color
517+ global color , graph_color , pie_color_1 , pie_color_2 , pie_color_3 , pie_color_4 , pie_color_5 , pie_color_6 , pie_color_7 , day_duration_list , day_name_list
486518 worksheet ["T1" ].value = color
487519 workbook .save (data_file )
488520 print ("Color saved." )
489521 color = widget .get ()
490522 colors = {"Orange" : orange_button_color , "Green" : green_button_color , "Blue" : blue_button_color }
491523 highlight_colors = {"Orange" : orange_highlight_color , "Green" : green_highlight_color , "Blue" : blue_highlight_color }
524+ pie_colors = {"Orange" : [pie_color_orange_1 , pie_color_orange_2 , pie_color_orange_3 , pie_color_orange_4 , pie_color_orange_5 , pie_color_orange_6 , pie_color_orange_7 ],
525+ "Green" : [pie_color_green_1 , pie_color_green_2 , pie_color_green_3 , pie_color_green_4 , pie_color_green_5 , pie_color_green_6 , pie_color_green_7 ],
526+ "Blue" : [pie_color_blue_1 , pie_color_blue_2 , pie_color_blue_3 , pie_color_blue_4 , pie_color_blue_5 , pie_color_blue_6 , pie_color_blue_7 ]}
527+ pie_color_1 , pie_color_2 , pie_color_3 , pie_color_4 , pie_color_5 , pie_color_6 , pie_color_7 = pie_colors [color ]
492528 c = colors [color ]
493529 highlight_color = highlight_colors [color ]
530+ graph_color = c
494531 change_color (c , highlight_color , widget_list , progressbar )
495532
496533#------------------------------------------------------------------------------GUI------------------------------------------------------------------------------#
@@ -530,10 +567,23 @@ def change_focus(event):
530567progressbar .place (anchor = "center" , relx = 0.5 , rely = 0.65 )
531568progressbar .set (0 )
532569
533- streak_frame = ctk .CTkFrame (goal_progress_frame , fg_color = frame_color , width = frame_width , corner_radius = 10 , height = 120 )
570+ streak_frame = ctk .CTkFrame (goal_progress_frame , fg_color = frame_color , width = frame_width , corner_radius = 10 , height = 220 )
534571streak_frame .pack (padx = frame_padding , pady = frame_padding )
535572streak_label = ctk .CTkLabel (streak_frame , text = "Streak" , font = (font_family , int (font_size )), text_color = font_color )
536573streak_label .place (anchor = "nw" , relx = 0.05 , rely = 0.05 )
574+ times_studied_text = ctk .CTkLabel (streak_frame , text = "Goal\n reached" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
575+ times_studied_text .place (anchor = "center" , relx = 0.3 , rely = 0.4 )
576+ times_studied_label = ctk .CTkLabel (streak_frame , text = goal_amount , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
577+ times_studied_label .place (anchor = "center" , relx = 0.3 , rely = 0.6 )
578+ times_reached_label = ctk .CTkLabel (streak_frame , text = "times" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
579+ times_reached_label .place (anchor = "center" , relx = 0.3 , rely = 0.8 )
580+
581+ time_studied_text = ctk .CTkLabel (streak_frame , text = "Time\n studied" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
582+ time_studied_text .place (anchor = "center" , relx = 0.7 , rely = 0.4 )
583+ time_studied_label = ctk .CTkLabel (streak_frame , text = total_duration , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
584+ time_studied_label .place (anchor = "center" , relx = 0.7 , rely = 0.6 )
585+ time_reached_label = ctk .CTkLabel (streak_frame , text = "minutes" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
586+ time_reached_label .place (anchor = "center" , relx = 0.7 , rely = 0.8 )
537587
538588timer_break_frame = ctk .CTkFrame (main_frame , height = (HEIGHT - button_height * 1.5 ), width = frame_width )
539589timer_break_frame .grid (row = 0 , column = 1 )
0 commit comments