Skip to content

Commit

Permalink
fixed bug #492
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierfriard committed May 16, 2022
1 parent 53d3d06 commit 9ffcbc4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 56 deletions.
19 changes: 9 additions & 10 deletions boris/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4437,9 +4437,9 @@ def full_event(self, behavior_idx: str) -> dict:
# pause if media and media playing
if self.pj[cfg.OBSERVATIONS][self.observationId][cfg.TYPE] in [cfg.MEDIA]:
if self.playerType == cfg.MEDIA:
memState = self.dw_player[0].mediaListPlayer.get_state()
# FIXME
if memState == self.vlc_playing:

if self.is_playing():
flag_player_playing = True
self.pause_video()

self.codingMapWindow = modifiers_coding_map.ModifiersCodingMapWindowClass(
Expand All @@ -4460,13 +4460,12 @@ def full_event(self, behavior_idx: str) -> dict:
# restart media
if self.pj[cfg.OBSERVATIONS][self.observationId][cfg.TYPE] in [cfg.MEDIA]:
if self.playerType == cfg.MEDIA:
# FIXME
if memState == self.vlc_playing:
if flag_player_playing:
self.play_video()

return event

def beep(self, sound_type: str):
def beep(self, sound_type: str) -> None:
"""
emit beep on various platform
Expand All @@ -4476,7 +4475,7 @@ def beep(self, sound_type: str):

QSound.play(f":/{sound_type}")

def is_playing(self):
def is_playing(self) -> bool:
"""
check if first media player is playing for cfg.MEDIA
Expand All @@ -4496,7 +4495,7 @@ def is_playing(self):
else:
return False

def keyPressEvent(self, event):
def keyPressEvent(self, event) -> None:

logging.debug(f"text #{event.text()}# event key: {event.key()} ")
"""
Expand Down Expand Up @@ -4719,7 +4718,7 @@ def keyPressEvent(self, event):
if not self.currentSubject and self.alertNoFocalSubject:
if self.pj[cfg.OBSERVATIONS][self.observationId][cfg.TYPE] in [cfg.MEDIA]:
if self.playerType == cfg.MEDIA:
if self.dw_player[0].mediaListPlayer.get_state() == self.vlc_playing:
if self.is_playing():
flagPlayerPlaying = True
self.pause_video()

Expand Down Expand Up @@ -4811,7 +4810,7 @@ def click_signal_find_in_events(self, msg):
if self.find_dialog.cbBehavior.isChecked():
fields_list.append(cfg.EVENT_BEHAVIOR_FIELD_IDX)
if self.find_dialog.cbModifier.isChecked():
"""fields_list.append(EVENT_MODIFIER_FIELD_IDX )"""
# fields_list.append(cfg.EVENT_MODIFIER_FIELD_IDX )
fields_list.append(4)

if self.find_dialog.cbComment.isChecked():
Expand Down
87 changes: 43 additions & 44 deletions boris/plot_events_rt.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,64 +135,63 @@ def aggregate_events(self, events: list, start: float, end: float) -> dict:
AltGr + p -> þ
"""

def group(subject, code, modifier):
def group(subject: str, code: str, modifier: str) -> str:
if self.groupby == "behaviors":
return f"{subject}þ{code}"
else: # with modifiers
return f"{subject}þ{code}þ{modifier}"

try:
mem_behav = {}
intervals_behav = {}
mem_behav = {}
intervals_behav = {}

for event in events:
intervals_behav[group(event[1], event[2], event[3])] = [(0, 0)]
for event in events:
intervals_behav[group(event[1], event[2], event[3])] = [(0, 0)]

for event in events:
for event in events:

time_, subject, code, modifier = event[:4]
key = group(subject, code, modifier)
time_, subject, code, modifier = event[:4]
key = group(subject, code, modifier)

# check if code is state
if code in self.state_events_list:
# check if code is state
if code in self.state_events_list:

if key in mem_behav and mem_behav[key] is not None:
# stop interval
if key in mem_behav and mem_behav[key] is not None:
# stop interval

# check if event is in interval start-end
if any(
# check if event is in interval start-end
if any(
(
start <= mem_behav[key] <= end,
start <= time_ <= end,
mem_behav[key] <= start and time_ > end,
):
intervals_behav[key].append((float(mem_behav[key]), float(time_)))
mem_behav[key] = None
else:
# start interval
mem_behav[key] = time_

else: # point event

if start <= time_ <= end:
intervals_behav[key].append(
(float(time_), float(time_) + self.point_event_plot_duration * 50)
) # point event -> 1 s

# check if intervals are closed
for k in mem_behav:
if mem_behav[k] is not None: # interval open
if self.observation_type == cfg.LIVE:
intervals_behav[k].append(
(float(mem_behav[k]), float((end + start) / 2))
) # close interval with current time

elif self.observation_type == cfg.MEDIA:

intervals_behav[k].append((float(mem_behav[k]), float(end))) # close interval with end value
return intervals_behav

except Exception:
return {"error": ""}
)
):
intervals_behav[key].append((float(mem_behav[key]), float(time_)))
mem_behav[key] = None
else:
# start interval
mem_behav[key] = time_

else: # point event

if start <= time_ <= end:
intervals_behav[key].append(
(float(time_), float(time_) + self.point_event_plot_duration * 50)
) # point event -> 1 s

# check if intervals are closed
for k in mem_behav:
if mem_behav[k] is not None: # interval open
if self.observation_type == cfg.LIVE:
intervals_behav[k].append(
(float(mem_behav[k]), float((end + start) / 2))
) # close interval with current time

elif self.observation_type == cfg.MEDIA:

intervals_behav[k].append((float(mem_behav[k]), float(end))) # close interval with end value

return intervals_behav

def plot_events(self, current_time: float, force_plot: bool = False):
"""
Expand Down
4 changes: 2 additions & 2 deletions boris/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"""

__version__ = "8.4"
__version_date__ = "BETA 2022-05-13"
__version__ = "8.4.1"
__version_date__ = "BETA 2022-05-16"

0 comments on commit 9ffcbc4

Please sign in to comment.