Commit 49851b1a authored by Saswat's avatar Saswat

add different color in plotter

parent 3f04ec12
No preview for this file type
...@@ -8,13 +8,14 @@ import matplotlib.pyplot as plt ...@@ -8,13 +8,14 @@ import matplotlib.pyplot as plt
class ActivityPlotter: class ActivityPlotter:
def __init__(self) -> None: def __init__(self) -> None:
config = load_config() config = load_config()
plt.rcParams.update({'font.size': 16})
self.db = DBHandler(config['DATABASE_FILE']) self.db = DBHandler(config['DATABASE_FILE'])
self.week_days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] self.week_days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
#self.curr_week = datetime.fromtimestamp(0) #self.curr_week = datetime.fromtimestamp(0)
def __init_dataholders(self): def __init_dataholders(self):
self.perday = np.zeros(7) self.perday = np.zeros(7, dtype=float)
self.perhour = np.zeros(24) self.perhour = np.zeros(24, dtype= float)
self.perapp = dict() self.perapp = dict()
return return
...@@ -37,36 +38,55 @@ class ActivityPlotter: ...@@ -37,36 +38,55 @@ class ActivityPlotter:
self.perapp = dict(sorted(self.perapp.items(), key=lambda x:x[1],reverse=True)) self.perapp = dict(sorted(self.perapp.items(), key=lambda x:x[1],reverse=True))
def __quantise_time(self, time_list):
max = np.max(time_list)
time_format = "mins"
if max > 2*60*60:
time_format = "hrs"
time_list /= 3600
else:
time_list /= 60
return time_list, time_format
def __get_week_plot(self): def __get_week_plot(self):
figure = plt.Figure(figsize=(10, 5), dpi=70) figure = plt.Figure(figsize=(10, 5), dpi=70)
ax = figure.add_subplot(111) ax = figure.add_subplot(111)
ax.bar(self.week_days, self.perday, width = 0.35)
q_perday, time_format = self.__quantise_time(self.perday)
ax.bar(self.week_days, q_perday, width = 0.35)
ax.patches[self.curr_date.date().weekday()].set_color('r')
ax.set_xlabel("Week Days") ax.set_xlabel("Week Days")
ax.set_ylabel(f"Total Screen Time in min") ax.set_ylabel(f"Total Screen Time in {time_format}")
ax.set_title("Total daily screen time in a week") ax.set_title("Total daily screen time in a week")
figure.tight_layout()
return figure return figure
def __get_day_plot(self): def __get_day_plot(self):
figure = plt.Figure(figsize=(10, 5), dpi=70) figure = plt.Figure(figsize=(10, 5), dpi=70)
ax = figure.add_subplot(111) ax = figure.add_subplot(111)
ax.bar(np.arange(24), self.perhour, width = 0.35)
q_perhour, time_format = self.__quantise_time(self.perhour)
ax.bar(np.arange(24), q_perhour, width = 0.35)
ax.set_xlabel("Hour of the day") ax.set_xlabel("Hour of the day")
ax.set_ylabel(f"Total Screen Time in sec") ax.set_ylabel(f"Total Screen Time in {time_format}")
ax.set_title("Total hourly screen time in a day") ax.set_title("Total hourly screen time in a day")
figure.savefig('daily.png') figure.tight_layout()
return figure return figure
def __get_app_plot(self): def __get_app_plot(self):
figure = plt.Figure(figsize=(6, 10), dpi=70) figure = plt.Figure(figsize=(6, 10), dpi=70)
ax = figure.add_subplot(111) ax = figure.add_subplot(111)
ax.barh(list(self.perapp.keys())[::-1], list(self.perapp.values())[::-1]) q_perapp, time_format = self.__quantise_time(np.array(list(self.perapp.values())[::-1], dtype=float))
ax.barh(list(self.perapp.keys())[::-1], q_perapp)
#for bar, app, values in zip(ax.patches, list(self.perapp.keys())[::-1], list(self.perapp.values())[::-1]):
# ax.text(bar.get_x()+bar.get_width()+ 3, bar.get_y()+bar.get_height()/2, values, color = 'black', va = 'center')
ax.set_xlabel("Time spent on the application") ax.set_xlabel(f"Time spent in {time_format}")
ax.set_ylabel("Applications") ax.set_ylabel("Applications")
ax.set_title("Activity per Application") ax.set_title("Activity per Application")
figure.savefig('perapp.png') figure.tight_layout()
return figure return figure
def get_figs(self, timestamp:datetime): def get_figs(self, timestamp:datetime):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment