WIP snapshot
parent
75f41fb9f5
commit
f0a6a1c8aa
108
log_analyzer.py
108
log_analyzer.py
|
|
@ -137,6 +137,13 @@ if __name__ == '__main__':
|
||||||
# "error"
|
# "error"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
loc_keys=[
|
||||||
|
"question",
|
||||||
|
"image",
|
||||||
|
"audio",
|
||||||
|
"video"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_data(store, relative_values=True, sort=True, show_errors=False):
|
def get_data(store, relative_values=True, sort=True, show_errors=False):
|
||||||
places = defaultdict(list)
|
places = defaultdict(list)
|
||||||
|
|
@ -182,6 +189,7 @@ if __name__ == '__main__':
|
||||||
pyproj.Proj(init='EPSG:32633'))
|
pyproj.Proj(init='EPSG:32633'))
|
||||||
return transform(project, track).length
|
return transform(project, track).length
|
||||||
|
|
||||||
|
|
||||||
whitelist = ['16fc3117-61db-4f50-b84f-81de6310206f', '5e64ce07-1c16-4d50-ac4e-b3117847ea43',
|
whitelist = ['16fc3117-61db-4f50-b84f-81de6310206f', '5e64ce07-1c16-4d50-ac4e-b3117847ea43',
|
||||||
'90278021-4c57-464e-90b1-d603799d07eb', 'ff8f1e8f-6cf5-4a7b-835b-5e2226c1e771']
|
'90278021-4c57-464e-90b1-d603799d07eb', 'ff8f1e8f-6cf5-4a7b-835b-5e2226c1e771']
|
||||||
|
|
||||||
|
|
@ -217,7 +225,7 @@ if __name__ == '__main__':
|
||||||
def get_all_data(store, sort=False, relative=True):
|
def get_all_data(store, sort=False, relative=True):
|
||||||
places = defaultdict(list)
|
places = defaultdict(list)
|
||||||
simu_distribution = defaultdict(lambda: 0)
|
simu_distribution = defaultdict(lambda: 0)
|
||||||
#divisiors = {"time":60_000, "space":1000000}
|
# divisiors = {"time":60_000, "space":1000000}
|
||||||
for log in store.get_all():
|
for log in store.get_all():
|
||||||
if not log.analysis() == analyzers.ActivityMapper:
|
if not log.analysis() == analyzers.ActivityMapper:
|
||||||
continue
|
continue
|
||||||
|
|
@ -244,8 +252,8 @@ if __name__ == '__main__':
|
||||||
percentage[i]["time"] = result["time"][i] / total_time
|
percentage[i]["time"] = result["time"][i] / total_time
|
||||||
else:
|
else:
|
||||||
percentage[i]["time"] = 0
|
percentage[i]["time"] = 0
|
||||||
for t in ("space","time"):
|
for t in ("space", "time"):
|
||||||
#total[i][t] += (result[t][i] / divisiors[t])
|
# total[i][t] += (result[t][i] / divisiors[t])
|
||||||
total[i][t] += result[t][i]
|
total[i][t] += result[t][i]
|
||||||
print(percentage)
|
print(percentage)
|
||||||
if not 'error' in result:
|
if not 'error' in result:
|
||||||
|
|
@ -254,11 +262,11 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
value = total
|
value = total
|
||||||
places[log.get()['instance']].append(value)
|
places[log.get()['instance']].append(value)
|
||||||
simus = defaultdict(lambda :0)
|
simus = defaultdict(lambda: 0)
|
||||||
for item in log.get()['boards']:
|
for item in log.get()['boards']:
|
||||||
if item["extra_data"]["activity_type"]=="simu":
|
if item["extra_data"]["activity_type"] == "simu":
|
||||||
simus[item["board_id"]] += 1
|
simus[item["board_id"]] += 1
|
||||||
simu_distribution[len(simus)]+=1
|
simu_distribution[len(simus)] += 1
|
||||||
|
|
||||||
if sort:
|
if sort:
|
||||||
for place in places:
|
for place in places:
|
||||||
|
|
@ -267,26 +275,28 @@ if __name__ == '__main__':
|
||||||
return places
|
return places
|
||||||
|
|
||||||
|
|
||||||
def stack_data(keys, places, type="time"):
|
def stack_data(keys, places, type="space"):
|
||||||
divisiors = {"time": 60_000, "space": 1000}
|
divisiors = {"time": 60_000, "space": 1000}
|
||||||
divisiors = {"time": 1, "space": 1}
|
#divisiors = {"time": 1, "space": 1}
|
||||||
dummy = [0] * len(keys)
|
dummy = [0] * len(keys)
|
||||||
results = []
|
results = []
|
||||||
sites = []
|
sites = []
|
||||||
for i in sorted(places):
|
for i in sorted(places):
|
||||||
if not i in whitelist:
|
if not i in whitelist:
|
||||||
continue
|
continue
|
||||||
for j in places[i]:
|
place = sorted(places[i], key=lambda item: item['map'][type])
|
||||||
|
for j in place:
|
||||||
ordered = []
|
ordered = []
|
||||||
for k in keys:
|
for k in keys:
|
||||||
if k in j:
|
if k in j:
|
||||||
ordered.append(j[k][type]/divisiors[type])
|
ordered.append(j[k][type] / divisiors[type])
|
||||||
else:
|
else:
|
||||||
ordered.append(0)
|
ordered.append(0)
|
||||||
print(sum(ordered))
|
print(sum(ordered))
|
||||||
if sum(ordered) > 0.9:
|
#if sum(ordered) > 0.9 and sum(ordered) < 4000 and sum(ordered)>10:
|
||||||
#print(sum(ordered), 1-sum(ordered))
|
if sum(ordered) > 0.9 and sum(ordered)<100:
|
||||||
#if sum(ordered)<1:
|
# print(sum(ordered), 1-sum(ordered))
|
||||||
|
# if sum(ordered)<1:
|
||||||
# ordered[-2] = 1-sum(ordered[:-2], ordered[-1])
|
# ordered[-2] = 1-sum(ordered[:-2], ordered[-1])
|
||||||
results.append(ordered)
|
results.append(ordered)
|
||||||
results.append(dummy)
|
results.append(dummy)
|
||||||
|
|
@ -296,8 +306,8 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
def plot_data(places, keys):
|
def plot_data(places, keys):
|
||||||
results, sites = stack_data(keys, places)
|
results, sites = stack_data(keys, places)
|
||||||
dpi=86.1
|
dpi = 86.1
|
||||||
plt.figure(figsize=(1280/dpi, 720/dpi))
|
plt.figure(figsize=(1280 / dpi, 720 / dpi))
|
||||||
size = len(results)
|
size = len(results)
|
||||||
print("{} elements total".format(size))
|
print("{} elements total".format(size))
|
||||||
ind = np.arange(size)
|
ind = np.arange(size)
|
||||||
|
|
@ -314,9 +324,9 @@ if __name__ == '__main__':
|
||||||
bottom[k] += x
|
bottom[k] += x
|
||||||
plt.legend(lines, keys)
|
plt.legend(lines, keys)
|
||||||
plt.title(", ".join(sites))
|
plt.title(", ".join(sites))
|
||||||
#plt.show()
|
# plt.show()
|
||||||
dpi=86
|
dpi = 86
|
||||||
plt.savefig("time_rel_{}.png".format(size), dpi=dpi,bbox_inches="tight")
|
plt.savefig("space_abs_{}.png".format(size), dpi=dpi, bbox_inches="tight")
|
||||||
|
|
||||||
|
|
||||||
colors = {
|
colors = {
|
||||||
|
|
@ -327,7 +337,8 @@ if __name__ == '__main__':
|
||||||
"video": "purple",
|
"video": "purple",
|
||||||
"other": "brown",
|
"other": "brown",
|
||||||
"map": "violet",
|
"map": "violet",
|
||||||
# "error":"grey"
|
# "error":"grey",
|
||||||
|
"tasks": "olive",
|
||||||
}
|
}
|
||||||
markers = [".", "o", "x", "s", "*", "D", "p", ",", "<", ">", "^", "v", "1", "2", "3", "4"]
|
markers = [".", "o", "x", "s", "*", "D", "p", ",", "<", ">", "^", "v", "1", "2", "3", "4"]
|
||||||
|
|
||||||
|
|
@ -348,11 +359,27 @@ if __name__ == '__main__':
|
||||||
# plt.clf()
|
# plt.clf()
|
||||||
# plt.close()
|
# plt.close()
|
||||||
|
|
||||||
|
def group_locationbased_tasks(data):
|
||||||
|
for id in data:
|
||||||
|
for log in data[id]:
|
||||||
|
loc = {"space":0,"time":0}
|
||||||
|
for k in log:
|
||||||
|
if k in loc_keys:
|
||||||
|
for i in ["space","time"]:
|
||||||
|
loc[i] += log[k][i]
|
||||||
|
log["tasks"] = loc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def plot_time_space_rel(combined, keys):
|
def plot_time_space_rel(combined, keys):
|
||||||
groups = defaultdict(list)
|
groups = defaultdict(list)
|
||||||
keys = list(keys)
|
keys = list(keys)
|
||||||
keys.remove("other")
|
keys.remove("other")
|
||||||
|
for i in loc_keys:
|
||||||
|
keys.remove(i)
|
||||||
|
keys.append("tasks")
|
||||||
ids = []
|
ids = []
|
||||||
|
group_locationbased_tasks(combined)
|
||||||
for k in keys:
|
for k in keys:
|
||||||
for id in sorted(combined):
|
for id in sorted(combined):
|
||||||
if id not in whitelist:
|
if id not in whitelist:
|
||||||
|
|
@ -363,15 +390,15 @@ if __name__ == '__main__':
|
||||||
count = 0
|
count = 0
|
||||||
for item in combined[id]:
|
for item in combined[id]:
|
||||||
if k in item:
|
if k in item:
|
||||||
time = item[k]["time"]/1000
|
time = item[k]["time"] / 1000
|
||||||
distance = item[k]["space"]
|
distance = item[k]["space"]
|
||||||
if time > 0:
|
if time > 0:
|
||||||
group += (distance / time)
|
group += (distance / time)
|
||||||
count+=1
|
count += 1
|
||||||
else:
|
else:
|
||||||
print("div by zero", distance, time)
|
print("div by zero", distance, time)
|
||||||
if count > 0:
|
if count > 0:
|
||||||
groups[k].append(group/count)
|
groups[k].append(group / count)
|
||||||
else:
|
else:
|
||||||
groups[k].append(0.0)
|
groups[k].append(0.0)
|
||||||
print(ids)
|
print(ids)
|
||||||
|
|
@ -380,45 +407,48 @@ if __name__ == '__main__':
|
||||||
print(ind)
|
print(ind)
|
||||||
print(json.dumps(groups, indent=1))
|
print(json.dumps(groups, indent=1))
|
||||||
bars = []
|
bars = []
|
||||||
dpi=10
|
dpi = 200
|
||||||
plt.figure(figsize=(1280/dpi, 720/dpi))
|
plt.figure(figsize=(1280 / dpi, 720 / dpi))
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
for k in groups:
|
for k in groups:
|
||||||
print(groups[k])
|
print(groups[k])
|
||||||
if not len(groups[k]):
|
if not len(groups[k]):
|
||||||
groups[k].append(0)
|
groups[k].append(0)
|
||||||
ind = ind + (width)
|
ind = ind + (width)
|
||||||
bars.append(ax.bar((ind + width*len(groups)/2), groups[k], width, color=colors[k]))
|
bars.append(ax.bar((ind + width * len(groups) / 2), groups[k], width, color=colors[k]))
|
||||||
ax.set_xticks(ind + width / 2)
|
ax.set_xticks(ind + width / 2)
|
||||||
ax.set_xticklabels(list([CONFIG_NAMES[i] if i in CONFIG_NAMES else "---" for i in ids]))
|
ax.set_xticklabels(list([CONFIG_NAMES[i] if i in CONFIG_NAMES else "---" for i in ids]))
|
||||||
plt.legend(bars, keys)
|
kmh = plt.hlines((1 / 3.6), 0.3, 4.2, linestyles="dashed", label="1 km/h", linewidths=1)
|
||||||
|
plt.legend(bars+[kmh], keys+[kmh.get_label()])
|
||||||
print(combined.keys(), ids)
|
print(combined.keys(), ids)
|
||||||
print([CONFIG_NAMES[i] if i in CONFIG_NAMES else "---" for i in ids])
|
print([CONFIG_NAMES[i] if i in CONFIG_NAMES else "---" for i in ids])
|
||||||
#plt.show()
|
# plt.show()
|
||||||
dpi=100
|
dpi = 200
|
||||||
plt.savefig("speed.png", dpi=dpi)
|
plt.savefig("speed2.png", dpi=dpi)
|
||||||
|
|
||||||
|
|
||||||
# spatial_data = get_data_distance(store,relative_values=False)
|
# spatial_data = get_data_distance(store,relative_values=False)
|
||||||
# temporal_data = get_data(store,relative_values=False)
|
# temporal_data = get_data(store,relative_values=False)
|
||||||
# spatial_data_rel = get_data_distance(store,relative_values=True)
|
# spatial_data_rel = get_data_distance(store,relative_values=True)
|
||||||
# temporal_data_rel = get_data(store,relative_values=True)
|
# temporal_data_rel = get_data(store,relative_values=True)
|
||||||
#temporal_data_rel = json.load(open("temporal_rel.json"))
|
# temporal_data_rel = json.load(open("temporal_rel.json"))
|
||||||
#spatial_data_rel = json.load(open("spatial_rel.json"))
|
# spatial_data_rel = json.load(open("spatial_rel.json"))
|
||||||
# import IPython
|
# import IPython
|
||||||
# IPython.embed()
|
# IPython.embed()
|
||||||
|
|
||||||
#print(json.dumps(get_all_data(store)))
|
# print(json.dumps(get_all_data(store)))
|
||||||
#json.dump(get_all_data(store), open("combined.json", "w"))
|
# json.dump(get_all_data(store), open("combined.json", "w"))
|
||||||
#combined = get_all_data(store, sort=True, relative=True)
|
# combined = get_all_data(store, sort=True, relative=True)
|
||||||
#json.dump(combined, open("combined_rel.json", "w"))
|
# json.dump(combined, open("combined_rel.json", "w"))
|
||||||
#combined = json.load(open("combined_rel.json"))
|
# combined = json.load(open("combined_rel.json"))
|
||||||
combined = json.load(open("combined_total.json"))
|
combined = json.load(open("combined_total.json"))
|
||||||
plot_time_space_rel(combined, keys)
|
#plot_time_space_rel(combined, keys)
|
||||||
|
plot_data(combined, keys)
|
||||||
|
|
||||||
#plot_time_space_rel(temporal_data_rel, spatial_data_rel, keys)
|
|
||||||
|
|
||||||
#plot_data(combined, keys)
|
# plot_time_space_rel(temporal_data_rel, spatial_data_rel, keys)
|
||||||
|
|
||||||
|
# plot_data(combined, keys)
|
||||||
# plot_data(get_data_distance(store,relative_values=False), keys)
|
# plot_data(get_data_distance(store,relative_values=False), keys)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue