From d22e958d382f4531446154925b9823e8ef46211c Mon Sep 17 00:00:00 2001 From: Stepan Bahnik Date: Sun, 17 May 2015 23:17:18 +0200 Subject: [PATCH] add time to first stay to mwm --- Stuff/Modules/cm.py | 6 ++++ Stuff/Modules/mwm.py | 72 ++++++++++++++++++++++++++++++++++++++++++++- Stuff/Modules/parameters.py | 6 +++- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/Stuff/Modules/cm.py b/Stuff/Modules/cm.py index 0aedfae..2c5c40c 100644 --- a/Stuff/Modules/cm.py +++ b/Stuff/Modules/cm.py @@ -128,6 +128,12 @@ def _processHeader(self, file): if strg[i] == "(": pos = i self.arenaDiameter = eval(strg[pos+1]) + elif "FeederParameters" in line and "//" not in line: + strg = line.split() + for i in range(len(strg)): + if strg[i] == "(": + pos = i + self.entranceLatency = eval(strg[pos+1]) elif "END_HEADER" in line: break diff --git a/Stuff/Modules/mwm.py b/Stuff/Modules/mwm.py index fe22734..e99ce8f 100644 --- a/Stuff/Modules/mwm.py +++ b/Stuff/Modules/mwm.py @@ -46,6 +46,8 @@ def __init__(self, nameA, *_): if not self.data: raise Exception("Failure in data initialization.") + print(self.getT1Stay()) + def _addReinforcedSector(self, string, position): self.platformX = eval(string[position+1]) @@ -54,9 +56,36 @@ def _addReinforcedSector(self, string, position): + def getT1(self, time = 1, startTime = 0, lastTime = "fromParameter"): + """computes time to get to the platform and stay there (in seconds), + argument 'time' is time of the session + argument 'lastTime' decides whether the last time point is obtained from 'time' parameter + or data + """ + start = self.findStart(startTime) + time *= 60000 # conversion from minutes to miliseconds + startTime *= 60000 + T1 = 0 + for content in self.data[start:]: + if content[5] < 2: + continue + elif content[5] in [2, 3]: + T1 = content[1] - startTime + break + + if T1 == 0 or T1 > time - startTime: + if lastTime == "fromData": # not used - may be added as an option in the future + T1 = min(time, self.data[-1][1]) - startTime + elif lastTime == "fromParameter": + T1 = time - startTime + + T1 = T1 / 1000 # conversion from miliseconds to seconds + return format(T1, "0.1f") + + def getT1Pass(self, time = 1, startTime = 0, lastTime = "fromParameter"): - """computes time to first shock (in seconds), + """computes time to first pass through the platform (in seconds), argument 'time' is time of the session argument 'lastTime' decides whether the last time point is obtained from 'time' parameter or data @@ -81,6 +110,47 @@ def getT1Pass(self, time = 1, startTime = 0, lastTime = "fromParameter"): return format(T1, "0.1f") + def getT1Stay(self, time = 1, startTime = 0, platformAdjustment = 2, lastTime = "fromParameter"): + """computes time to first stay in the vicinity of the platform (in seconds), + argument 'time' is time of the session + argument 'lastTime' decides whether the last time point is obtained from 'time' parameter + or data + """ + time = time * 60000 # conversion from minutes to miliseconds + start = self.findStart(startTime) + T1 = 0 + x, y = self.platformX, self.platformY + passTime = None + for content in self.data[start:]: + if content[5] == 0: + if passTime: + distanceToTarget = sqrt((content[2] - x)**2 + (content[3] - y)**2) + if distanceToTarget < self.platformRadius * platformAdjustment: + if content[1] - passTime >= self.entranceLatency: + T1 = content[1] - startTime + break + else: + passTime = None + elif content[5] in [2, 3]: + T1 = content[1] - startTime + break + elif content[5] == 1: + if not passTime: + passTime = content[1] + elif content[1] - passTime >= self.entranceLatency: + T1 = content[1] - startTime + break + + if T1 == 0 or T1 > time - startTime: + if lastTime == "fromData": # not used - may be added as an option in the future + T1 = min(time, self.data[-1][1]) - startTime + elif lastTime == "fromParameter": + T1 = time - startTime + + T1 = T1 / 1000 # conversion from miliseconds to seconds + return format(T1, "0.1f") + + def getPasses(self, time = 1, startTime = 0): """computes number of entrances, argument 'time' is time of the session diff --git a/Stuff/Modules/parameters.py b/Stuff/Modules/parameters.py index f732729..fa9cfcf 100644 --- a/Stuff/Modules/parameters.py +++ b/Stuff/Modules/parameters.py @@ -181,7 +181,11 @@ def __init__(self): "Computed from every [in rows]"), "minDifference": (Opt('MinDiffParAvgDistance', 0, ['int', 'float']), "Minimal distance counted [in pixels]") - }) + }) + self["Time to first stay"] = Par("getT1Stay", "experimental", { + "platformAdjustment": (Opt('platformAdjustmentT1Stay', 2, ['int', 'float']), + "Platform adjustment") + }) self["Average distance from chosen"] = Par("getAvgDistanceChosen", "advanced", { "angle": (Opt('angleParAvgDistanceCustom', 180, ['int', 'float', 'list']), "Angle of chosen location relative to the target [in degrees]"),