boris-behav-obs 8.27.8__py2.py3-none-any.whl → 8.27.9__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,9 +70,10 @@ def synthetic_time_budget(self) -> None:
70
70
  start_coding=start_coding,
71
71
  end_coding=end_coding,
72
72
  maxTime=max_media_duration_all_obs,
73
- flagShowExcludeBehaviorsWoEvents=False,
73
+ show_exclude_non_coded_behaviors=False,
74
74
  by_category=False,
75
75
  n_observations=len(selected_observations),
76
+ show_exclude_non_coded_modifiers=True,
76
77
  )
77
78
 
78
79
  if synth_tb_param == {}:
@@ -195,10 +196,11 @@ def synthetic_binned_time_budget(self) -> None:
195
196
  start_coding=start_coding,
196
197
  end_coding=end_coding,
197
198
  maxTime=max_media_duration_all_obs,
198
- flagShowExcludeBehaviorsWoEvents=False,
199
+ show_exclude_non_coded_behaviors=False,
199
200
  by_category=False,
200
201
  n_observations=len(selected_observations),
201
202
  show_time_bin_size=True,
203
+ show_exclude_non_coded_modifiers=True,
202
204
  )
203
205
 
204
206
  if synth_tb_param == {}:
@@ -25,6 +25,8 @@ from decimal import Decimal as dec
25
25
  from typing import Tuple
26
26
  import tablib
27
27
  import logging
28
+ import itertools
29
+ import re
28
30
 
29
31
  from . import config as cfg
30
32
  from . import db_functions
@@ -134,35 +136,24 @@ def synthetic_time_budget_bin(pj: dict, selected_observations: list, parameters_
134
136
  """
135
137
 
136
138
  def interval_len(interval):
137
- if interval.empty:
138
- return dec(0)
139
- else:
140
- return sum([x.upper - x.lower for x in interval])
139
+ return dec(0) if interval.empty else sum([x.upper - x.lower for x in interval])
141
140
 
142
141
  def interval_number(interval):
143
- if interval.empty:
144
- return dec(0)
145
- else:
146
- return len(interval)
142
+ return dec(0) if interval.empty else len(interval)
147
143
 
148
144
  def interval_mean(interval):
149
- if interval.empty:
150
- return dec(0)
151
- else:
152
- return sum([x.upper - x.lower for x in interval]) / len(interval)
145
+ return dec(0) if interval.empty else sum([x.upper - x.lower for x in interval]) / len(interval)
153
146
 
154
147
  def interval_std_dev(interval) -> str:
155
148
  if interval.empty:
156
- return "NA"
149
+ return cfg.NA
157
150
  else:
158
151
  try:
159
152
  return f"{statistics.stdev([x.upper - x.lower for x in interval]):.3f}"
160
153
  except Exception:
161
154
  return cfg.NA
162
155
 
163
- selected_subjects = parameters_obs[cfg.SELECTED_SUBJECTS]
164
156
  selected_behaviors = parameters_obs[cfg.SELECTED_BEHAVIORS]
165
- include_modifiers = parameters_obs[cfg.INCLUDE_MODIFIERS]
166
157
  time_interval = parameters_obs["time"]
167
158
  start_time = parameters_obs[cfg.START_TIME]
168
159
  end_time = parameters_obs[cfg.END_TIME]
@@ -182,12 +173,26 @@ def synthetic_time_budget_bin(pj: dict, selected_observations: list, parameters_
182
173
  distinct_behav_modif = []
183
174
  for obs_id in selected_observations:
184
175
  for event in pj[cfg.OBSERVATIONS][obs_id][cfg.EVENTS]:
185
- if include_modifiers:
186
- if (
187
- event[cfg.EVENT_BEHAVIOR_FIELD_IDX],
188
- event[cfg.EVENT_MODIFIER_FIELD_IDX],
189
- ) not in distinct_behav_modif:
190
- distinct_behav_modif.append((event[cfg.EVENT_BEHAVIOR_FIELD_IDX], event[cfg.EVENT_MODIFIER_FIELD_IDX]))
176
+ if parameters_obs[cfg.INCLUDE_MODIFIERS]:
177
+ if parameters_obs[cfg.EXCLUDE_NON_CODED_MODIFIERS]:
178
+ # get coded modifiers
179
+ if (
180
+ event[cfg.EVENT_BEHAVIOR_FIELD_IDX],
181
+ event[cfg.EVENT_MODIFIER_FIELD_IDX],
182
+ ) not in distinct_behav_modif:
183
+ distinct_behav_modif.append((event[cfg.EVENT_BEHAVIOR_FIELD_IDX], event[cfg.EVENT_MODIFIER_FIELD_IDX]))
184
+ else:
185
+ # get all modifiers combination
186
+ ms: list = []
187
+ modifiers_list = project_functions.get_modifiers_of_behavior(pj[cfg.ETHOGRAM], event[cfg.EVENT_BEHAVIOR_FIELD_IDX])
188
+ if modifiers_list:
189
+ for modif_set in modifiers_list[0]:
190
+ modif_set.append("None")
191
+ ms.append([re.sub(r" \(.*\)", "", x) for x in modif_set])
192
+ distinct_modifiers = ["|".join(x) for x in itertools.product(*ms)]
193
+ for modifier in distinct_modifiers:
194
+ distinct_behav_modif.append((event[cfg.EVENT_BEHAVIOR_FIELD_IDX], modifier))
195
+
191
196
  else:
192
197
  if (event[cfg.EVENT_BEHAVIOR_FIELD_IDX], "") not in distinct_behav_modif:
193
198
  distinct_behav_modif.append((event[cfg.EVENT_BEHAVIOR_FIELD_IDX], ""))
@@ -209,7 +214,7 @@ def synthetic_time_budget_bin(pj: dict, selected_observations: list, parameters_
209
214
  behav_header[1] = "Behaviors:"
210
215
  modif_header[1] = "Modifiers:"
211
216
 
212
- for subj in selected_subjects:
217
+ for subj in parameters_obs[cfg.SELECTED_SUBJECTS]:
213
218
  for behavior_modifiers in distinct_behav_modif:
214
219
  behavior, modifiers = behavior_modifiers
215
220
  behavior_modifiers_str = "|".join(behavior_modifiers) if modifiers else behavior
@@ -221,7 +226,7 @@ def synthetic_time_budget_bin(pj: dict, selected_observations: list, parameters_
221
226
 
222
227
  data_report.append(subj_header)
223
228
  data_report.append(behav_header)
224
- if include_modifiers:
229
+ if parameters_obs[cfg.INCLUDE_MODIFIERS]:
225
230
  data_report.append(modif_header)
226
231
  data_report.append(param_header)
227
232
 
@@ -230,7 +235,7 @@ def synthetic_time_budget_bin(pj: dict, selected_observations: list, parameters_
230
235
  ]
231
236
  # select time interval
232
237
  for obs_id in selected_observations:
233
- behaviors = init_behav_modif_bin(pj[cfg.ETHOGRAM], selected_subjects, distinct_behav_modif, parameters)
238
+ behaviors = init_behav_modif_bin(pj[cfg.ETHOGRAM], parameters_obs[cfg.SELECTED_SUBJECTS], distinct_behav_modif, parameters)
234
239
 
235
240
  obs_length = observation_operations.observation_total_length(pj[cfg.OBSERVATIONS][obs_id])
236
241
 
@@ -263,13 +268,13 @@ def synthetic_time_budget_bin(pj: dict, selected_observations: list, parameters_
263
268
  else:
264
269
  current_subject = event[cfg.EVENT_SUBJECT_FIELD_IDX]
265
270
 
266
- if current_subject not in selected_subjects:
271
+ if current_subject not in parameters_obs[cfg.SELECTED_SUBJECTS]:
267
272
  continue
268
273
  if current_subject not in events_interval:
269
274
  events_interval[current_subject] = {}
270
275
  mem_events_interval[current_subject] = {}
271
276
 
272
- if include_modifiers:
277
+ if parameters_obs[cfg.INCLUDE_MODIFIERS]:
273
278
  modif = event[cfg.EVENT_MODIFIER_FIELD_IDX]
274
279
  else:
275
280
  modif = ""
@@ -338,7 +343,7 @@ def synthetic_time_budget_bin(pj: dict, selected_observations: list, parameters_
338
343
  behaviors[subject][behav]["proportion of time"] = cfg.NA
339
344
 
340
345
  columns = [obs_id, f"{max_time - min_time:.3f}", f"{time_bin_start:.3f}-{time_bin_end:.3f}"]
341
- for subject in selected_subjects:
346
+ for subject in parameters_obs[cfg.SELECTED_SUBJECTS]:
342
347
  for behavior_modifiers in distinct_behav_modif:
343
348
  behavior, modifiers = behavior_modifiers
344
349
  behavior_modifiers_str = behavior_modifiers
@@ -374,12 +379,9 @@ def synthetic_time_budget(pj: dict, selected_observations: list, parameters_obs:
374
379
  tablib.Dataset: dataset containing synthetic time budget data
375
380
  """
376
381
 
377
- selected_subjects = parameters_obs[cfg.SELECTED_SUBJECTS]
378
- selected_behaviors = parameters_obs[cfg.SELECTED_BEHAVIORS]
379
- include_modifiers = parameters_obs[cfg.INCLUDE_MODIFIERS]
380
382
  interval = parameters_obs["time"]
381
- start_time = parameters_obs["start time"]
382
- end_time = parameters_obs["end time"]
383
+ start_time = parameters_obs[cfg.START_TIME]
384
+ end_time = parameters_obs[cfg.END_TIME]
383
385
 
384
386
  parameters = [
385
387
  ["duration", "Total duration"],
@@ -392,7 +394,9 @@ def synthetic_time_budget(pj: dict, selected_observations: list, parameters_obs:
392
394
  data_report = tablib.Dataset()
393
395
  data_report.title = "Synthetic time budget"
394
396
 
395
- ok, msg, db_connector = db_functions.load_aggregated_events_in_db(pj, selected_subjects, selected_observations, selected_behaviors)
397
+ ok, msg, db_connector = db_functions.load_aggregated_events_in_db(
398
+ pj, parameters_obs[cfg.SELECTED_SUBJECTS], selected_observations, parameters_obs[cfg.SELECTED_BEHAVIORS]
399
+ )
396
400
 
397
401
  if not ok:
398
402
  return False, msg, None
@@ -400,20 +404,32 @@ def synthetic_time_budget(pj: dict, selected_observations: list, parameters_obs:
400
404
  db_connector.create_aggregate("stdev", 1, StdevFunc)
401
405
  cursor = db_connector.cursor()
402
406
 
403
- # modifiers
404
- if include_modifiers:
405
- cursor.execute("SELECT distinct behavior, modifiers FROM aggregated_events")
406
- distinct_behav_modif = [[rows["behavior"], rows["modifiers"]] for rows in cursor.fetchall()]
407
- else:
408
- cursor.execute("SELECT distinct behavior FROM aggregated_events")
409
- distinct_behav_modif = [[rows["behavior"], ""] for rows in cursor.fetchall()]
410
-
411
407
  # add selected behaviors that are not observed
412
- for behav in selected_behaviors:
413
- if [x for x in distinct_behav_modif if x[0] == behav] == []:
414
- distinct_behav_modif.append([behav, ""])
408
+ distinct_behav_modif: list = []
409
+ for behavior in parameters_obs[cfg.SELECTED_BEHAVIORS]:
410
+ # modifiers
411
+ if parameters_obs[cfg.INCLUDE_MODIFIERS]:
412
+ if parameters_obs[cfg.EXCLUDE_NON_CODED_MODIFIERS]:
413
+ # get coded modifiers
414
+ cursor.execute("SELECT DISTINCT modifiers FROM aggregated_events WHERE behavior = ?", (behavior,))
415
+ for row in cursor.fetchall():
416
+ distinct_behav_modif.append((behavior, row["modifiers"]))
417
+ else:
418
+ # get all modifiers combination
419
+ ms: list = []
420
+ modifiers_list = project_functions.get_modifiers_of_behavior(pj[cfg.ETHOGRAM], behavior)
421
+ if modifiers_list:
422
+ for modif_set in modifiers_list[0]:
423
+ modif_set.append("None")
424
+ ms.append([re.sub(r" \(.*\)", "", x) for x in modif_set])
425
+ distinct_modifiers = ["|".join(x) for x in itertools.product(*ms)]
426
+ for modifier in distinct_modifiers:
427
+ distinct_behav_modif.append((behavior, modifier))
428
+
429
+ else:
430
+ distinct_behav_modif.append((behavior, ""))
415
431
 
416
- """behaviors = init_behav_modif(pj[cfg.ETHOGRAM], selected_subjects, distinct_behav_modif, parameters)"""
432
+ # print(f"{distinct_behav_modif=}")
417
433
 
418
434
  param_header = ["Observations id", "Total length (s)"]
419
435
  subj_header, behav_header, modif_header = (
@@ -425,10 +441,10 @@ def synthetic_time_budget(pj: dict, selected_observations: list, parameters_obs:
425
441
  behav_header[1] = "Behaviors:"
426
442
  modif_header[1] = "Modifiers:"
427
443
 
428
- for subj in selected_subjects:
429
- for behavior_modifiers in distinct_behav_modif:
430
- behavior, modifiers = behavior_modifiers
431
- behavior_modifiers_str = "|".join(behavior_modifiers) if modifiers else behavior
444
+ for subj in parameters_obs[cfg.SELECTED_SUBJECTS]:
445
+ for behavior, modifiers in distinct_behav_modif:
446
+ """behavior, modifiers = behavior_modifiers"""
447
+ """behavior_modifiers_str = "|".join(behavior_modifiers) if modifiers else behavior"""
432
448
  for param in parameters:
433
449
  subj_header.append(subj)
434
450
  behav_header.append(behavior)
@@ -437,15 +453,17 @@ def synthetic_time_budget(pj: dict, selected_observations: list, parameters_obs:
437
453
 
438
454
  data_report.append(subj_header)
439
455
  data_report.append(behav_header)
440
- if include_modifiers:
456
+ if parameters_obs[cfg.INCLUDE_MODIFIERS]:
441
457
  data_report.append(modif_header)
442
458
  data_report.append(param_header)
443
459
 
444
460
  # select time interval
445
461
  for obs_id in selected_observations:
446
- behaviors = init_behav_modif(pj[cfg.ETHOGRAM], selected_subjects, distinct_behav_modif, parameters)
462
+ behaviors = init_behav_modif(pj[cfg.ETHOGRAM], parameters_obs[cfg.SELECTED_SUBJECTS], distinct_behav_modif, parameters)
447
463
 
448
- ok, msg, db_connector = db_functions.load_aggregated_events_in_db(pj, selected_subjects, [obs_id], selected_behaviors)
464
+ ok, msg, db_connector = db_functions.load_aggregated_events_in_db(
465
+ pj, parameters_obs[cfg.SELECTED_SUBJECTS], [obs_id], parameters_obs[cfg.SELECTED_BEHAVIORS]
466
+ )
449
467
 
450
468
  if not ok:
451
469
  return False, msg, None
@@ -453,7 +471,7 @@ def synthetic_time_budget(pj: dict, selected_observations: list, parameters_obs:
453
471
  db_connector.create_aggregate("stdev", 1, StdevFunc)
454
472
  cursor = db_connector.cursor()
455
473
  # if modifiers not to be included set modifiers to ""
456
- if not include_modifiers:
474
+ if not parameters_obs[cfg.INCLUDE_MODIFIERS]:
457
475
  cursor.execute("UPDATE aggregated_events SET modifiers = ''")
458
476
 
459
477
  # time
@@ -528,14 +546,14 @@ def synthetic_time_budget(pj: dict, selected_observations: list, parameters_obs:
528
546
  ),
529
547
  )
530
548
 
531
- for subject in selected_subjects:
549
+ for subject in parameters_obs[cfg.SELECTED_SUBJECTS]:
532
550
  # check if behaviors are to exclude from total time
533
551
  time_to_subtract = 0
534
552
  if obs_length != dec(-2): # obs not an images obs without time
535
553
  if cfg.EXCLUDED_BEHAVIORS in parameters_obs:
536
554
  for excluded_behav in parameters_obs[cfg.EXCLUDED_BEHAVIORS]:
537
555
  cursor.execute(
538
- ("SELECT SUM(stop-start) " "FROM aggregated_events " "WHERE observation = ? AND subject = ? AND behavior = ? "),
556
+ ("SELECT SUM(stop-start) FROM aggregated_events WHERE observation = ? AND subject = ? AND behavior = ? "),
539
557
  (
540
558
  obs_id,
541
559
  subject,
@@ -613,7 +631,7 @@ def synthetic_time_budget(pj: dict, selected_observations: list, parameters_obs:
613
631
  columns = [obs_id, cfg.NA]
614
632
  else:
615
633
  columns = [obs_id, f"{max_time - min_time:0.3f}"]
616
- for subj in selected_subjects:
634
+ for subj in parameters_obs[cfg.SELECTED_SUBJECTS]:
617
635
  for behavior_modifiers in distinct_behav_modif:
618
636
  behavior, modifiers = behavior_modifiers
619
637
  behavior_modifiers_str = "|".join(behavior_modifiers) if modifiers else behavior
@@ -654,12 +672,23 @@ def time_budget_analysis(
654
672
  out: list = []
655
673
  for subject in parameters[cfg.SELECTED_SUBJECTS]:
656
674
  out_cat: list = []
657
- categories[subject]: dict = {}
675
+ categories[subject] = {}
658
676
 
659
677
  for behavior in parameters[cfg.SELECTED_BEHAVIORS]:
660
678
  if parameters[cfg.INCLUDE_MODIFIERS]: # with modifiers
661
- cursor.execute("SELECT DISTINCT modifiers FROM events WHERE subject = ? AND code = ?", (subject, behavior))
662
- distinct_modifiers = list(cursor.fetchall())
679
+ if parameters[cfg.EXCLUDE_NON_CODED_MODIFIERS]:
680
+ # get coded modifiers
681
+ cursor.execute("SELECT DISTINCT modifiers FROM events WHERE subject = ? AND code = ?", (subject, behavior))
682
+ distinct_modifiers = [x[0] for x in cursor.fetchall()]
683
+ else:
684
+ # get all modifiers combinations
685
+ ms: list = []
686
+ modifiers_list = project_functions.get_modifiers_of_behavior(ethogram, behavior)
687
+ if modifiers_list:
688
+ for modif_set in modifiers_list[0]:
689
+ modif_set.append("None")
690
+ ms.append([re.sub(r" \(.*\)", "", x) for x in modif_set])
691
+ distinct_modifiers = ["|".join(x) for x in itertools.product(*ms)]
663
692
 
664
693
  if not distinct_modifiers:
665
694
  if not parameters[cfg.EXCLUDE_BEHAVIORS]:
@@ -670,7 +699,7 @@ def time_budget_analysis(
670
699
  else:
671
700
  duration = 0.000
672
701
 
673
- out.append(
702
+ out_cat.append(
674
703
  {
675
704
  "subject": subject,
676
705
  "behavior": behavior,
@@ -684,7 +713,7 @@ def time_budget_analysis(
684
713
  }
685
714
  )
686
715
  else: # point
687
- out.append(
716
+ out_cat.append(
688
717
  {
689
718
  "subject": subject,
690
719
  "behavior": behavior,
@@ -701,6 +730,8 @@ def time_budget_analysis(
701
730
 
702
731
  if cfg.POINT in project_functions.event_type(behavior, ethogram):
703
732
  for modifier in distinct_modifiers:
733
+ print(f"{modifier=}")
734
+
704
735
  cursor.execute(
705
736
  (
706
737
  "SELECT occurence, observation FROM events "
@@ -709,7 +740,7 @@ def time_budget_analysis(
709
740
  "AND modifiers = ? "
710
741
  "ORDER BY observation, occurence"
711
742
  ),
712
- (subject, behavior, modifier[0]),
743
+ (subject, behavior, modifier),
713
744
  )
714
745
 
715
746
  rows = cursor.fetchall()
@@ -721,20 +752,12 @@ def time_budget_analysis(
721
752
  new_rows.append([float("NaN"), observation])
722
753
  else:
723
754
  new_rows.append([occurence, observation])
724
- """
725
- if occurence is not None:
726
- new_occurence = max(float(parameters["start time"]), occurence)
727
- new_occurence = min(new_occurence, float(parameters["end time"]))
728
- else:
729
- new_occurence = float("NaN")
730
- new_rows.append([new_occurence, observation])
731
- """
732
755
  rows = list(new_rows)
733
756
 
734
757
  # include behaviors without events
735
758
  if len(rows) == 0:
736
759
  if not parameters[cfg.EXCLUDE_BEHAVIORS]:
737
- out.append(
760
+ out_cat.append(
738
761
  {
739
762
  "subject": subject,
740
763
  "behavior": behavior,
@@ -769,7 +792,7 @@ def time_budget_analysis(
769
792
  {
770
793
  "subject": subject,
771
794
  "behavior": behavior,
772
- "modifiers": modifier[0],
795
+ "modifiers": modifier,
773
796
  "duration": cfg.NA,
774
797
  "duration_mean": cfg.NA,
775
798
  "duration_stdev": cfg.NA,
@@ -789,7 +812,7 @@ def time_budget_analysis(
789
812
  "AND modifiers = ? "
790
813
  "ORDER BY observation, occurence"
791
814
  ),
792
- (subject, behavior, modifier[0]),
815
+ (subject, behavior, modifier),
793
816
  )
794
817
 
795
818
  rows = list(cursor.fetchall())
@@ -801,11 +824,11 @@ def time_budget_analysis(
801
824
  duration = cfg.NA
802
825
  else:
803
826
  duration: float = 0.000
804
- out.append(
827
+ out_cat.append(
805
828
  {
806
829
  "subject": subject,
807
830
  "behavior": behavior,
808
- "modifiers": modifier[0],
831
+ "modifiers": modifier,
809
832
  "duration": duration,
810
833
  "duration_mean": cfg.NA,
811
834
  "duration_stdev": cfg.NA,
@@ -817,11 +840,11 @@ def time_budget_analysis(
817
840
  continue
818
841
 
819
842
  if len(rows) % 2:
820
- out.append(
843
+ out_cat.append(
821
844
  {
822
845
  "subject": subject,
823
846
  "behavior": behavior,
824
- "modifiers": modifier[0],
847
+ "modifiers": modifier,
825
848
  "duration": cfg.UNPAIRED,
826
849
  "duration_mean": cfg.UNPAIRED,
827
850
  "duration_stdev": cfg.UNPAIRED,
@@ -882,7 +905,7 @@ def time_budget_analysis(
882
905
  {
883
906
  "subject": subject,
884
907
  "behavior": behavior,
885
- "modifiers": modifier[0],
908
+ "modifiers": modifier,
886
909
  "duration": total_duration,
887
910
  "duration_mean": duration_mean,
888
911
  "duration_stdev": duration_stdev,
@@ -895,7 +918,7 @@ def time_budget_analysis(
895
918
  else: # no modifiers
896
919
  if cfg.POINT in project_functions.event_type(behavior, ethogram):
897
920
  cursor.execute(
898
- ("SELECT occurence,observation FROM events WHERE subject = ? AND code = ? ORDER BY observation, occurence"),
921
+ ("SELECT occurence, observation FROM events " "WHERE subject = ? AND code = ? ORDER BY observation, occurence"),
899
922
  (subject, behavior),
900
923
  )
901
924
 
@@ -908,21 +931,12 @@ def time_budget_analysis(
908
931
  new_rows.append([float("NaN"), observation])
909
932
  else:
910
933
  new_rows.append([occurence, observation])
911
- """
912
- if occurence is not None:
913
- new_occurence = max(float(parameters["start time"]), occurence)
914
- new_occurence = min(new_occurence, float(parameters["end time"]))
915
- else:
916
- new_occurence = float("NaN")
917
- new_rows.append([new_occurence, observation])
918
- """
919
-
920
934
  rows = list(new_rows)
921
935
 
922
936
  # include behaviors without events
923
937
  if len(rows) == 0:
924
938
  if not parameters[cfg.EXCLUDE_BEHAVIORS]:
925
- out.append(
939
+ out_cat.append(
926
940
  {
927
941
  "subject": subject,
928
942
  "behavior": behavior,
@@ -982,7 +996,7 @@ def time_budget_analysis(
982
996
  duration = cfg.NA
983
997
  else:
984
998
  duration = 0.000
985
- out.append(
999
+ out_cat.append(
986
1000
  {
987
1001
  "subject": subject,
988
1002
  "behavior": behavior,
@@ -998,7 +1012,7 @@ def time_budget_analysis(
998
1012
  continue
999
1013
 
1000
1014
  if len(rows) % 2: # unpaired events
1001
- out.append(
1015
+ out_cat.append(
1002
1016
  {
1003
1017
  "subject": subject,
1004
1018
  "behavior": behavior,
@@ -390,6 +390,7 @@ def time_budget(self, mode: str, mode2: str = "list"):
390
390
  Args:
391
391
  mode (str): ["by_behavior", "by_category"]
392
392
  mode2 (str): must be in ["list", "current"]
393
+ "current" time budget of current observation
393
394
  """
394
395
 
395
396
  if mode2 == "current":
@@ -436,6 +437,7 @@ def time_budget(self, mode: str, mode2: str = "list"):
436
437
  maxTime=max_media_duration_all_obs,
437
438
  by_category=(mode == "by_category"),
438
439
  n_observations=len(selected_observations),
440
+ show_exclude_non_coded_modifiers=True,
439
441
  )
440
442
  if parameters == {}:
441
443
  return
@@ -474,14 +476,6 @@ def time_budget(self, mode: str, mode2: str = "list"):
474
476
  time_interval=cfg.TIME_FULL_OBS,
475
477
  )
476
478
 
477
- """
478
- cursor.execute("SELECT code, occurence, type FROM events ")
479
- print()
480
- for row in cursor.fetchall():
481
- print(row["code"], row["occurence"], row["type"])
482
- print()
483
- """
484
-
485
479
  total_observation_time = 0
486
480
  for obsId in selected_observations:
487
481
  obs_length = observation_operations.observation_total_length(self.pj[cfg.OBSERVATIONS][obsId])
@@ -588,14 +582,6 @@ def time_budget(self, mode: str, mode2: str = "list"):
588
582
  except Exception:
589
583
  pass
590
584
 
591
- """
592
- cursor.execute("SELECT code, occurence, type FROM events WHERE observation = ?", (obsId,))
593
- print()
594
- for row in cursor.fetchall():
595
- print(row["code"], row["occurence"], row["type"])
596
- print()
597
- """
598
-
599
585
  out, categories = time_budget_functions.time_budget_analysis(
600
586
  self.pj[cfg.ETHOGRAM], cursor, selected_observations, parameters, by_category=(mode == "by_category")
601
587
  )
boris/transitions.py CHANGED
@@ -181,8 +181,8 @@ def transitions_matrix(self, mode):
181
181
  parameters = select_subj_behav.choose_obs_subj_behav_category(
182
182
  self,
183
183
  selected_observations,
184
- flagShowIncludeModifiers=True,
185
- flagShowExcludeBehaviorsWoEvents=False,
184
+ show_include_modifiers=True,
185
+ show_exclude_non_coded_behaviors=False,
186
186
  n_observations=len(selected_observations),
187
187
  )
188
188
 
boris/utilities.py CHANGED
@@ -1273,6 +1273,11 @@ def ffprobe_media_analysis(ffmpeg_bin: str, file_name: str) -> dict:
1273
1273
  fps = eval(stream["r_frame_rate"])
1274
1274
  except Exception:
1275
1275
  fps = 0
1276
+ if fps >= 1000 and "avg_frame_rate" in stream: # case for some h265 video ("r_frame_rate": "1200000/1")
1277
+ try:
1278
+ fps = eval(stream["avg_frame_rate"])
1279
+ except Exception:
1280
+ pass
1276
1281
 
1277
1282
  if "duration" in stream:
1278
1283
  duration = float(stream["duration"])
@@ -1339,7 +1344,6 @@ def ffprobe_media_analysis(ffmpeg_bin: str, file_name: str) -> dict:
1339
1344
  }
1340
1345
 
1341
1346
  except Exception as e:
1342
- raise
1343
1347
  return {"error": str(e)}
1344
1348
 
1345
1349
 
@@ -1359,6 +1363,8 @@ def accurate_media_analysis(ffmpeg_bin: str, file_name: str) -> dict:
1359
1363
 
1360
1364
  ffprobe_results = ffprobe_media_analysis(ffmpeg_bin, file_name)
1361
1365
 
1366
+ print(f"{ffprobe_results=}")
1367
+
1362
1368
  logging.debug(f"file_name: {file_name}")
1363
1369
  logging.debug(f"ffprobe_results: {ffprobe_results}")
1364
1370
 
boris/version.py CHANGED
@@ -20,5 +20,5 @@ This file is part of BORIS.
20
20
 
21
21
  """
22
22
 
23
- __version__ = "8.27.8"
24
- __version_date__ = "2024-08-26"
23
+ __version__ = "8.27.9"
24
+ __version_date__ = "2024-10-07"