Exemplo n.º 1
0
def test_add_lights_on_mark_correct():
    dest_label = "Lights On"
    with open(TEST_RES + "/realisticLogs/lights_on.txt", "r") as file:
        source = Log.from_file(file)
    with open(TEST_RES + "/realisticLogs/all.txt", "r") as file:
        middle = Log.from_file(file)
    with open(TEST_RES + "/realisticLogs/all.txt", "r") as file:
        destination = RawLog.from_file(file)

    frame_diff = 54001 + 54001 - 12331 + 54001
    # pylint: disable=bad-continuation
    time_diff = timedelta(minutes=30, seconds=0.03) + \
                timedelta(minutes=30, seconds=0.03) - \
                timedelta(minutes=6, seconds=51.03) + \
                timedelta(minutes=30, seconds=0.03)
    with open(TEST_RES + "/realisticLogs/all.txt", "r") as file:
        expected = RawLog.from_file(file)
    new_mark = Mark(-frame_diff, -time_diff, dest_label)
    expected.marks.append(new_mark.to_line_tab())

    actual = copy_mark_disjoint([source, middle, middle], "Lights On",
                                destination, dest_label)

    assert expected.marks == actual.marks
    assert "-" in expected.marks[-1]
Exemplo n.º 2
0
def test_get_section_missing_header():
    """Test handling of section headers that don't match what is expected.

    Test that a FileFormatError with the proper message is raised when there is
    a difference in the expected header and the header actually found.

    Returns: None

    """
    failed = False
    headers = [
        "------------------------------------------",
        "frame|time(min:sec)|command", "---"
    ]
    end = "------------------------------------------"
    exp = FileFormatError.from_lines(
        "tests/res/realisticLogs/all.txt",
        "------------------------------------------", "---")
    with open(TEST_RES + "/realisticLogs/all.txt", 'r') as file:
        try:
            RawLog.get_section(file, "RAW LOG", headers, end)
        except FileFormatError as error:
            assert str(error) == str(exp)
            failed = True
    assert failed
Exemplo n.º 3
0
def test_get_section_missing_start():
    """Test handling of section starts that aren't found.

    Test that a FileFormatError with the proper message is raised when the line
    thought to signal the start of the section is never found.

    Returns: None

    """
    failed = False
    with open(TEST_RES + "/realisticLogs/all.txt", 'r') as file:
        try:
            RawLog.get_section(file, "-----", [], "RAW LOG")
        except FileFormatError as error:
            assert str(error) == "The start line '-----' was not found in " \
                                 "tests/res/realisticLogs/all.txt"
            failed = True
    assert failed
Exemplo n.º 4
0
def test_from_rawlog():
    str_full = " 0  00:00.00  null  either "
    str_mark = "    1     0:00.03    video start"

    rawlog = RawLog()
    rawlog.full.append(str_full)
    rawlog.marks.append(str_mark)

    log = Log.from_raw_log(rawlog)

    assert log.full == [BehaviorFull(" 0  00:00.00  null  either ")]
    assert log.marks == [Mark.from_line("    1     0:00.03    video start")]
Exemplo n.º 5
0
def batch_mark_lights_on(path_to_log_dir: str) -> None:
    """Transfer ``LIGHTS ON`` marks en masse for all logs in a directory

    The logs are partitioned using :py:func:`same_fish_and_day` into groups of
    logs that pertain to the same fish on the same day. A ``LIGHTS ON`` behavior
    in one of the aggression logs is transferred to the full scoring log,
    accounting for the change in reference point for frame numbers and times.
    The ``LIGHTS ON`` behavior can instead be specified in a separate lights-on
    log (see :py:func:`is_lights_on`). This log should have the same name as the
    log in which the ``LIGHTS ON`` behavior would otherwise be (before being
    transferred), except its name (before the terminal extension like ``.txt``)
    should end in ``_LIGHTSON`` and the initials of the scorer may differ.

    Args:
        path_to_log_dir: Path to the directory of logs to process

    Returns:
        None
    """
    partitions = get_partitions(path_to_log_dir)
    for partition in partitions:
        scored, lightson = find_scored_lights(partition)

        if lightson:
            with open(lightson, 'r') as f:
                lightson_log = Log.from_file(f)

        log_names = [
            name for name in partition if name not in (scored, lightson)
        ]
        log_names = sorted(log_names, key=lambda x: int(get_last_name_elem(x)))

        logs = []
        for name in log_names:
            with open(name, 'r') as f:
                log = Log.from_file(f)
                if lightson and get_last_name_elem(name) == \
                        get_last_name_elem(lightson):
                    log.extend(lightson_log)
                logs.append(log)
        with open(scored, 'r') as f:
            scored_raw = RawLog.from_file(f)
            final = copy_lights_on(logs, scored_raw, read_aggr_behav_list())
        with open(scored, 'w') as f:
            lines = final.to_lines()
            for line in lines:
                f.write(line + "\n")
Exemplo n.º 6
0
def copy_mark(logs: List[Tuple[Log, timedelta, int]], src_pattern: str,
              dest: RawLog, dest_label: str) -> RawLog:
    """Copy a behavior into another log file as a mark, adjusting time and frame

    Time and frame are adjusted so as to be correct (potentially by being
    negative) in relation to the other entries in ``dest``. The logs are aligned
    in time using the provided start time and frame information.

    Args:
        logs: List of tuples containing log to search for ``src_pattern`` in and
            account for when adjusting time and frame, time at which the next
            video (``dest`` for last video) starts, and frame at which the next
            video (``dest`` for last video) starts
        src_pattern: Search pattern (regular expression) that identifies the
            behavior to copy
        dest: Log to insert mark into
        dest_label: Label for inserted mark

    Returns:
        A copy of ``dest``, but with the new mark inserted

    """
    found = False
    frames = 0
    time = timedelta(seconds=0)
    for tup in logs:
        tup[0].sort_lists()

    for log, s_time, s_frame in logs:
        if not found:
            for behav in log.full:
                if re.match(src_pattern, behav.description):
                    found = True

                    frames = s_frame - behav.frame
                    time = s_time - behav.time
        else:
            frames += s_frame
            time += s_time

    new_mark = Mark(-frames, -time, dest_label)
    new_log = RawLog.from_raw_log(dest)
    new_log.marks.append(new_mark.to_line_tab())
    return new_log
Exemplo n.º 7
0
def test_constructor_no_notes():
    """Test creating a RawLog object from a log with no notes

        Creates a RawLog object from a test log without notes(noNotes.txt) and then
        compares the resulting object's attributes to the contents of the files
        in expectedLogParts.

        Returns: None

        """
    with open(TEST_RES + "/realisticLogs/noNotes.txt", 'r') as log_all:
        log = RawLog.from_file(log_all)

    tests = [("header.txt", log.header), ("video_info.txt", log.video_info),
             ("comm.txt", log.commands), ("raw.txt", log.raw),
             ("full.txt", log.full), ("blank.txt", log.notes),
             ("marks.txt", log.marks)]

    for file, found in tests:
        with open(TEST_RES + "/expectedLogParts/" + file, 'r') as part_file:
            expected = [remove_trailing_newline(line) for line in part_file]
        assert found == expected
Exemplo n.º 8
0
def test_from_file():
    with open(TEST_RES + "/realisticLogs/all.txt") as f:
        auto = Log.from_file(f)
        manual = Log.from_raw_log(RawLog.from_file(f))
    assert auto.full == manual.full
    assert auto.marks == manual.marks