add boxplot for simu retries
parent
06a606fbb8
commit
b81719aba3
|
|
@ -1,3 +1,5 @@
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from .analyzer import Analyzer, Result
|
from .analyzer import Analyzer, Result
|
||||||
from .analyzer.biogames import BoardDurationAnalyzer, SimulationRoundsAnalyzer
|
from .analyzer.biogames import BoardDurationAnalyzer, SimulationRoundsAnalyzer
|
||||||
from .analyzer.default import LogEntryCountAnalyzer, LocationAnalyzer, LogEntrySequenceAnalyzer, ActionSequenceAnalyzer
|
from .analyzer.default import LogEntryCountAnalyzer, LocationAnalyzer, LogEntrySequenceAnalyzer, ActionSequenceAnalyzer
|
||||||
|
|
@ -7,6 +9,7 @@ from .render import Render
|
||||||
from .render.default import PrintRender, JSONRender
|
from .render.default import PrintRender, JSONRender
|
||||||
from .render.locomotion import LocomotionActionRelativeRender, LocomotionActionAbsoluteRender, \
|
from .render.locomotion import LocomotionActionRelativeRender, LocomotionActionAbsoluteRender, \
|
||||||
LocomotionActionRatioRender
|
LocomotionActionRatioRender
|
||||||
|
from .render.biogames import SimulationRoundsRender
|
||||||
|
|
||||||
__FALLBACK__ = PrintRender
|
__FALLBACK__ = PrintRender
|
||||||
__MAPPING__ = {
|
__MAPPING__ = {
|
||||||
|
|
@ -19,6 +22,7 @@ __MAPPING__ = {
|
||||||
],
|
],
|
||||||
SimulationRoundsAnalyzer: [
|
SimulationRoundsAnalyzer: [
|
||||||
JSONRender,
|
JSONRender,
|
||||||
|
SimulationRoundsRender,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,3 +31,10 @@ def get_renderer(cls: type) -> [type]:
|
||||||
if cls not in __MAPPING__:
|
if cls not in __MAPPING__:
|
||||||
return [__FALLBACK__]
|
return [__FALLBACK__]
|
||||||
return __MAPPING__[cls]
|
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):
|
def __init__(self, settings: LogSettings):
|
||||||
super().__init__(settings)
|
super().__init__(settings)
|
||||||
self.store = defaultdict(lambda: 0)
|
self.store = defaultdict(lambda: -1) # TODO verify
|
||||||
|
|
||||||
def result(self) -> Result:
|
def result(self) -> Result:
|
||||||
return Result(type(self), dict(self.store))
|
return Result(type(self), dict(self.store))
|
||||||
|
|
@ -58,5 +58,6 @@ class SimulationRoundsAnalyzer(Analyzer):
|
||||||
entry_type = entry[self.settings.type_field]
|
entry_type = entry[self.settings.type_field]
|
||||||
if entry_type in self.settings.custom['simulation_rounds']:
|
if entry_type in self.settings.custom['simulation_rounds']:
|
||||||
if entry["answers"][self.settings.type_field] in self.settings.custom["simu_data"]:
|
if entry["answers"][self.settings.type_field] in self.settings.custom["simu_data"]:
|
||||||
self.store[entry['answers']["@id"]] += 1
|
simu_id = entry['answers']["@id"]
|
||||||
return False
|
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 load import LOADERS
|
||||||
from typing import List
|
from typing import List
|
||||||
from analyzers import get_renderer, Analyzer
|
from analyzers import get_renderer, Analyzer, render
|
||||||
from analyzers.settings import LogSettings, load_settings
|
from analyzers.settings import LogSettings, load_settings
|
||||||
import analyzers
|
import analyzers
|
||||||
|
|
||||||
|
|
@ -50,9 +50,7 @@ if __name__ == '__main__':
|
||||||
if False:
|
if False:
|
||||||
for r in get_renderer(analyzers.LocomotionActionAnalyzer):
|
for r in get_renderer(analyzers.LocomotionActionAnalyzer):
|
||||||
r().render(results)
|
r().render(results)
|
||||||
jr = analyzers.JSONRender()
|
render(analyzers.SimulationRoundsAnalyzer, results)
|
||||||
jr.result_types = [analyzers.SimulationRoundsAnalyzer]
|
|
||||||
jr.render(results)
|
|
||||||
|
|
||||||
# for analyzers in analyzers:
|
# for analyzers in analyzers:
|
||||||
# if analyzers.name() in ["LogEntryCount", "ActionSequenceAnalyzer"]:
|
# if analyzers.name() in ["LogEntryCount", "ActionSequenceAnalyzer"]:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue