Пример #1
0
def test_check_chunksize_positive():
    invalid_meta = source.MetaData(
        chunk_size=-12,
        recurrence_size=10,
        recurrence_distance=1,
        consistency_sample_size=10,
    )
    assert error_handling.check_chunksize_positive(
        meta=invalid_meta
    ) == either.Left(error_handling.ErrorCode.CHUNKSIZE_NONPOSITIVE)

    valid_meta = source.MetaData(
        chunk_size=0,
        recurrence_size=10,
        recurrence_distance=1,
        consistency_sample_size=10,
    )
    assert error_handling.check_chunksize_positive(
        meta=valid_meta
    ) == either.Right(valid_meta)

    valid_meta = source.MetaData(
        chunk_size=12,
        recurrence_size=10,
        recurrence_distance=1,
        consistency_sample_size=10,
    )
    assert error_handling.check_chunksize_positive(
        meta=valid_meta
    ) == either.Right(valid_meta)
Пример #2
0
def test_check_recurrence_size_nonnegative():
    invalid_meta = source.MetaData(
        chunk_size=12,
        recurrence_size=-10,
        recurrence_distance=1,
        consistency_sample_size=10,
    )
    assert error_handling.check_recurrence_size_nonnegative(
        meta=invalid_meta
    ) == either.Left(error_handling.ErrorCode.RECURRENCESIZE_NEGATIVE)

    valid_meta = source.MetaData(
        chunk_size=12,
        recurrence_size=10,
        recurrence_distance=1,
        consistency_sample_size=10,
    )
    assert error_handling.check_recurrence_size_nonnegative(
        meta=valid_meta
    ) == either.Right(valid_meta)

    valid_meta = source.MetaData(
        chunk_size=12,
        recurrence_size=0,
        recurrence_distance=1,
        consistency_sample_size=10,
    )
    assert error_handling.check_recurrence_size_nonnegative(
        meta=valid_meta
    ) == either.Right(valid_meta)
Пример #3
0
def test_processes_example_file_correct(tmpdir):
    meta = source.MetaData(
        chunk_size=6,
        recurrence_size=2,
        recurrence_distance=3,
        consistency_sample_size=10,
    )
    output_filename = pathlib.Path(tmpdir) / "output.tdms"

    fix.export_correct_data(
        tdms_path="tests/assets/example_file.tdms",
        meta=meta,
        export_path=output_filename,
    )
    tdms_operator = nptdms.TdmsFile(output_filename)
    df_result = tdms_operator.as_dataframe()
    assert len(df_result) == 15
    assert np.array_equal(
        df_result.columns.values,
        np.array([
            "/'Untitled'/'D'",
            "/'Untitled'/'C'",
            "/'Untitled'/'B'",
            "/'Untitled'/'A'",
        ]),
    )
    assert np.array_equal(df_result["/'Untitled'/'A'"].values,
                          np.arange(1, 16))
Пример #4
0
def main(
    recurrence_size: int,
    recurrence_distance: int,
    chunk_size: int,
    consistency_sample_size: int,
    output_file: str,
    filename: str,
):
    meta = source.MetaData(
        recurrence_distance=recurrence_distance,
        recurrence_size=recurrence_size,
        chunk_size=chunk_size,
        consistency_sample_size=consistency_sample_size,
    )

    tdms_path = pathlib.Path(filename)

    if output_file == "":
        name = tdms_path.with_suffix("").name + "_corrected.tdms"
        export_path = tdms_path.parent.joinpath(name)
    else:
        export_path = pathlib.Path(output_file)

    fix.export_correct_data(tdms_path=tdms_path,
                            meta=meta,
                            export_path=export_path)

    CLI_CONFIG.update_config(
        recurrence_distance=recurrence_distance,
        recurrence_size=recurrence_size,
        chunk_size=chunk_size,
        consistency_sample_size=consistency_sample_size,
    )
    CLI_CONFIG.to_yaml(PATH_TO_CONFIG)
Пример #5
0
def main(
    recurrence_size: int,
    recurrence_distance: int,
    chunk_size: int,
    consistency_sample_size: int,
    output_file: str,
    filename: str,
    segment_size: int,
):
    meta = source.MetaData(
        recurrence_distance=recurrence_distance,
        recurrence_size=recurrence_size,
        chunk_size=chunk_size,
        consistency_sample_size=consistency_sample_size,
        segment_size=segment_size,
    )

    fix.export_correct_data(filename=filename,
                            meta=meta,
                            output_file=output_file)

    CLI_CONFIG.update_config(
        recurrence_distance=recurrence_distance,
        recurrence_size=recurrence_size,
        chunk_size=chunk_size,
        consistency_sample_size=consistency_sample_size,
        segment_size=segment_size,
    )
    CLI_CONFIG.to_yaml(PATH_TO_CONFIG)
Пример #6
0
def test_check_recurrence_size_smaller_chunk_size():
    invalid_meta = source.MetaData(
        chunk_size=10,
        recurrence_size=12,
        recurrence_distance=1,
        consistency_sample_size=10,
    )
    assert error_handling.check_recurrence_size_smaller_chunk_size(
        meta=invalid_meta
    ) == either.Left(error_handling.ErrorCode.RECURRENCESIZE_GREATER_CHUNKSIZE)

    valid_meta = source.MetaData(
        chunk_size=12,
        recurrence_size=10,
        recurrence_distance=1,
        consistency_sample_size=10,
    )
    assert error_handling.check_recurrence_size_smaller_chunk_size(
        meta=valid_meta
    ) == either.Right(valid_meta)
Пример #7
0
def test_correct_array_size_works_for_example(tmpdir):
    meta = source.MetaData(
        chunk_size=6,
        recurrence_size=3,  # <- 2 would be correct
        recurrence_distance=3,
        consistency_sample_size=10,
    )
    example_source = source.SourceFile.read_from_path(
        tdms_path="tests/assets/example_file.tdms",
        meta=meta,
    )
    res = tdms_helpers.get_maximum_array_size(example_source.tdms_operator)
    assert res == 19
Пример #8
0
def test_prechecks_recognize_wrong_parameters(tmpdir):
    meta = source.MetaData(
        chunk_size=6,
        recurrence_size=3,  # <- 2 would be correct
        recurrence_distance=3,
        consistency_sample_size=10,
    )
    output_filename = pathlib.Path(tmpdir) / "output.tdms"
    with pytest.raises(Exception):
        fix.export_correct_data(
            tdms_path="tests/assets/example_file.tdms",
            meta=meta,
            export_path=output_filename,
        )
Пример #9
0
def tests_fails_for_nonexistent_filepath():
    meta = source.MetaData(
        chunk_size=6,
        recurrence_size=2,
        recurrence_distance=3,
        consistency_sample_size=10,
    )
    output_filename = pathlib.Path("NonexistentPath/tdms_file.tdms")

    with pytest.raises(Exception):
        fix.export_correct_data(
            tdms_path="tests/assets/example_file.tdms",
            meta=meta,
            export_path=output_filename,
        )
Пример #10
0
def test_fails_wrong_file(tmpdir):
    meta = source.MetaData(
        chunk_size=6,
        recurrence_size=2,
        recurrence_distance=3,
        consistency_sample_size=10,
    )

    output_filename = pathlib.Path(tmpdir) / "output"
    with pytest.raises(Exception):
        fix.export_correct_data(
            file_name="tests/assets/example_file.txt",
            meta=meta,
            output_file=output_filename,
        )