From 489dd2e987af4a9a94640eb1742349a0f05242c2 Mon Sep 17 00:00:00 2001 From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl> Date: Fri, 8 Dec 2017 17:39:09 +0100 Subject: [PATCH] first op --- firanka/series/__init__.py | 27 +++++++++++++++++++++++++++ firanka/series/exceptions.py | 15 +++++++++++++++ tests/series/__init__.py | 8 ++++++++ tests/series/series.py | 11 +++++++++++ 4 files changed, 61 insertions(+) create mode 100644 firanka/series/__init__.py create mode 100644 firanka/series/exceptions.py create mode 100644 tests/series/__init__.py create mode 100644 tests/series/series.py diff --git a/firanka/series/__init__.py b/firanka/series/__init__.py new file mode 100644 index 0000000..7ff0068 --- /dev/null +++ b/firanka/series/__init__.py @@ -0,0 +1,27 @@ +# coding=UTF-8 +from __future__ import print_function, absolute_import, division +import six +import logging + +logger = logging.getLogger(__name__) + + +class DataSeries(object): + """ + Finite mapping from x: REAL => object + """ + + def __init__(self, data=None): + self.data = data or [] + + def length(self): + """ + Return timespan + :return: float + """ + try: + return self.data[-1] - self.data[0] + except IndexError: + return 0.0 + + diff --git a/firanka/series/exceptions.py b/firanka/series/exceptions.py new file mode 100644 index 0000000..e0e7c53 --- /dev/null +++ b/firanka/series/exceptions.py @@ -0,0 +1,15 @@ +# coding=UTF-8 +from __future__ import print_function, absolute_import, division +import six +import logging + +logger = logging.getLogger(__name__) + + +class FirankaException(Exception): + pass + +class Empty(FirankaException): + """ + Series was empty + """ \ No newline at end of file diff --git a/tests/series/__init__.py b/tests/series/__init__.py new file mode 100644 index 0000000..1c762b1 --- /dev/null +++ b/tests/series/__init__.py @@ -0,0 +1,8 @@ +# coding=UTF-8 +from __future__ import print_function, absolute_import, division +import six +import logging + +logger = logging.getLogger(__name__) + + diff --git a/tests/series/series.py b/tests/series/series.py new file mode 100644 index 0000000..01f3fdf --- /dev/null +++ b/tests/series/series.py @@ -0,0 +1,11 @@ +# coding=UTF-8 +from __future__ import print_function, absolute_import, division +import six +import unittest +from firanka.series import DataSeries + +class TestSeries(unittest.TestCase): + def test_ds(self): + + ds = DataSeries() + self.assertAlmostEqual(ds.length(), 0.0) -- GitLab