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.7.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

json_timeseries-0.1.7-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file json_timeseries-0.1.7.tar.gz.

File metadata

  • Download URL: json_timeseries-0.1.7.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for json_timeseries-0.1.7.tar.gz
Algorithm Hash digest
SHA256 12addeb14d8a374fcef7ab05698b9cc43880e707c29bc83103d80414e29b602c
MD5 0454a680bbf5693da91da23db37d83c0
BLAKE2b-256 d35405a8c8bf9bc8303a19dbec4a28f833bc47c7424832243b5e9f051bc02bb0

See more details on using hashes here.

File details

Details for the file json_timeseries-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for json_timeseries-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6af2d7a31dfef4fa8e8417689003f6a32a5b5a4f0998cbc55d21eea6e0ce5e55
MD5 2b22c7a0dc5b2efde49029c83275df37
BLAKE2b-256 62a408f3c790a722e76bd70cd6cefa07919de6c627b0794d417f648abcb29677

See more details on using hashes here.

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