Skip to content

Commit 4fefc69

Browse files
committed
Cumulative Time Graph Fix
1 parent d235099 commit 4fefc69

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

main.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def _file_setup(self) -> None:
103103

104104

105105
def initialize_variables(self) -> None:
106+
self.graph_limit = True
106107
self.statistics_scroll_position = "left"
107108
self.achievements_scroll_position = "left"
108109
self.scrolling = False
@@ -700,26 +701,34 @@ def _my_format(pct):
700701

701702

702703
def create_total_time_graph(self, frame):
704+
def group_lists(list_of_dates, list_of_durations):
705+
date_list = []
706+
duration_list = []
707+
index = 0
708+
cumulative_duration = 0
709+
while index < len(list_of_dates):
710+
current_date = list_of_dates[index]
711+
while index < len(list_of_dates) and list_of_dates[index] == current_date:
712+
cumulative_duration += list_of_durations[index]
713+
index += 1
714+
date_list.append(current_date)
715+
duration_list.append(cumulative_duration)
716+
717+
return date_list, duration_list
718+
719+
703720
dates = self.data_manager.date_list.copy()
704721
times = self.data_manager.duration_list.copy()
705722

723+
dates, times = group_lists(dates, times)
724+
706725
if times:
707726
dates.insert(0, (dates[0] - datetime.timedelta(days=1)))
708727
times.insert(0, 0)
709728

710-
711-
# Calculate cumulative time
712-
cumulative_times = [sum(times[:i+1]) for i in range(len(times))]
713-
714-
# Create subplot
715-
fig, ax = plt.subplots(figsize=(5, 5))
716-
717-
# Plot
718-
ax.plot(dates, cumulative_times, color=self.data_manager.color)
719-
720729
fig, ax = plt.subplots()
721-
ax.plot(dates, cumulative_times, color=self.data_manager.graph_color)
722-
ax.fill_between(dates, cumulative_times, color=self.data_manager.graph_color)
730+
ax.plot(dates, times, color=self.data_manager.graph_color)
731+
ax.fill_between(dates, times, color=self.data_manager.graph_color)
723732
ax.set_title("Cumulative Time By Date", color=self.data_manager.font_color)
724733
ax.tick_params(colors=self.data_manager.font_color)
725734
ax.set_facecolor(self.data_manager.graph_fg_color)
@@ -751,6 +760,10 @@ def clear_frame(self, frame):
751760
widget.destroy()
752761

753762
def create_graphs(self) -> None:
763+
if self.graph_limit == True:
764+
self.graph_limit = False
765+
return
766+
754767
self.statistics_frame.grid_propagate(False)
755768
plt.close("all")
756769
self.clear_frame(self.statistics_facts_frame)

0 commit comments

Comments
 (0)