From 8467b9806f2fa17516e2c3132ae778f8ed99195b Mon Sep 17 00:00:00 2001 From: Philip Lee Date: Wed, 8 Apr 2020 21:38:59 +0100 Subject: [PATCH] Fix issue with single segment trend lines --- mobius/csv.py | 2 +- tests/__init__.py | 0 tests/test_csv.py | 23 +++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_csv.py diff --git a/mobius/csv.py b/mobius/csv.py index 3ed20bc..7e11889 100644 --- a/mobius/csv.py +++ b/mobius/csv.py @@ -99,7 +99,7 @@ def categorise_paths(paths, name, date_lookup): single_segment_lines.sort(key=lambda p: p.length()) short_trends = single_segment_lines[:-5] - single_segment_lines = single_segment_lines[:5] + single_segment_lines = single_segment_lines[-5:] y_lines = sorted([path.start.imag for path in single_segment_lines]) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_csv.py b/tests/test_csv.py new file mode 100644 index 0000000..06813e8 --- /dev/null +++ b/tests/test_csv.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from svgpathtools.path import Path, Line + +import mobius + + +def test_single_segment_lines(): + # Given + paths = [ + (Path(Line(start=(24058.2+8686.78j), end=(24534.52+8686.78j))), None), # horizontal line - bottom + (Path(Line(start=(24058.2+8627.24j), end=(24534.52+8627.24j))), None), # horizontal line + (Path(Line(start=(24058.2+8567.7j), end=(24534.52+8567.7j))), None), # horizontal line - baseline + (Path(Line(start=(24058.2+8508.16j), end=(24534.52+8508.16j))), None), # horizontal line + (Path(Line(start=(24058.2+8448.62j), end=(24534.52+8448.62j))), None), # horizontal line - top + (Path(Line(start=(24523.2+8664.45j), end=(24534.54+8663.114000000001j))), None)] # Trend line + + date_lookup = mobius.io.read_dates_lookup(filepath="../config/dates_lookup.csv") + + # When + df = mobius.csv.csv_process(paths, 1, date_lookup, output_folder=None, plots=False, save=None) + + # Then + assert round(df.at[42, "value"]) == -64