diff --git a/src/player_blink_gui.py b/src/player_blink_gui.py index 8771956..acfc068 100644 --- a/src/player_blink_gui.py +++ b/src/player_blink_gui.py @@ -222,7 +222,7 @@ class Application(tk.Frame): self.display_percent.insert(0, 100) self.after_task() - + def increase_advances(self): plus = int(self.advances_increase.get()) self.rng.advance(plus) @@ -333,7 +333,7 @@ class Application(tk.Frame): def monitoring_work(self): self.tracking = False blinks, intervals, offset_time = rngtool.tracking_blink(self.player_eye, *self.config_json["view"], MonitorWindow=self.config_json["MonitorWindow"], WindowPrefix=self.config_json["WindowPrefix"], crop=self.config_json["crop"], camera=self.config_json["camera"], tk_window=self, th=self.config_json["thresh"]) - self.rng = rngtool.recov(blinks, intervals) + self.rng = rngtool.recov(blinks, intervals, npc=self.config_json["npc"]) self.monitor_blink_button['text'] = "Monitor Blinks" self.monitoring = False diff --git a/src/rngtool.py b/src/rngtool.py index fc3e21e..2f3e594 100644 --- a/src/rngtool.py +++ b/src/rngtool.py @@ -370,31 +370,45 @@ def simultaneous_tracking(plimg, plroi:Tuple[int,int,int,int], pkimg, pkroi:Tupl print(intervals) return (blinks, intervals, offset_time) -def recov(blinks:List[int],rawintervals:List[int])->Xorshift: +def recov(blinks:List[int],rawintervals:List[int],npc:int=0)->Xorshift: """ Recover the xorshift from the type and interval of blinks. Args: blinks (List[int]): intervals (List[int]): + npc (int): Returns: List[int]: internalstate """ intervals = rawintervals[1:] + if npc != 0: + intervals = [x*(npc+1) for x in intervals] advanced_frame = sum(intervals) states = calc.reverseStates(blinks, intervals) prng = Xorshift(*states) states = prng.getState() #validation check - expected_blinks = [r&0xF for r in prng.getNextRandSequence(advanced_frame) if r&0b1110==0] - paired = list(zip(blinks,expected_blinks)) - print(blinks) - print(expected_blinks) - #print(paired) - assert all([o==e for o,e in paired]) - + if npc == 0: + expected_blinks = [r&0xF for r in prng.getNextRandSequence(advanced_frame) if r&0b1110==0] + paired = list(zip(blinks,expected_blinks)) + print(blinks) + print(expected_blinks) + assert all([o==e for o,e in paired]) + else: + raise_error = True + for d in range(npc+1): + expected_blinks = [r&0xF for r in prng.getNextRandSequence(advanced_frame*npc)[d::npc+1] if r&0b1110==0] + paired = list(zip(blinks,expected_blinks)) + if all([o==e for o,e in paired]): + raise_error = False + break + print(blinks) + print(expected_blinks) + if raise_error: + raise all([o==e for o,e in paired]) result = Xorshift(*states) result.getNextRandSequence(advanced_frame) return result