add boxplot for simu retries
parent
06a606fbb8
commit
b81719aba3
|
|
@ -1,3 +1,5 @@
|
|||
from typing import List
|
||||
|
||||
from .analyzer import Analyzer, Result
|
||||
from .analyzer.biogames import BoardDurationAnalyzer, SimulationRoundsAnalyzer
|
||||
from .analyzer.default import LogEntryCountAnalyzer, LocationAnalyzer, LogEntrySequenceAnalyzer, ActionSequenceAnalyzer
|
||||
|
|
@ -7,6 +9,7 @@ from .render import Render
|
|||
from .render.default import PrintRender, JSONRender
|
||||
from .render.locomotion import LocomotionActionRelativeRender, LocomotionActionAbsoluteRender, \
|
||||
LocomotionActionRatioRender
|
||||
from .render.biogames import SimulationRoundsRender
|
||||
|
||||
__FALLBACK__ = PrintRender
|
||||
__MAPPING__ = {
|
||||
|
|
@ -19,6 +22,7 @@ __MAPPING__ = {
|
|||
],
|
||||
SimulationRoundsAnalyzer: [
|
||||
JSONRender,
|
||||
SimulationRoundsRender,
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -27,3 +31,10 @@ def get_renderer(cls: type) -> [type]:
|
|||
if cls not in __MAPPING__:
|
||||
return [__FALLBACK__]
|
||||
return __MAPPING__[cls]
|
||||
|
||||
|
||||
def render(cls: type, results: List[Result]):
|
||||
for r in get_renderer(cls):
|
||||
p = r()
|
||||
p.result_types.append(cls)
|
||||
p.render(results)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class SimulationRoundsAnalyzer(Analyzer):
|
|||
|
||||
def __init__(self, settings: LogSettings):
|
||||
super().__init__(settings)
|
||||
self.store = defaultdict(lambda: 0)
|
||||
self.store = defaultdict(lambda: -1) # TODO verify
|
||||
|
||||
def result(self) -> Result:
|
||||
return Result(type(self), dict(self.store))
|
||||
|
|
@ -58,5 +58,6 @@ class SimulationRoundsAnalyzer(Analyzer):
|
|||
entry_type = entry[self.settings.type_field]
|
||||
if entry_type in self.settings.custom['simulation_rounds']:
|
||||
if entry["answers"][self.settings.type_field] in self.settings.custom["simu_data"]:
|
||||
self.store[entry['answers']["@id"]] += 1
|
||||
return False
|
||||
simu_id = entry['answers']["@id"]
|
||||
self.store[simu_id] += 1
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
from collections import defaultdict
|
||||
from typing import List, Tuple
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from . import Render
|
||||
from .. import Result, SimulationRoundsAnalyzer
|
||||
|
||||
|
||||
def plot(src_data: List[Tuple[str, List[int]]]):
|
||||
names, datas = list(zip(*src_data))
|
||||
plt.boxplot(datas, labels=names)
|
||||
plt.xticks(rotation='vertical')
|
||||
# plt.margins()
|
||||
plt.ylabel("simulation rounds")
|
||||
plt.title("simulation retries")
|
||||
plt.show()
|
||||
|
||||
|
||||
class SimulationRoundsRender(Render):
|
||||
def render(self, results: List[Result]):
|
||||
data = defaultdict(list)
|
||||
for result in self.filter(results):
|
||||
get = result.get()
|
||||
for key in get:
|
||||
data[key].append(get[key])
|
||||
data_tuples = [(key, data[key]) for key in sorted(data)]
|
||||
data_tuples = sorted(data_tuples, key=lambda x: sum(x[1]))
|
||||
plot(data_tuples)
|
||||
|
||||
result_types = [SimulationRoundsAnalyzer]
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
from load import LOADERS
|
||||
from typing import List
|
||||
from analyzers import get_renderer, Analyzer
|
||||
from analyzers import get_renderer, Analyzer, render
|
||||
from analyzers.settings import LogSettings, load_settings
|
||||
import analyzers
|
||||
|
||||
|
|
@ -50,9 +50,7 @@ if __name__ == '__main__':
|
|||
if False:
|
||||
for r in get_renderer(analyzers.LocomotionActionAnalyzer):
|
||||
r().render(results)
|
||||
jr = analyzers.JSONRender()
|
||||
jr.result_types = [analyzers.SimulationRoundsAnalyzer]
|
||||
jr.render(results)
|
||||
render(analyzers.SimulationRoundsAnalyzer, results)
|
||||
|
||||
# for analyzers in analyzers:
|
||||
# if analyzers.name() in ["LogEntryCount", "ActionSequenceAnalyzer"]:
|
||||
|
|
|
|||
Loading…
Reference in New Issue