Commit b6abe573 authored by Saswat's avatar Saswat

remove test.py

parent 49851b1a
No preview for this file type
from dbhandler import *
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import numpy as np
db = DBHandler('data/activity_data.db')
today = datetime.today()
data = db.read_week_data(date=today)
start = today - timedelta(days=today.weekday())
weekly_sum = np.zeros(7)
daily_sum = np.zeros(24)
app_time = dict()
week_ind = np.arange(7)
for entry in data:
timestamp = datetime.fromtimestamp(entry[0])
currdate = timestamp.date()
day = currdate.weekday()
if currdate == today.date():
daily_sum[timestamp.hour] += entry[2]
if entry[1] in app_time:
app_time[entry[1]] += entry[2]
else:
app_time[entry[1]] = entry[2]
weekly_sum[day] += entry[2]
print(weekly_sum)
max = np.max(weekly_sum)
print(max)
time_format = "min"
app_time = dict(sorted(app_time.items(), key=lambda x:x[1],reverse=True))
max_app_time = list(app_time.items())[0][1]
print(max_app_time)
if max > 60*60:
time_format = "hr"
weekly_sum /= 3600
else:
weekly_sum /= 60
print(daily_sum)
figure1 = plt.Figure(figsize=(6, 5), dpi=100)
ax1 = figure1.add_subplot(111)
#bar1 = FigureCanvasTkAgg(figure1, root)
#bar1.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH)
ax1.bar(week_day, weekly_sum, width = 0.35)
ax1.set_xlabel("Week Days")
ax1.set_ylabel(f"Total Screen Time in {time_format}")
ax1.set_title("Total daily screen time in a week")
figure1.savefig('weekly.png')
figure2 = plt.Figure(figsize=(6, 5), dpi=100)
ax2 = figure2.add_subplot(111)
#bar1 = FigureCanvasTkAgg(figure1, root)
#bar1.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH)
ax2.bar(np.arange(24), daily_sum, width = 0.35)
ax2.set_xlabel("Hour of the day")
ax2.set_ylabel(f"Total Screen Time in sec")
ax2.set_title("Total hourly screen time in a day")
figure2.savefig('daily.png')
figure3 = plt.Figure(figsize=(6, 5), dpi=100)
ax3 = figure3.add_subplot(111)
#bar1 = FigureCanvasTkAgg(figure1, root)
#bar1.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH)
print(list(app_time.keys()))
print(list(app_time.values()))
ax3.barh(list(app_time.keys())[::-1], list(app_time.values())[::-1])
ax3.set_xlabel("Time spent on the application")
ax3.set_ylabel("Applications")
ax3.set_title("Activity per Application")
figure3.savefig('perapp.png')
exit()
app_set = set()
for entry in data:
if entry[1] not in app_set:
app_set.add(entry[1])
week_data = np.zeros(len(app_set), 8)
week_data = week_data.sort(key=lambda item: item[7], reverse = True)
ind = np.arange(7)
width = 0.35
fig = plt.subplots(figsize =(10, 7))
prev_sum = np.zeros(0,7)
for i in len(week_data):
plt.bar(ind, week_data[i][0:7], width, bottom = prev_sum)
prev_sum += week_data[i][0:7]
plt.ylabel('Screen Time')
plt.title('Dates')
plt.xticks(ind, )
plt.yticks(np.arange(0, 81, 10))
plt.legend((p1[0], p2[0]), ('boys', 'girls'))
plt.show()
plt.plot([0,1,2], [2,3,4])
plt.legend()
\ No newline at end of file
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