add MaskSpatial, formatting
parent
97f5d380a4
commit
1ffffd18e0
|
|
@ -1,3 +1,4 @@
|
|||
from .analyzer import *
|
||||
from .biogames import *
|
||||
from .locomotion_action import *
|
||||
from .mask import *
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class LocationAnalyzer(Analyzer):
|
|||
raise NotImplementedError()
|
||||
|
||||
def process(self, entry: dict) -> bool:
|
||||
if entry[self.settings.entry_type] in self.settings.spatials:
|
||||
if entry[self.settings.type_field] in self.settings.spatials:
|
||||
self.entries.append(entry)
|
||||
return False
|
||||
|
||||
|
|
@ -51,11 +51,11 @@ class LogEntryCountAnalyzer(Analyzer):
|
|||
"""
|
||||
__name__ = "LogEntryCount"
|
||||
|
||||
def result(self) -> defaultdict:
|
||||
return self.store
|
||||
def result(self) -> dict:
|
||||
return dict(self.store)
|
||||
|
||||
def process(self, entry: dict) -> bool:
|
||||
self.store[entry[self.settings.entry_type]] += 1
|
||||
self.store[entry[self.settings.type_field]] += 1
|
||||
return False
|
||||
|
||||
def __init__(self, settings: LogSettings):
|
||||
|
|
@ -73,7 +73,7 @@ class LogEntrySequenceAnalyzer(Analyzer):
|
|||
return self.store
|
||||
|
||||
def process(self, entry: dict) -> bool:
|
||||
entry_type = entry[self.settings.entry_type]
|
||||
entry_type = entry[self.settings.type_field]
|
||||
self.store.append(entry_type)
|
||||
return False
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ class ActionSequenceAnalyzer(LogEntrySequenceAnalyzer):
|
|||
__name__ = "ActionSequenceAnalyzer"
|
||||
|
||||
def process(self, entry: dict) -> bool:
|
||||
entry_type = entry[self.settings.entry_type]
|
||||
entry_type = entry[self.settings.type_field]
|
||||
if entry_type in self.settings.spatials:
|
||||
return False
|
||||
self.store.append(entry_type)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class BoardDurationAnalyzer(Analyzer):
|
|||
return result
|
||||
|
||||
def process(self, entry: dict) -> bool:
|
||||
entry_type = entry[self.settings.entry_type]
|
||||
entry_type = entry[self.settings.type_field]
|
||||
if entry_type in self.settings.boards:
|
||||
self.store.append(self.save_entry(entry["board_id"], entry["timestamp"])) # TODO: make configurable
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ from util import combinate
|
|||
def init_filter(settings: LogSettings, state: str) -> callable:
|
||||
# this implies OR for lists; AND for dicts
|
||||
if type(settings.sequences[state]) in (str, list):
|
||||
return lambda entry: entry[settings.entry_type] in settings.sequences[state]
|
||||
return lambda entry: entry[settings.type_field] in settings.sequences[state]
|
||||
else:
|
||||
return lambda entry: combinate(settings.sequences[state], entry)
|
||||
|
||||
|
||||
class LocomotionActionAnalyzer(Analyzer): # TODO
|
||||
class LocomotionActionAnalyzer(Analyzer):
|
||||
"""
|
||||
calculate locomation/action times and ratio
|
||||
calculate locomotion/action times and ratio
|
||||
|
||||
Anything between LogEntryCache and CacheEnableAction
|
||||
is counted as ActionTime, the rest as LocomotionTime.
|
||||
|
|
@ -74,15 +74,16 @@ class LocomotionActionAnalyzer(Analyzer): # TODO
|
|||
self.last = None
|
||||
|
||||
|
||||
class CacheSequenceAnalyzer(Analyzer): # TODO
|
||||
class CacheSequenceAnalyzer(Analyzer):
|
||||
__name__ = "CacheSequence"
|
||||
|
||||
def process(self, entry: dict) -> bool:
|
||||
if self.filter(entry):
|
||||
if entry['cache']:
|
||||
self.store.append((entry['timestamp'],entry['cache']['@id']))
|
||||
self.store.append((entry['timestamp'], entry['cache']['@id']))
|
||||
else:
|
||||
self.store.append((entry['timestamp'],entry['cache']))
|
||||
self.store.append((entry['timestamp'], entry['cache']))
|
||||
return False
|
||||
|
||||
def result(self) -> list:
|
||||
return self.store
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
from .analyzer import Analyzer
|
||||
|
||||
|
||||
class MaskSpatials(Analyzer):
|
||||
__name__ = "MaskSpatials"
|
||||
masked = 0
|
||||
|
||||
def process(self, entry: dict) -> bool:
|
||||
if entry[self.settings.type_field] in self.settings.spatials:
|
||||
self.masked += 1
|
||||
return True
|
||||
return False
|
||||
|
||||
def result(self) -> int:
|
||||
return self.masked
|
||||
|
|
@ -6,7 +6,7 @@ import analyzer
|
|||
|
||||
class LogSettings:
|
||||
log_format = None
|
||||
entry_type = None
|
||||
type_field = None
|
||||
spatials = None
|
||||
actions = None
|
||||
analyzers = []
|
||||
|
|
@ -15,7 +15,7 @@ class LogSettings:
|
|||
|
||||
def __init__(self, json_dict):
|
||||
self.log_format = json_dict['logFormat']
|
||||
self.entry_type = json_dict['entryType']
|
||||
self.type_field = json_dict['entryType']
|
||||
self.spatials = json_dict['spatials']
|
||||
self.actions = json_dict['actions']
|
||||
self.boards = json_dict['boards']
|
||||
|
|
@ -27,7 +27,7 @@ class LogSettings:
|
|||
def __repr__(self):
|
||||
return str({
|
||||
"logFormat": self.log_format,
|
||||
"entryType": self.entry_type,
|
||||
"entryType": self.type_field,
|
||||
"spatials": self.spatials,
|
||||
"actions": self.actions,
|
||||
"analyzers": self.analyzers,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ def json_path(obj: dict, key: str):
|
|||
if not type(obj) is dict:
|
||||
return None
|
||||
if "." not in key:
|
||||
if key not in obj:
|
||||
return None
|
||||
return obj[key]
|
||||
child_key = key.split(".")
|
||||
if child_key[0] not in obj:
|
||||
|
|
@ -10,9 +12,9 @@ def json_path(obj: dict, key: str):
|
|||
return json_path(obj[child_key[0]], ".".join(child_key[1:]))
|
||||
|
||||
|
||||
def combinate(settings: dict, entry:dict)-> bool:
|
||||
def combinate(settings: dict, entry: dict) -> bool:
|
||||
"""combine all settings {<key>: <expected>} with entry using AND"""
|
||||
result = True
|
||||
for key, value in settings.items():
|
||||
result = result and json_path(entry, key) == value
|
||||
return result
|
||||
return result
|
||||
|
|
|
|||
Loading…
Reference in New Issue