allow monitoring blinks with npcs

This commit is contained in:
Lincoln-LM 2022-01-19 16:41:27 -07:00
parent e0c0ffd548
commit d25e738af8
2 changed files with 24 additions and 10 deletions

View File

@ -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

View File

@ -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
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)
#print(paired)
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