test plotting
parent
1ffffd18e0
commit
e0398e6494
|
|
@ -53,14 +53,43 @@ class LocomotionActionAnalyzer(Analyzer):
|
|||
self.actions.append(self.last - self.cache_time)
|
||||
locomotion = sum(self.locomotion)
|
||||
action = sum(self.actions)
|
||||
total = locomotion + action
|
||||
return {
|
||||
'loco_sum': locomotion,
|
||||
'locomotion_sum': locomotion,
|
||||
'action_sum': action,
|
||||
'loco': self.locomotion,
|
||||
'act': self.actions,
|
||||
'dur': (self.last_timestamp - self.instance_start)
|
||||
'locomotion': self.locomotion,
|
||||
'action': self.actions,
|
||||
'duration': (self.last_timestamp - self.instance_start),
|
||||
'locomotion_relative': locomotion / total,
|
||||
'action_relative': action / total,
|
||||
'locomotion_action_ratio': locomotion / action,
|
||||
}
|
||||
|
||||
def render(self):
|
||||
raw = self.result()
|
||||
return [
|
||||
raw['locomotion_sum'],
|
||||
raw['action_sum'],
|
||||
raw['locomotion_relative'],
|
||||
raw['action_relative'],
|
||||
raw['locomotion_action_ratio']
|
||||
]
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
ind = np.arange(1)
|
||||
loc = plt.bar(ind, [raw["locomotion_relative"]], 0.35)
|
||||
act = plt.bar(ind, [raw["action_relative"]], 0.35)
|
||||
#ratio = plt.plot([1,2,3],[raw['locomotion_action_ratio'],raw['locomotion_relative'],raw['action_relative']], label="ratio", marker=".")
|
||||
ratio = plt.plot(ind,[raw['locomotion_action_ratio']], label="ratio", marker=".")
|
||||
plt.ylabel("time")
|
||||
plt.title("abs locomotion/action")
|
||||
plt.xlabel("sessions")
|
||||
|
||||
plt.xticks(ind, ["s1"])
|
||||
plt.legend((loc[0], act[0]), ("loc", "act"))
|
||||
plt.show()
|
||||
|
||||
def __init__(self, settings: LogSettings):
|
||||
super().__init__(settings)
|
||||
self.filter_start = init_filter(settings, "start")
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import json
|
|||
import sys
|
||||
from load import LOADERS
|
||||
import analyzer
|
||||
from typing import List
|
||||
|
||||
|
||||
class LogSettings:
|
||||
|
|
@ -40,10 +41,8 @@ def load_settings(file: str) -> LogSettings:
|
|||
return LogSettings(json.load(open(file)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
settings = load_settings("biogames2.json")
|
||||
print(settings)
|
||||
logfile = "data/inst_56d9b64144ab44e7b90bf766f3be32e3/instance_log.sqlite"
|
||||
def process_log(log_id: str, settings: LogSettings) -> List:
|
||||
logfile = "data/inst_{id}/instance_log.sqlite".format(id=log_id)
|
||||
loader = LOADERS[settings.log_format]()
|
||||
try:
|
||||
loader.load(logfile)
|
||||
|
|
@ -56,18 +55,49 @@ if __name__ == '__main__':
|
|||
for analyzer in analyzers:
|
||||
if analyzer.process(entry):
|
||||
break
|
||||
for analyzer in analyzers:
|
||||
print("* Result for " + analyzer.name())
|
||||
print(analyzer.result())
|
||||
#for analyzer in analyzers:
|
||||
return analyzers
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
settings = load_settings("biogames2.json")
|
||||
#print(settings)
|
||||
log_id = "56d9b64144ab44e7b90bf766f3be32e3"
|
||||
log_ids = ["56d9b64144ab44e7b90bf766f3be32e3","85a9ad58951e4fbda26f860c9b66f567"]
|
||||
results = []
|
||||
for log_id in log_ids:
|
||||
for analysis in process_log(log_id, settings):
|
||||
print("* Result for " + analysis.name())
|
||||
#print(analysis.result())
|
||||
if analysis.name() in ("LocomotionAction"):
|
||||
results.append(analysis.render())
|
||||
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
data = list(zip(*results))
|
||||
ind = np.arange(len(results))
|
||||
loc = plt.bar(ind, data[2], width=0.35, color="red")
|
||||
act = plt.bar(ind, data[3], width=0.35, bottom=data[2], color="green")
|
||||
# ratio = plt.plot([1,2,3],[raw['locomotion_action_ratio'],raw['locomotion_relative'],raw['action_relative']], label="ratio", marker=".")
|
||||
#ratio = plt.plot(ind, data[4], label="ratio", marker=".")
|
||||
plt.ylabel("time")
|
||||
plt.title("abs locomotion/action")
|
||||
plt.xlabel("sessions")
|
||||
|
||||
#plt.xticks(ind, log_ids)
|
||||
plt.xticks(ind, [""]*len(results))
|
||||
#plt.yticks(np.arange(0,1.1,0.10))
|
||||
plt.legend((loc[0], act[0]), ("loc", "act"))
|
||||
plt.show()
|
||||
# for analyzer in analyzers:
|
||||
# if analyzer.name() in ["LogEntryCount", "ActionSequenceAnalyzer"]:
|
||||
# print(json.dumps(analyzer.result(), indent=2))
|
||||
|
||||
#for analyzer in analyzers:
|
||||
# for analyzer in analyzers:
|
||||
# if analyzer.name() in ["BoardDuration"]:
|
||||
# print(json.dumps(analyzer.result(), indent=2))
|
||||
# print(analyzer.render())
|
||||
|
||||
# coords = analyzers[1].render()
|
||||
# with open("test.js", "w") as out:
|
||||
# out.write("coords = "+coords)
|
||||
# coords = analyzers[1].render()
|
||||
# with open("test.js", "w") as out:
|
||||
# out.write("coords = "+coords)
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
matplotlib
|
||||
Loading…
Reference in New Issue