1- import os
21import datetime
32
4- import openpyxl as op
53from openpyxl .styles import Font
4+ from .styles import *
5+
6+ import customtkinter as ctk
67
78class DataManager :
89 def __init__ (self , App , timer_manager , workbook , worksheet ):
@@ -14,20 +15,28 @@ def __init__(self, App, timer_manager, workbook, worksheet):
1415
1516
1617 def initialize_variables (self ):
18+ self .day_name_list = ["Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" ]
1719 self .date_list = []
1820 self .duration_list = []
1921 self .total_duration = 0
22+ self .graph_color = "#f38064"
23+ self .widget_list = []
2024
2125
2226 def initialize_new_file_variables (self ):
2327 self .goal_amount = 0
2428 self .data_amount = 0
29+ self .monday_duration = self .tuesday_duration = self .wednesday_duration = self .thursday_duration = self .friday_duration = self .saturday_duration = self .sunday_duration = 0
30+ self .color_name = "Orange"
31+ self .save_color (self .color_name )
2532
2633
2734 def collect_data (self ):
2835 self .data_amount = int (self .worksheet ["Z2" ].value )
2936 self .goal_amount = int (self .worksheet ["R2" ].value )
3037
38+ self .collect_day_data ()
39+
3140 print ("Data collected." )
3241
3342
@@ -44,11 +53,10 @@ def data_to_variable(self):
4453
4554 def save_data (self ):
4655 self .initialize_variables ()
56+ self .save_weekday ()
57+ self .save_color (self .color_name )
4758
4859 self .data_amount += 1
49-
50- self .timer_time = self .timer_manager .timer_time
51- self .break_time = self .timer_manager .break_time
5260
5361 self .stop_time = datetime .datetime .now ()
5462
@@ -68,8 +76,10 @@ def write_to_excel(self):
6876 self .worksheet ["A" + str ((self .data_amount + 1 ))].value = self .start_time .strftime ("%d/%m/%Y %H:%M" )
6977 self .worksheet ["B" + str ((self .data_amount + 1 ))].value = self .stop_time .strftime ("%d/%m/%Y %H:%M" )
7078 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
79+ self .worksheet ["D" + str ((self .data_amount + 1 ))].value = self .timer_manager .break_time / 60
80+
7281 self .worksheet ["R2" ].value = self .goal_amount
82+
7383 self .worksheet ["Z2" ].value = self .data_amount
7484 self .workbook .save (self .app .data_file )
7585
@@ -83,25 +93,40 @@ def customize_excel(self):
8393 self .worksheet ["R1" ].value = "Goals reached:"
8494 self .worksheet ["R2" ].value = self .goal_amount
8595
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 )
96+ self .worksheet ["T2" ].value = self .color_name
97+
98+ self .worksheet ["W2" ].value = self .monday_duration
99+ self .worksheet ["W3" ].value = self .tuesday_duration
100+ self .worksheet ["W4" ].value = self .wednesday_duration
101+ self .worksheet ["W5" ].value = self .thursday_duration
102+ self .worksheet ["W6" ].value = self .friday_duration
103+ self .worksheet ["W7" ].value = self .saturday_duration
104+ self .worksheet ["W8" ].value = self .sunday_duration
91105
92106 self .worksheet ["Z1" ].value = "Data amount: "
93107 self .worksheet ["Z1" ].font = Font (bold = True , size = 14 )
94108 self .worksheet ["Z2" ].value = self .data_amount
109+
110+ self .style_excel ()
111+
95112 self .workbook .save (self .app .data_file )
96113 print ("Excel customized." )
97114
98115
116+ def style_excel (self ):
117+ self .worksheet ["A1" ].font = Font (bold = True , size = 14 )
118+ self .worksheet ["B1" ].font = Font (bold = True , size = 14 )
119+ self .worksheet ["C1" ].font = Font (bold = True , size = 14 )
120+ self .worksheet ["D1" ].font = Font (bold = True , size = 14 )
121+ self .worksheet ["E1" ].font = Font (bold = True , size = 14 )
122+
123+
99124 def get_start_time (self ):
100125 self .start_time = datetime .datetime .now ()
101126
102127
103128 def calculate_duration (self ):
104- duration = self .timer_time - self .break_time
129+ duration = self .timer_manager . timer_time - self . timer_manager .break_time
105130 if duration < 0 :
106131 duration = 0
107132 else :
@@ -110,9 +135,7 @@ def calculate_duration(self):
110135
111136
112137 def increase_goal_streak (self ):
113- print ("AAA" )
114138 self .goal_amount += 1
115- print (self .goal_amount )
116139
117140
118141 def reset_data (self , workbook , worksheet ):
@@ -124,4 +147,86 @@ def reset_data(self, workbook, worksheet):
124147
125148 self .workbook .save (self .app .data_file )
126149
127- print ("Data reset." )
150+ print ("Data reset." )
151+
152+
153+ def clear_graph_lists (self ):
154+ self .date_list .clear ()
155+ self .duration_list .clear ()
156+
157+
158+ def collect_day_data (self ):
159+ monday_duration = int (self .worksheet ["W2" ].value )
160+ tuesday_duration = int (self .worksheet ["W3" ].value )
161+ wednesday_duration = int (self .worksheet ["W4" ].value )
162+ thursday_duration = int (self .worksheet ["W5" ].value )
163+ friday_duration = int (self .worksheet ["W6" ].value )
164+ saturday_duration = int (self .worksheet ["W7" ].value )
165+ sunday_duration = int (self .worksheet ["W8" ].value )
166+
167+ day_duration_list = [monday_duration , tuesday_duration , wednesday_duration , thursday_duration , friday_duration , saturday_duration , sunday_duration ]
168+ return day_duration_list
169+
170+
171+ def save_weekday (self ):
172+ duration = self .calculate_duration ()
173+ weekday_today = datetime .datetime .now ().weekday ()
174+
175+ match weekday_today :
176+ case 0 :
177+ self .monday_duration += duration
178+ self .worksheet ["W2" ].value = self .monday_duration
179+ case 1 :
180+ self .tuesday_duration += duration
181+ self .worksheet ["W3" ].value = self .tuesday_duration
182+ case 2 :
183+ self .wednesday_duration += duration
184+ self .worksheet ["W4" ].value = self .wednesday_duration
185+ case 3 :
186+ self .thursday_duration += duration
187+ self .worksheet ["W5" ].value = self .thursday_duration
188+ case 4 :
189+ self .friday_duration += duration
190+ self .worksheet ["W6" ].value = self .friday_duration
191+ case 5 :
192+ self .saturday_duration += duration
193+ self .worksheet ["W7" ].value = self .saturday_duration
194+ case 6 :
195+ self .sunday_duration += duration
196+ self .worksheet ["W8" ].value = self .sunday_duration
197+
198+ self .workbook .save (self .app .data_file )
199+ print ("Weekday saved." )
200+
201+
202+ def set_color (self , color_dropdown ):
203+ color_name = color_dropdown .get ()
204+ print ("Color set." )
205+ self .save_color (color_name )
206+
207+
208+ def save_color (self , color_name ):
209+ self .worksheet ["T2" ].value = color_name
210+ self .load_color ()
211+
212+
213+ def load_color (self ):
214+ color_name = self .worksheet ["T2" ].value
215+ self .app .color_dropdown .configure (variable = ctk .StringVar (value = color_name ))
216+ colors = {"Orange" : [orange_button_color , orange_highlight_color , orange_pie_colors ],
217+ "Green" : [green_button_color , green_highlight_color , green_pie_colors ],
218+ "Blue" : [blue_button_color , blue_highlight_color , blue_pie_colors ]}
219+
220+ self .color = colors [color_name ][0 ]
221+ self .highlight_color = colors [color_name ][1 ]
222+ self .pie_colors = colors [color_name ][2 ]
223+ self .graph_color = self .color
224+ print ("Color loaded." )
225+ self .change_color (self .color , self .highlight_color )
226+
227+
228+ def change_color (self , color , highlight_color ):
229+ for widget in self .widget_list :
230+ widget .configure (fg_color = color , hover_color = highlight_color )
231+ self .app .progressbar .configure (progress_color = color )
232+ print ("Color changed." )
0 commit comments