Skip to main content

JSON-TimeSeries (JTS specification) handling library

Project description

JSON Time Series

Documentation Status PyPI version

JSON Time Series (JTS specification) handling Python library - Time Series data construction, manipulation and serialisation.

Installation

pip install json-timeseries

Import or require module

from json_timeseries import TsRecord, TimeSeries, JtsDocument

Usage

from json_timeseries import TsRecord, TimeSeries, JtsDocument
from datetime import datetime

# Create Time Series
timeseries1 = TimeSeries(identifier='series_1', name='Series 1', data_type='NUMBER', 
    records=[
    TsRecord(**{"timestamp": datetime.now(), "value": '1.23', "quality": 192, "annotation": 'comment'}),
    TsRecord(**{"timestamp": datetime.now(), "value": '2.34', "quality": 245, "annotation": 'comment number 2'})])

timeseries2 = TimeSeries(identifier='series_2', name='Series 2', data_type='NUMBER', units="C", 
                         records=TsRecord(timestamp=datetime.now(), value=1.11, quality=111, annotation="comment ts2 111")
                         )

# Add record(s)
timeseries1.insert(TsRecord(**{ timestamp: datetime.now(), value: 30 }))

# Output in JSON Time Series document format
jts_doc = JtsDocument([timeseries1, timeseries2])
json_str = jts_doc.toJSONString()

TimeSeries

TimeSeries is a class for constructing and manipulating a single dataset.

from json_timeseries import TsRecord, TimeSeries
from datetime import datetime

time_series = TimeSeries(identifier='series_2', name='Series 2', data_type='NUMBER', units="m/s", 
                         records=TsRecord(timestamp=datetime.now(), value=1.11, quality=0, annotation="example comment")
                         )

Options

Optionally provide configuration used for certain output formats such as JTS Document.

  • data_type: data type of record value attribute. NUMBER | TEXT | TIME | COORDINATES
  • id: string or number to uniquely identify the series to use instead of the automatically assigned id.
  • name: string
  • units: string
  • records: list of data records

Alternatively set later:

time_series.data_type = 'NUMBER'
time_series.id = 'Series_1'
time_series.name = 'My Series'
time_series.units = 'm/s'

TsRecord

TsRecord is a class for constructing and manipulating a single record.

from json_timeseries import TsRecord
from datetime import datetime

ts_record1 = TsRecord(timestamp=datetime.now(), value=1.11, quality=0, annotation="example comment")
# Or as dict of parameters using ** operator
ts_record2 = TsRecord(**{"timestamp": datetime.now(), "value": 1.11, "quality": 0, "annotation": 'example comment'})

Record attributes

Records require a timestamp and at least one attribute: value, quality or annotation

  • timestamp: date object. Type of datetime. e.g.datetime.now()
  • value (optional): number, string, date, null
  • quality (optional): number (quality code) associated with value
  • annotation (optional): string description or comment related to the record

Methods

See full documentation.

Properties

See full documentation.

JTS Document

JtsDocument is a class for outputting TimeSeries in JSON Time Series document format.

# Create a JTS Document from one or more timeseries
jts_document = JtsDocument(series=[timeseries1, timeseries2])
# Output series in JTS Document format
json_str = jts_document.toJSONString()

Options

  • series: array of TimeSeries to include in JTS Document

Methods

See full documentation.

Properties

See full documentation.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_timeseries-0.1.6.tar.gz (13.7 kB view hashes)

Uploaded Source

Built Distribution

json_timeseries-0.1.6-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page