Commit 5c8f573c authored by julian.gethmann's avatar julian.gethmann

Fix documentation and docstring in Cassandra

Docstring was out of date and needed to be fixed.
This fixes issue #7
parent 75252971
......@@ -108,6 +108,13 @@ flake8 and tox, etc. are all installed by installing the `test-requirements.txt`
Change things marked by the `pre-commit`_-hooks if there are some.
If you wrote doctests you should also run the test directly and not just via tox or `python setup.py test`, because the mechanism to run the doctests is not seen by `pytest`.
So please also run::
$ python tests/test_your_doctest_test.py
And be aware that you have to be in the IBPT-LAN to run the tests.
.. _`pre-commit`: http://pre-commit.com/
6. Check for upstream updates::
......
......@@ -16,7 +16,12 @@ import json
from collections import namedtuple
from os import path
from sys import version_info
from typing import Dict, List, Optional, Tuple, Union # flake8: noqa
from typing import Dict # flake8: noqa; flake8: noqa
from typing import List # flake8: noqa
from typing import NamedTuple # flake8: noqa
from typing import Optional # flake8: noqa
from typing import Tuple # flake8: noqa
from typing import Union # flake8: noqa
from cassandra import __version__
......@@ -229,31 +234,33 @@ class CassandraHelper(object):
return ret
@staticmethod
def cassandra_json_to_timeseries(json_data):
# type: (List[Optional[Dict[str, Union[int, Dict[str, str]]]]]) -> Tuple[List[datetime.datetime], List[Union[List[float], float]]]
def cassandra_json_to_timeseries(
json_data, # type: List[Optional[Dict[str, Union[int, Dict[str, str]]]]]
):
# type: (...) -> NamedTuple("dataset", [List[datetime.datetime], List[Union[List[float], float]]])
"""Return lists of timestamps and values for given Cassandra's JSON data.
Args:
json_data (list): JSON list with Cassandra entries.
Returns:
tuple:
The tuple consists of a list of datetime objects and
namedtuple:
The namedtuple `dataset` consists of a list of datetime objects called `timestamps` and
a list of the corresponding values either as floats or
wrapped inside a list if there are more than one value
to be returned.
to be returned. The latter list is called `values`.
Examples:
>>> CassandraHelper().cassandra_json_to_timeseries([])
([], [])
dataset(timestamps=[], values=[])
>>> CassandraHelper().cassandra_json_to_timeseries([{"value": [1.3e-07],
... "time": 1454698800000000000,
... "severity": {"level": "OK"}}])
([datetime.datetime(2016, 2, 5, 20, 0)], [1.3e-07])
dataset(timestamps=[datetime.datetime(2016, 2, 5, 20, 0)], values=[1.3e-07])
>>> CassandraHelper().cassandra_json_to_timeseries([{"value": [1.3e-07, 1.4e-07],
... "time": 1454698800000000000,
... "severity": {"level": "OK"}}])
([datetime.datetime(2016, 2, 5, 20, 0)], [[1.3e-07, 1.4e-07]])
dataset(timestamps=[datetime.datetime(2016, 2, 5, 20, 0)], values=[[1.3e-07, 1.4e-07]])
.. note:: This function doesn't check for sanity of the data, yet.
.. warning:: Returned values may be empty ones!
......@@ -304,7 +311,7 @@ class Cassandra(object):
... Pvs.pv["clic_field"], 1) as cas:
... clic_field = cas
>>> clic_field
([datetime.datetime(2016, 4, 13, 10, 59, 59, 250177), datetime.datetime(2016, 4, 13, 11, 0, 0, 250285), datetime.datetime(2016, 4, 13, 11, 0, 1, 250484)], [0.9991628617721655, 0.9992209719948126, 0.9991912895254449])
dataset(timestamps=[datetime.datetime(2016, 4, 13, 10, 59, 59, 250177), datetime.datetime(2016, 4, 13, 11, 0, 0, 250285), datetime.datetime(2016, 4, 13, 11, 0, 1, 250484)], values=[0.9991628617721655, 0.9992209719948126, 0.9991912895254449])
"""
HOSTNAME = "ankasr-archiver.anka.kit.edu"
PORT = 9812
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment