From b40efa4bbb60a35e19ecf91d175f14d403d846cf Mon Sep 17 00:00:00 2001 From: Clemens Klug Date: Mon, 13 Nov 2017 13:52:57 +0100 Subject: [PATCH 1/3] WIP snapshot --- analyzers/__init__.py | 2 +- analyzers/analyzer/__init__.py | 2 +- analyzers/render/biogames.py | 8 +- biogames2.json | 1 + log_analyzer.py | 317 +++++++++++++++++++++++++-------- requirements.txt | 3 +- 6 files changed, 253 insertions(+), 80 deletions(-) diff --git a/analyzers/__init__.py b/analyzers/__init__.py index 4557f9d..d09114a 100644 --- a/analyzers/__init__.py +++ b/analyzers/__init__.py @@ -51,7 +51,7 @@ __MAPPING__ = { StoreRender ], SimulationOrderAnalyzer: [ - JSONRender, + #JSONRender, # SimulationOrderRender, SimulationGroupRender ] diff --git a/analyzers/analyzer/__init__.py b/analyzers/analyzer/__init__.py index e9f4e30..1740d08 100644 --- a/analyzers/analyzer/__init__.py +++ b/analyzers/analyzer/__init__.py @@ -50,7 +50,7 @@ class ResultStore: :return: """ result = [] - for key in self.store: + for key in sorted(self.store): result += self.store[key] return result diff --git a/analyzers/render/biogames.py b/analyzers/render/biogames.py index 415b8a9..dd6fc01 100644 --- a/analyzers/render/biogames.py +++ b/analyzers/render/biogames.py @@ -185,7 +185,13 @@ class SimulationOrderRender(Render): class SimulationGroupRender(Render): def render(self, results: List[Result], name=None): - data = [r.get() for r in self.filter(results)] + #data = [r.get() for r in self.filter(results)] + data = [] + for r in self.filter(results): + raw = r.get() + if len(raw) < 6: + raw = [0] + raw + data.append(raw) print(name, len(data)) graph_plot(list(data), ylabel="simulation retries", title="sequential simulation retries", rotation=None, name=name) #graph_fit(list(data), name=name) diff --git a/biogames2.json b/biogames2.json index 83072ea..cc1633b 100644 --- a/biogames2.json +++ b/biogames2.json @@ -14,6 +14,7 @@ "analyzers": { "analyzers": [ "SimulationCategorizer", + "SimulationOrderAnalyzer", "ActivityMapper" ] }, diff --git a/log_analyzer.py b/log_analyzer.py index c0b0723..bb542ea 100644 --- a/log_analyzer.py +++ b/log_analyzer.py @@ -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"]: diff --git a/requirements.txt b/requirements.txt index 6168760..5813878 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ matplotlib==2.1.0 osmnx==0.6 networkx==2.0 pydot==1.2.3 -scipy==1.0.0 \ No newline at end of file +scipy==1.0.0 +ipython==6.2.1 \ No newline at end of file From 75f41fb9f53bdc7e707ecb6ee5a50f74c32dba87 Mon Sep 17 00:00:00 2001 From: Clemens Klug Date: Wed, 15 Nov 2017 18:39:42 +0100 Subject: [PATCH 2/3] WIP snapshot --- analyzers/analyzer/biogames.py | 3 ++ log_analyzer.py | 93 ++++++++++++++++++++++++++-------- 2 files changed, 75 insertions(+), 21 deletions(-) diff --git a/analyzers/analyzer/biogames.py b/analyzers/analyzer/biogames.py index 96215e3..eab26e0 100644 --- a/analyzers/analyzer/biogames.py +++ b/analyzers/analyzer/biogames.py @@ -195,6 +195,7 @@ class ActivityMapper(Analyzer): board_data = get_board_data(self.settings.source, self.instance_config_id, entry["sequence_id"], entry["board_id"]) entry["extra_data"] = board_data + entry["extra_data"]["activity_type"] = self.last_board_type entry['coordinate'] = self.new_coordinate() self.timeline.append(entry) return False @@ -236,6 +237,8 @@ class ActivityMapper(Analyzer): self.track['properties'].update(props) self.tracks.append(self.track) self.track = self.new_track(props['end_timestamp']) + if self.last_coordinate: + self.track['coordinates'].append(self.last_coordinate) def new_track(self, timestamp): return {"type": "LineString", "coordinates": [], "properties": {'start_timestamp': timestamp}} diff --git a/log_analyzer.py b/log_analyzer.py index bb542ea..9d9fc40 100644 --- a/log_analyzer.py +++ b/log_analyzer.py @@ -182,6 +182,9 @@ if __name__ == '__main__': pyproj.Proj(init='EPSG:32633')) return transform(project, track).length + whitelist = ['16fc3117-61db-4f50-b84f-81de6310206f', '5e64ce07-1c16-4d50-ac4e-b3117847ea43', + '90278021-4c57-464e-90b1-d603799d07eb', 'ff8f1e8f-6cf5-4a7b-835b-5e2226c1e771'] + def get_data_distance(store, relative_values=True, sort=True, show_errors=False): places = defaultdict(list) @@ -211,9 +214,10 @@ if __name__ == '__main__': return places - def get_all_data(store): + def get_all_data(store, sort=False, relative=True): places = defaultdict(list) - + simu_distribution = defaultdict(lambda: 0) + #divisiors = {"time":60_000, "space":1000000} for log in store.get_all(): if not log.analysis() == analyzers.ActivityMapper: continue @@ -223,13 +227,14 @@ if __name__ == '__main__': if len(coords) > 1: distance = calc_distance(coords) else: - distance = 0.1 + distance = 0.0 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)) + total = defaultdict(lambda: defaultdict(lambda: 0)) for i in result["space"]: if not total_space == 0: percentage[i]["space"] = result["space"][i] / total_space @@ -239,22 +244,51 @@ if __name__ == '__main__': percentage[i]["time"] = result["time"][i] / total_time else: percentage[i]["time"] = 0 + for t in ("space","time"): + #total[i][t] += (result[t][i] / divisiors[t]) + total[i][t] += result[t][i] print(percentage) if not 'error' in result: - places[log.get()['instance']].append(percentage) + if relative: + value = percentage + else: + value = total + places[log.get()['instance']].append(value) + simus = defaultdict(lambda :0) + for item in log.get()['boards']: + if item["extra_data"]["activity_type"]=="simu": + simus[item["board_id"]] += 1 + simu_distribution[len(simus)]+=1 + + if sort: + for place in places: + places[place] = sorted(places[place], key=lambda item: item['map']['time']) + print(simu_distribution) return places - def stack_data(keys, places): + def stack_data(keys, places, type="time"): + divisiors = {"time": 60_000, "space": 1000} + divisiors = {"time": 1, "space": 1} dummy = [0] * len(keys) results = [] sites = [] - for i in places: + for i in sorted(places): + if not i in whitelist: + continue for j in places[i]: ordered = [] for k in keys: - ordered.append(j[k]) - results.append(ordered) + if k in j: + ordered.append(j[k][type]/divisiors[type]) + else: + ordered.append(0) + print(sum(ordered)) + if sum(ordered) > 0.9: + #print(sum(ordered), 1-sum(ordered)) + #if sum(ordered)<1: + # ordered[-2] = 1-sum(ordered[:-2], ordered[-1]) + results.append(ordered) results.append(dummy) sites.append(CONFIG_NAMES[i] if i in CONFIG_NAMES else "---") return results, sites @@ -262,7 +296,8 @@ if __name__ == '__main__': def plot_data(places, keys): results, sites = stack_data(keys, places) - + dpi=86.1 + plt.figure(figsize=(1280/dpi, 720/dpi)) size = len(results) print("{} elements total".format(size)) ind = np.arange(size) @@ -272,13 +307,16 @@ if __name__ == '__main__': # print(data) lines = [] bottom = [0] * size + plt.ticklabel_format(useMathText=False) 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.show() + dpi=86 + plt.savefig("time_rel_{}.png".format(size), dpi=dpi,bbox_inches="tight") colors = { @@ -314,13 +352,18 @@ if __name__ == '__main__': groups = defaultdict(list) keys = list(keys) keys.remove("other") + ids = [] for k in keys: for id in sorted(combined): + if id not in whitelist: + continue + if not id in ids: + ids.append(id) group = 0.0 count = 0 for item in combined[id]: if k in item: - time = item[k]["time"] + time = item[k]["time"]/1000 distance = item[k]["space"] if time > 0: group += (distance / time) @@ -331,24 +374,29 @@ if __name__ == '__main__': groups[k].append(group/count) else: groups[k].append(0.0) - ind = np.arange(len(combined.keys())) + print(ids) + ind = np.arange(len(ids)) width = .7 / len(groups) print(ind) print(json.dumps(groups, indent=1)) bars = [] + dpi=10 + plt.figure(figsize=(1280/dpi, 720/dpi)) 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 + ind = ind + (width) + bars.append(ax.bar((ind + width*len(groups)/2), groups[k], width, color=colors[k])) 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())])) + ax.set_xticklabels(list([CONFIG_NAMES[i] if i in CONFIG_NAMES else "---" for i in ids])) 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() + print(combined.keys(), ids) + print([CONFIG_NAMES[i] if i in CONFIG_NAMES else "---" for i in ids]) + #plt.show() + dpi=100 + plt.savefig("speed.png", dpi=dpi) # spatial_data = get_data_distance(store,relative_values=False) @@ -361,13 +409,16 @@ if __name__ == '__main__': # 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")) + #json.dump(get_all_data(store), open("combined.json", "w")) + #combined = get_all_data(store, sort=True, relative=True) + #json.dump(combined, open("combined_rel.json", "w")) + #combined = json.load(open("combined_rel.json")) + combined = json.load(open("combined_total.json")) plot_time_space_rel(combined, keys) #plot_time_space_rel(temporal_data_rel, spatial_data_rel, keys) - # plot_data(data, keys) + #plot_data(combined, keys) # plot_data(get_data_distance(store,relative_values=False), keys) From f0a6a1c8aa0a289386a370402f267d0165408633 Mon Sep 17 00:00:00 2001 From: Clemens Klug Date: Mon, 20 Nov 2017 17:56:07 +0100 Subject: [PATCH 3/3] WIP snapshot --- log_analyzer.py | 108 +++++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 39 deletions(-) diff --git a/log_analyzer.py b/log_analyzer.py index 9d9fc40..ef04c38 100644 --- a/log_analyzer.py +++ b/log_analyzer.py @@ -137,6 +137,13 @@ if __name__ == '__main__': # "error" ] + loc_keys=[ + "question", + "image", + "audio", + "video" + ] + def get_data(store, relative_values=True, sort=True, show_errors=False): places = defaultdict(list) @@ -182,6 +189,7 @@ if __name__ == '__main__': pyproj.Proj(init='EPSG:32633')) return transform(project, track).length + whitelist = ['16fc3117-61db-4f50-b84f-81de6310206f', '5e64ce07-1c16-4d50-ac4e-b3117847ea43', '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): places = defaultdict(list) simu_distribution = defaultdict(lambda: 0) - #divisiors = {"time":60_000, "space":1000000} + # divisiors = {"time":60_000, "space":1000000} for log in store.get_all(): if not log.analysis() == analyzers.ActivityMapper: continue @@ -244,8 +252,8 @@ if __name__ == '__main__': percentage[i]["time"] = result["time"][i] / total_time else: percentage[i]["time"] = 0 - for t in ("space","time"): - #total[i][t] += (result[t][i] / divisiors[t]) + for t in ("space", "time"): + # total[i][t] += (result[t][i] / divisiors[t]) total[i][t] += result[t][i] print(percentage) if not 'error' in result: @@ -254,11 +262,11 @@ if __name__ == '__main__': else: value = total places[log.get()['instance']].append(value) - simus = defaultdict(lambda :0) + simus = defaultdict(lambda: 0) 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 - simu_distribution[len(simus)]+=1 + simu_distribution[len(simus)] += 1 if sort: for place in places: @@ -267,26 +275,28 @@ if __name__ == '__main__': return places - def stack_data(keys, places, type="time"): + def stack_data(keys, places, type="space"): divisiors = {"time": 60_000, "space": 1000} - divisiors = {"time": 1, "space": 1} + #divisiors = {"time": 1, "space": 1} dummy = [0] * len(keys) results = [] sites = [] for i in sorted(places): if not i in whitelist: continue - for j in places[i]: + place = sorted(places[i], key=lambda item: item['map'][type]) + for j in place: ordered = [] for k in keys: if k in j: - ordered.append(j[k][type]/divisiors[type]) + ordered.append(j[k][type] / divisiors[type]) else: ordered.append(0) print(sum(ordered)) - if sum(ordered) > 0.9: - #print(sum(ordered), 1-sum(ordered)) - #if sum(ordered)<1: + #if sum(ordered) > 0.9 and sum(ordered) < 4000 and sum(ordered)>10: + if sum(ordered) > 0.9 and sum(ordered)<100: + # print(sum(ordered), 1-sum(ordered)) + # if sum(ordered)<1: # ordered[-2] = 1-sum(ordered[:-2], ordered[-1]) results.append(ordered) results.append(dummy) @@ -296,8 +306,8 @@ if __name__ == '__main__': def plot_data(places, keys): results, sites = stack_data(keys, places) - dpi=86.1 - plt.figure(figsize=(1280/dpi, 720/dpi)) + dpi = 86.1 + plt.figure(figsize=(1280 / dpi, 720 / dpi)) size = len(results) print("{} elements total".format(size)) ind = np.arange(size) @@ -314,9 +324,9 @@ if __name__ == '__main__': bottom[k] += x plt.legend(lines, keys) plt.title(", ".join(sites)) - #plt.show() - dpi=86 - plt.savefig("time_rel_{}.png".format(size), dpi=dpi,bbox_inches="tight") + # plt.show() + dpi = 86 + plt.savefig("space_abs_{}.png".format(size), dpi=dpi, bbox_inches="tight") colors = { @@ -327,7 +337,8 @@ if __name__ == '__main__': "video": "purple", "other": "brown", "map": "violet", - # "error":"grey" + # "error":"grey", + "tasks": "olive", } markers = [".", "o", "x", "s", "*", "D", "p", ",", "<", ">", "^", "v", "1", "2", "3", "4"] @@ -348,11 +359,27 @@ if __name__ == '__main__': # plt.clf() # 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): groups = defaultdict(list) keys = list(keys) keys.remove("other") + for i in loc_keys: + keys.remove(i) + keys.append("tasks") ids = [] + group_locationbased_tasks(combined) for k in keys: for id in sorted(combined): if id not in whitelist: @@ -363,15 +390,15 @@ if __name__ == '__main__': count = 0 for item in combined[id]: if k in item: - time = item[k]["time"]/1000 + time = item[k]["time"] / 1000 distance = item[k]["space"] if time > 0: group += (distance / time) - count+=1 + count += 1 else: print("div by zero", distance, time) if count > 0: - groups[k].append(group/count) + groups[k].append(group / count) else: groups[k].append(0.0) print(ids) @@ -380,45 +407,48 @@ if __name__ == '__main__': print(ind) print(json.dumps(groups, indent=1)) bars = [] - dpi=10 - plt.figure(figsize=(1280/dpi, 720/dpi)) + dpi = 200 + plt.figure(figsize=(1280 / dpi, 720 / dpi)) fig, ax = plt.subplots() for k in groups: print(groups[k]) if not len(groups[k]): groups[k].append(0) 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_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([CONFIG_NAMES[i] if i in CONFIG_NAMES else "---" for i in ids]) - #plt.show() - dpi=100 - plt.savefig("speed.png", dpi=dpi) + # plt.show() + dpi = 200 + plt.savefig("speed2.png", dpi=dpi) # 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")) + # 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 = get_all_data(store, sort=True, relative=True) - #json.dump(combined, open("combined_rel.json", "w")) - #combined = json.load(open("combined_rel.json")) + # print(json.dumps(get_all_data(store))) + # json.dump(get_all_data(store), open("combined.json", "w")) + # combined = get_all_data(store, sort=True, relative=True) + # json.dump(combined, open("combined_rel.json", "w")) + # combined = json.load(open("combined_rel.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)