87 lines
2.2 KiB
Python
87 lines
2.2 KiB
Python
def time_distribution(store):
|
|
# json.dump(store.serializable(), open("new.json", "w"), indent=1)
|
|
from collections import defaultdict
|
|
import json
|
|
import numpy as np
|
|
|
|
keys = [
|
|
"simu",
|
|
"question",
|
|
"image",
|
|
"audio",
|
|
"video",
|
|
"other",
|
|
"map"
|
|
]
|
|
import matplotlib.pyplot as plt
|
|
|
|
# results = []
|
|
|
|
places = defaultdict(list)
|
|
|
|
for log in store.get_all():
|
|
result = defaultdict(lambda: 0)
|
|
for i in log.get()['track']:
|
|
duration = i['properties']['end_timestamp'] - i['properties']['start_timestamp']
|
|
result[i['properties']['activity_type']] += duration
|
|
print(json.dumps(result, indent=4))
|
|
total = sum(result.values())
|
|
print(total)
|
|
percentage = defaultdict(lambda: 0)
|
|
minutes = defaultdict(lambda: 0)
|
|
for i in result:
|
|
percentage[i] = result[i] / total
|
|
minutes[i] = result[i] / 60_000
|
|
print(json.dumps(percentage, indent=4))
|
|
if not 'error' in result:
|
|
# places[log.get()['instance']].append(percentage)
|
|
places[log.get()['instance']].append(minutes)
|
|
|
|
for place in places:
|
|
places[place] = sorted(places[place], key=lambda item: item['map'])
|
|
|
|
dummy = [0] * len(keys)
|
|
results = []
|
|
sites = []
|
|
from util.meta_temp import CONFIG_NAMES
|
|
|
|
for i in places:
|
|
for j in places[i]:
|
|
ordered = []
|
|
for k in keys:
|
|
ordered.append(j[k])
|
|
results.append(ordered)
|
|
results.append(dummy)
|
|
sites.append(CONFIG_NAMES[i] if i in CONFIG_NAMES else "---")
|
|
|
|
size = len(results)
|
|
ind = np.arange(size)
|
|
width = 0.9
|
|
print(results)
|
|
data = list(zip(*results))
|
|
print(data)
|
|
lines = []
|
|
bottom = [0] * len(results)
|
|
for i in range(0, len(data)):
|
|
lines.append(plt.bar(ind, data[i], bottom=bottom, width=width)[0])
|
|
for k, x in enumerate(data[i]):
|
|
bottom[k] += x
|
|
plt.legend(lines, keys)
|
|
plt.title(", ".join(sites))
|
|
plt.show()
|
|
|
|
# size = len(results)
|
|
# ind = np.arange(size)
|
|
# width = 0.9
|
|
# print(results)
|
|
# data = list(zip(*results))
|
|
# print(data)
|
|
# lines = []
|
|
# bottom = [0] * len(results)
|
|
# for i in range(0, len(data)):
|
|
# lines.append(plt.bar(ind, data[i], bottom=bottom, width=width)[0])
|
|
# for k, x in enumerate(data[i]):
|
|
# bottom[k] += x
|
|
# plt.legend(lines, keys)
|
|
# plt.title("Zwei Spiele in Filderstadt (t1=237min; t2=67min)")
|
|
# plt.show() |