init
commit
b5f522ad8b
|
|
@ -0,0 +1,2 @@
|
||||||
|
from .analyzer import *
|
||||||
|
from .biogames import *
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
from log_analyzer import LogSettings
|
||||||
|
|
||||||
|
|
||||||
|
class Analyzer:
|
||||||
|
def __init__(self, settings: LogSettings):
|
||||||
|
self.settings = settings
|
||||||
|
|
||||||
|
def process(self, entry: object) -> bool:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def result(self) -> object:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
|
class LocationAnalyzer(Analyzer):
|
||||||
|
|
||||||
|
def __init__(self, settings: LogSettings):
|
||||||
|
super().__init__(settings)
|
||||||
|
|
||||||
|
def result(self) -> object:
|
||||||
|
return self.settings.spatials
|
||||||
|
|
||||||
|
def process(self, entry: object) -> bool:
|
||||||
|
pass
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
from log_analyzer import LogSettings
|
||||||
|
|
||||||
|
from .analyzer import Analyzer
|
||||||
|
|
||||||
|
|
||||||
|
class BoardDurationAnalyzer(Analyzer):
|
||||||
|
def result(self) -> object:
|
||||||
|
return self.store
|
||||||
|
|
||||||
|
def process(self, entry: object) -> bool:
|
||||||
|
self.store[entry] += 1
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __init__(self, settings: LogSettings):
|
||||||
|
super().__init__(settings)
|
||||||
|
self.store = defaultdict(lambda: 0)
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"logFormat": "json",
|
||||||
|
"entryType": "@class",
|
||||||
|
"spatials":["...PositionLogEvent"],
|
||||||
|
"actions":["...QuestionAnswerEvent", "...SimuAnswerEvent"],
|
||||||
|
"analyzers": {
|
||||||
|
"analyzer": [
|
||||||
|
"LocationAnalyzer"
|
||||||
|
],
|
||||||
|
"analyzer.biogames": [
|
||||||
|
"BoardDurationAnalyzer"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class Loader:
|
||||||
|
def load(self, file: str):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def get_entry(self) -> object:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
|
class JSONLoader(Loader):
|
||||||
|
data = None
|
||||||
|
|
||||||
|
def load(self, file: str):
|
||||||
|
self.data = json.load(open(file))
|
||||||
|
|
||||||
|
def get_entry(self):
|
||||||
|
for entry in self.data:
|
||||||
|
yield entry
|
||||||
|
|
||||||
|
class SQLiteLoader(Loader):
|
||||||
|
def load(self, file: str):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_entry(self) -> object:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
LOADERS = {
|
||||||
|
"json": JSONLoader,
|
||||||
|
"sqlite": SQLiteLoader
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from load import LOADERS
|
||||||
|
import analyzer
|
||||||
|
|
||||||
|
|
||||||
|
class LogSettings:
|
||||||
|
log_format = None
|
||||||
|
entry_type = None
|
||||||
|
spatials = None
|
||||||
|
actions = None
|
||||||
|
analyzers = []
|
||||||
|
|
||||||
|
def __init__(self, json_dict):
|
||||||
|
self.log_format = json_dict['logFormat']
|
||||||
|
self.entry_type = json_dict['entryType']
|
||||||
|
self.spatials = json_dict['spatials']
|
||||||
|
self.actions = json_dict['actions']
|
||||||
|
for mod in json_dict['analyzers']:
|
||||||
|
for name in json_dict['analyzers'][mod]:
|
||||||
|
self.analyzers.append(getattr(sys.modules[mod], name))
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return str({
|
||||||
|
"logFormat": self.log_format,
|
||||||
|
"entryType": self.entry_type,
|
||||||
|
"spatials": self.spatials,
|
||||||
|
"actions": self.actions,
|
||||||
|
"analyzers": self.analyzers
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def load_settings(file:str) -> LogSettings:
|
||||||
|
return LogSettings(json.load(open(file)))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
settings = load_settings("biogames.json")
|
||||||
|
print(settings)
|
||||||
|
logfile = "sample.json"
|
||||||
|
loader = LOADERS[settings.log_format]()
|
||||||
|
try:
|
||||||
|
loader.load(logfile)
|
||||||
|
except BaseException as e:
|
||||||
|
raise RuntimeError(e)
|
||||||
|
analyzers = []
|
||||||
|
for analyzer in settings.analyzers:
|
||||||
|
analyzers.append(analyzer(settings))
|
||||||
|
for entry in loader.get_entry():
|
||||||
|
for analyzer in analyzers:
|
||||||
|
analyzer.process(entry)
|
||||||
|
for analyzer in analyzers:
|
||||||
|
print("* Result for " + str(type(analyzer)))
|
||||||
|
print(analyzer.result())
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
||||||
Loading…
Reference in New Issue