Exemplo n.º 1
0
 def test_t8(self):
     pj_float = json.loads(open("files/test.boris").read())
     pj = utilities.convert_time_to_decimal(pj_float)
     r = utilities.get_current_states_modifiers_by_subject(
         state_behaviors_codes=["s"],
         events=pj["observations"]["observation #1"]["events"],
         subjects=pj["subjects_conf"],
         time=Decimal("8.0"),
         include_modifiers=False)
     assert r == {'0': [], '1': []}
Exemplo n.º 2
0
def events_to_timed_behavioral_sequences(pj: dict,
                                         obs_id: str,
                                         subject: str,
                                         parameters: dict,
                                         precision: float,
                                         behav_seq_separator: str) -> str:
    """
    return the behavioral string for subject in obsId

    Args:
        pj (dict): project
        obs_id (str): observation id
        subj (str): subject
        parameters (dict): parameters
        precision (float): time value for scan sample
        behav_seq_separator (str): separator of behviors in behavioral sequences

    Returns:
        str: behavioral string for selected subject in selected observation
    """

    out = ""
    current_states = []
    # events_with_status = project_functions.events_start_stop(pj[ETHOGRAM], pj[OBSERVATIONS][obs_id][EVENTS])

    state_behaviors_codes = utilities.state_behavior_codes(pj[ETHOGRAM])
    delta = Decimal(str(round(precision, 3)))
    out = ""
    t = Decimal("0.000")

    current = []
    while t < pj[OBSERVATIONS][obs_id][EVENTS][-1][0]:
        '''
        if out:
            out += behav_seq_separator
        '''
        csbs = utilities.get_current_states_modifiers_by_subject(state_behaviors_codes,
                                                                 pj[OBSERVATIONS][obs_id][EVENTS],
                                                                 {"": {"name": subject}},
                                                                 t,
                                                                 include_modifiers=False)[""]
        if csbs:
            if current:
                if csbs == current[-1]:
                    current.append("+".join(csbs))
                else:
                    out.append(current)
                    current = [csbs]
            else:
                current = [csbs]

        t += delta

    return out
Exemplo n.º 3
0
 def test_events_with_modifiers_required(self):
     pj_float = json.loads(open("files/test.boris").read())
     pj = utilities.convert_time_to_decimal(pj_float)
     r = utilities.get_current_states_modifiers_by_subject(
         state_behaviors_codes=["r", "s"],
         events=pj["observations"]["modifiers"]["events"],
         subjects={
             "0": {
                 "key": "",
                 "name": "",
                 "description": "no focal subject"
             }
         },
         time=Decimal("20"),
         include_modifiers=True)
     #print(r)
     assert r == {'0': ['r (m1)']}