|
|
|
|
@ -63,17 +63,18 @@ if __name__ == '__main__':
|
|
|
|
|
# "fec57041458e6cef98652df625", ]
|
|
|
|
|
log_ids = []
|
|
|
|
|
# with open("/home/clemens/git/ma/test/filtered") as src:
|
|
|
|
|
with open("/home/clemens/git/ma/test/filtered") as src:
|
|
|
|
|
for line in src:
|
|
|
|
|
line = line.strip()
|
|
|
|
|
log_ids.append(line)
|
|
|
|
|
store: ResultStore = ResultStore()
|
|
|
|
|
for log_id in log_ids:
|
|
|
|
|
for analysis in process_log(log_id, settings):
|
|
|
|
|
log.info("* Result for " + analysis.name())
|
|
|
|
|
# print(analysis.result())
|
|
|
|
|
# print(analysis.render())
|
|
|
|
|
analysis.result(store)
|
|
|
|
|
if False:
|
|
|
|
|
with open("/home/clemens/git/ma/test/filtered_5_actions") as src:
|
|
|
|
|
for line in src:
|
|
|
|
|
line = line.strip()
|
|
|
|
|
log_ids.append(line)
|
|
|
|
|
store: ResultStore = ResultStore()
|
|
|
|
|
for log_id in log_ids:
|
|
|
|
|
for analysis in process_log(log_id, settings):
|
|
|
|
|
log.info("* Result for " + analysis.name())
|
|
|
|
|
# print(analysis.result())
|
|
|
|
|
# print(analysis.render())
|
|
|
|
|
analysis.result(store)
|
|
|
|
|
if False:
|
|
|
|
|
for r in get_renderer(analyzers.LocomotionActionAnalyzer):
|
|
|
|
|
r().render(store.get_all())
|
|
|
|
|
@ -120,8 +121,10 @@ if __name__ == '__main__':
|
|
|
|
|
writer.writerow(line)
|
|
|
|
|
|
|
|
|
|
if True:
|
|
|
|
|
#json.dump(store.serializable(), open("new.json", "w"), indent=1)
|
|
|
|
|
# json.dump(store.serializable(), open("new.json", "w"), indent=1)
|
|
|
|
|
from collections import defaultdict
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
from util.meta_temp import CONFIG_NAMES
|
|
|
|
|
|
|
|
|
|
keys = [
|
|
|
|
|
"simu",
|
|
|
|
|
@ -130,81 +133,243 @@ if __name__ == '__main__':
|
|
|
|
|
"audio",
|
|
|
|
|
"video",
|
|
|
|
|
"other",
|
|
|
|
|
"map"
|
|
|
|
|
"map",
|
|
|
|
|
# "error"
|
|
|
|
|
]
|
|
|
|
|
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)
|
|
|
|
|
def get_data(store, relative_values=True, sort=True, show_errors=False):
|
|
|
|
|
places = defaultdict(list)
|
|
|
|
|
|
|
|
|
|
for place in places:
|
|
|
|
|
places[place] = sorted(places[place], key=lambda item:item['map'])
|
|
|
|
|
for log in store.get_all():
|
|
|
|
|
if not log.analysis() == analyzers.ActivityMapper:
|
|
|
|
|
continue
|
|
|
|
|
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 or show_errors:
|
|
|
|
|
if relative_values:
|
|
|
|
|
places[log.get()['instance']].append(percentage)
|
|
|
|
|
else:
|
|
|
|
|
places[log.get()['instance']].append(minutes)
|
|
|
|
|
if sort:
|
|
|
|
|
for place in places:
|
|
|
|
|
places[place] = sorted(places[place], key=lambda item: item['map'])
|
|
|
|
|
return places
|
|
|
|
|
|
|
|
|
|
dummy = [0]*len(keys)
|
|
|
|
|
results = []
|
|
|
|
|
sites = []
|
|
|
|
|
from util.meta_temp import CONFIG_NAMES
|
|
|
|
|
for i in places:
|
|
|
|
|
for j in places[i]:
|
|
|
|
|
ordered = []
|
|
|
|
|
|
|
|
|
|
from shapely.geometry import LineString
|
|
|
|
|
from shapely.ops import transform
|
|
|
|
|
from functools import partial
|
|
|
|
|
import pyproj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def calc_distance(coordinates):
|
|
|
|
|
track = LineString(coordinates)
|
|
|
|
|
project = partial(
|
|
|
|
|
pyproj.transform,
|
|
|
|
|
pyproj.Proj(init='EPSG:4326'),
|
|
|
|
|
pyproj.Proj(init='EPSG:32633'))
|
|
|
|
|
return transform(project, track).length
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_data_distance(store, relative_values=True, sort=True, show_errors=False):
|
|
|
|
|
places = defaultdict(list)
|
|
|
|
|
|
|
|
|
|
for log in store.get_all():
|
|
|
|
|
if not log.analysis() == analyzers.ActivityMapper:
|
|
|
|
|
continue
|
|
|
|
|
result = defaultdict(lambda: 0)
|
|
|
|
|
for i in log.get()['track']:
|
|
|
|
|
coords = i['coordinates']
|
|
|
|
|
if len(coords) > 1:
|
|
|
|
|
distance = calc_distance(coords)
|
|
|
|
|
result[i['properties']['activity_type']] += distance
|
|
|
|
|
total = sum(result.values())
|
|
|
|
|
percentage = defaultdict(lambda: 0)
|
|
|
|
|
for i in result:
|
|
|
|
|
if not total == 0:
|
|
|
|
|
percentage[i] = result[i] / total
|
|
|
|
|
if not 'error' in result or show_errors:
|
|
|
|
|
if relative_values:
|
|
|
|
|
places[log.get()['instance']].append(percentage)
|
|
|
|
|
else:
|
|
|
|
|
places[log.get()['instance']].append(result)
|
|
|
|
|
if sort:
|
|
|
|
|
for place in places:
|
|
|
|
|
places[place] = sorted(places[place], key=lambda item: item['map'])
|
|
|
|
|
return places
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_all_data(store):
|
|
|
|
|
places = defaultdict(list)
|
|
|
|
|
|
|
|
|
|
for log in store.get_all():
|
|
|
|
|
if not log.analysis() == analyzers.ActivityMapper:
|
|
|
|
|
continue
|
|
|
|
|
result = defaultdict(lambda: defaultdict(lambda: 0))
|
|
|
|
|
for i in log.get()['track']:
|
|
|
|
|
coords = i['coordinates']
|
|
|
|
|
if len(coords) > 1:
|
|
|
|
|
distance = calc_distance(coords)
|
|
|
|
|
else:
|
|
|
|
|
distance = 0.1
|
|
|
|
|
result["space"][i['properties']['activity_type']] += distance
|
|
|
|
|
duration = i['properties']['end_timestamp'] - i['properties']['start_timestamp']
|
|
|
|
|
result["time"][i['properties']['activity_type']] += duration
|
|
|
|
|
total_space = sum(result["space"].values())
|
|
|
|
|
total_time = sum(result["time"].values())
|
|
|
|
|
percentage = defaultdict(lambda: defaultdict(lambda: 0))
|
|
|
|
|
for i in result["space"]:
|
|
|
|
|
if not total_space == 0:
|
|
|
|
|
percentage[i]["space"] = result["space"][i] / total_space
|
|
|
|
|
else:
|
|
|
|
|
percentage[i]["space"] = 0
|
|
|
|
|
if not total_time == 0:
|
|
|
|
|
percentage[i]["time"] = result["time"][i] / total_time
|
|
|
|
|
else:
|
|
|
|
|
percentage[i]["time"] = 0
|
|
|
|
|
print(percentage)
|
|
|
|
|
if not 'error' in result:
|
|
|
|
|
places[log.get()['instance']].append(percentage)
|
|
|
|
|
return places
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def stack_data(keys, places):
|
|
|
|
|
dummy = [0] * len(keys)
|
|
|
|
|
results = []
|
|
|
|
|
sites = []
|
|
|
|
|
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 "---")
|
|
|
|
|
return results, sites
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def plot_data(places, keys):
|
|
|
|
|
results, sites = stack_data(keys, places)
|
|
|
|
|
|
|
|
|
|
size = len(results)
|
|
|
|
|
print("{} elements total".format(size))
|
|
|
|
|
ind = np.arange(size)
|
|
|
|
|
width = 1
|
|
|
|
|
# print(results)
|
|
|
|
|
data = list(zip(*results))
|
|
|
|
|
# print(data)
|
|
|
|
|
lines = []
|
|
|
|
|
bottom = [0] * size
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
colors = {
|
|
|
|
|
"simu": "blue",
|
|
|
|
|
"question": "orange",
|
|
|
|
|
"image": "green",
|
|
|
|
|
"audio": "red",
|
|
|
|
|
"video": "purple",
|
|
|
|
|
"other": "brown",
|
|
|
|
|
"map": "violet",
|
|
|
|
|
# "error":"grey"
|
|
|
|
|
}
|
|
|
|
|
markers = [".", "o", "x", "s", "*", "D", "p", ",", "<", ">", "^", "v", "1", "2", "3", "4"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def plot_time_space(time_data, space_data, keys):
|
|
|
|
|
# assuming time_data and space_data are in same order!
|
|
|
|
|
marker = 0
|
|
|
|
|
for id in time_data:
|
|
|
|
|
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 "---")
|
|
|
|
|
for i in range(len(time_data[id])):
|
|
|
|
|
print(time_data[id][i][k], space_data[id][i][k])
|
|
|
|
|
plt.plot(time_data[id][i][k], space_data[id][i][k], color=colors[k], marker=markers[marker])
|
|
|
|
|
marker += 1
|
|
|
|
|
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(", ".join(sites))
|
|
|
|
|
plt.show()
|
|
|
|
|
# plt.cla()
|
|
|
|
|
# plt.clf()
|
|
|
|
|
# plt.close()
|
|
|
|
|
|
|
|
|
|
#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()
|
|
|
|
|
def plot_time_space_rel(combined, keys):
|
|
|
|
|
groups = defaultdict(list)
|
|
|
|
|
keys = list(keys)
|
|
|
|
|
keys.remove("other")
|
|
|
|
|
for k in keys:
|
|
|
|
|
for id in sorted(combined):
|
|
|
|
|
group = 0.0
|
|
|
|
|
count = 0
|
|
|
|
|
for item in combined[id]:
|
|
|
|
|
if k in item:
|
|
|
|
|
time = item[k]["time"]
|
|
|
|
|
distance = item[k]["space"]
|
|
|
|
|
if time > 0:
|
|
|
|
|
group += (distance / time)
|
|
|
|
|
count+=1
|
|
|
|
|
else:
|
|
|
|
|
print("div by zero", distance, time)
|
|
|
|
|
if count > 0:
|
|
|
|
|
groups[k].append(group/count)
|
|
|
|
|
else:
|
|
|
|
|
groups[k].append(0.0)
|
|
|
|
|
ind = np.arange(len(combined.keys()))
|
|
|
|
|
width = .7 / len(groups)
|
|
|
|
|
print(ind)
|
|
|
|
|
print(json.dumps(groups, indent=1))
|
|
|
|
|
bars = []
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
|
for k in groups:
|
|
|
|
|
print(groups[k])
|
|
|
|
|
if not len(groups[k]):
|
|
|
|
|
groups[k].append(0)
|
|
|
|
|
bars.append(ax.bar(ind, groups[k], width, color=colors[k]))
|
|
|
|
|
ind = ind + width
|
|
|
|
|
ax.set_xticks(ind + width / 2)
|
|
|
|
|
ax.set_xticklabels(list([CONFIG_NAMES[i] if i in CONFIG_NAMES else "---" for i in sorted(combined.keys())]))
|
|
|
|
|
plt.legend(bars, keys)
|
|
|
|
|
print(combined.keys())
|
|
|
|
|
print([CONFIG_NAMES[i] if i in CONFIG_NAMES else "---" for i in sorted(combined.keys())])
|
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# spatial_data = get_data_distance(store,relative_values=False)
|
|
|
|
|
# temporal_data = get_data(store,relative_values=False)
|
|
|
|
|
# spatial_data_rel = get_data_distance(store,relative_values=True)
|
|
|
|
|
# temporal_data_rel = get_data(store,relative_values=True)
|
|
|
|
|
#temporal_data_rel = json.load(open("temporal_rel.json"))
|
|
|
|
|
#spatial_data_rel = json.load(open("spatial_rel.json"))
|
|
|
|
|
# import IPython
|
|
|
|
|
# IPython.embed()
|
|
|
|
|
|
|
|
|
|
#print(json.dumps(get_all_data(store)))
|
|
|
|
|
# json.dump(get_all_data(store), open("combined.json", "w"))
|
|
|
|
|
combined = json.load(open("combined.json"))
|
|
|
|
|
plot_time_space_rel(combined, keys)
|
|
|
|
|
|
|
|
|
|
#plot_time_space_rel(temporal_data_rel, spatial_data_rel, keys)
|
|
|
|
|
|
|
|
|
|
# plot_data(data, keys)
|
|
|
|
|
# plot_data(get_data_distance(store,relative_values=False), keys)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# for analyzers in analyzers:
|
|
|
|
|
# if analyzers.name() in ["LogEntryCount", "ActionSequenceAnalyzer"]:
|
|
|
|
|
|