Compare commits

...

4 Commits

Author SHA1 Message Date
clemens 25183908da Merge branch 'master' of git.clkl.de:ma/project 2018-06-12 13:57:59 +02:00
clemens 9704dffeec Merge branch 'master' of git.clkl.de:ma/project 2018-06-12 11:44:11 +02:00
clemens 276242096a Merge branch 'master' of https://clkl.de/git/ma/project 2017-11-15 18:42:44 +01:00
clemens d280b1dd44 improve renderings 2017-10-24 14:01:36 +02:00
6 changed files with 52 additions and 16 deletions

View File

@ -14,22 +14,24 @@ from .render.biogames import SimulationRoundsRender, BoardDurationHistRender, Bo
from .render.default import PrintRender, JSONRender, TrackRender, HeatMapRender, LogEntryCountAnalyzerPlot, \
LogEntryCountCSV, KMLRender
from .render.locomotion import LocomotionActionRelativeRender, LocomotionActionAbsoluteRender, \
LocomotionActionRatioRender
LocomotionActionRatioRender, LocomotionActionRatioHistRender
__FALLBACK__ = PrintRender
__MAPPING__ = {
LocomotionActionAnalyzer: [
LocomotionActionAbsoluteRender,
LocomotionActionRelativeRender,
LocomotionActionRatioRender, ],
LocomotionActionRatioRender,
LocomotionActionRatioHistRender,
],
LogEntryCountAnalyzer: [
# JSONRender,
LogEntryCountAnalyzerPlot,
LogEntryCountCSV,
],
SimulationRoundsAnalyzer: [
JSONRender,
SimulationRoundsRender,
SimulationRoundsMeanRender,
],
BoardDurationAnalyzer: [
BoardDurationHistRender,

View File

@ -18,7 +18,6 @@ class Result:
return self.__analysis__
def get(self):
log.debug("get" + str(len(self.result)))
return self.result
def __repr__(self):

View File

@ -28,7 +28,7 @@ class BoardDurationAnalyzer(Analyzer):
board_id, timestamp = board["id"], board["timestamp"]
if not last_timestamp is None:
result.append(self.save_entry(last_board, last_timestamp, timestamp - last_timestamp))
result.append(self.save_entry(last_board, last_timestamp, (timestamp - last_timestamp)/1000))
last_timestamp = timestamp
last_board = board_id
# TODO: last board?

View File

@ -1,6 +1,9 @@
from analysis import util
from . import Analyzer, LogSettings, Result, ResultStore
log: logging.Logger = logging.getLogger(__name__)
ONE_DAY = 24 * 60 * 60 * 1000
MIN_DURATION = 5 * 60 * 1000
def init_filter(settings: LogSettings, state: str) -> callable:
# this implies OR for lists; AND for dicts
@ -19,6 +22,8 @@ class LocomotionActionAnalyzer(Analyzer):
"""
__name__ = "LocomotionAction"
limit = ONE_DAY
def process(self, entry: dict) -> bool:
self.last_timestamp = entry["timestamp"]
if self.instance_start is None:
@ -50,13 +55,22 @@ class LocomotionActionAnalyzer(Analyzer):
self.last = None
locomotion = sum(self.locomotion)
action = sum(self.actions)
if not action > 0:
action = 1
total = locomotion + action
if total > self.limit:
log.error("total duration over limit, skip")
elif total < MIN_DURATION:
log.error("total duration too short, skip")
elif action < MIN_DURATION:
log.error("action time too short, skip")
else:
store.add(Result(type(self), {
'locomotion_sum': locomotion,
'action_sum': action,
'locomotion_sum': locomotion/1000,
'action_sum': action/1000,
'locomotion': self.locomotion,
'action': self.actions,
'duration': (self.last_timestamp - self.instance_start),
'duration': (self.last_timestamp - self.instance_start)/1000,
'locomotion_relative': locomotion / total,
'action_relative': action / total,
'locomotion_action_ratio': locomotion / action,

View File

@ -1,3 +1,5 @@
import json
import logging
from typing import List
import matplotlib.pyplot as plt
@ -6,6 +8,14 @@ import numpy as np
from . import Render
from .. import Result, LocomotionActionAnalyzer
log = logging.getLogger(__name__)
def default(item):
return item
def sort(item):
return item[0]
def sort_sum(item):
return sum(item)
def plot(results: [[int]], ylabel: str, title: str, legend: (str,) = ("Locomotion", "Action")):
size = len(results)
@ -38,11 +48,12 @@ def plot_line(results: [[int]], ylabel="Ratio", title="Locomotion/Action "):
plt.show()
def filter_results(raw_results: [Result], keys) -> [[int]]:
def filter_results(raw_results: [Result], keys, sort=default) -> [[int]]:
results = []
for result in raw_results:
raw = result.get()
results.append([raw[k] for k in keys])
results = sorted(results,key=sort)
return results
@ -66,3 +77,12 @@ class LocomotionActionRatioRender(LocomotionActionRender):
def render(self, results: List[Result], name=None):
results = filter_results(self.filter(results), ['locomotion_action_ratio'])
plot_line(results, ylabel="Ratio", title="Locomotion/Action Ratio")
class LocomotionActionRatioHistRender(LocomotionActionRender):
def render(self, results: List[Result]):
results = filter_results(self.filter(results), ['locomotion_action_ratio'])
plt.title("locomotion/action")
plt.xlabel("ratio")
plt.ylabel("frequency")
n, bins, patches = plt.hist([results], bins=len(results))
plt.show()

View File

@ -27,6 +27,7 @@
"SimulationCategorizer",
"InstanceConfig"],
"disabled_analyzers": [
"ActivityMapper",
"LocomotionActionAnalyzer",
"LogEntryCountAnalyzer",
"LocationAnalyzer",