Skip to main content

Hybrid SPARQL query engine for timeseries data

Project description

chrontext: High-performance hybrid query engine for knowledge graphs and time-series

Chrontext allows you to use your knowledge graph to access time-series data. It uses a commodity SPARQL Triplestore and your existing infrastructure for time-series. It currently supports time-series stored in Google Cloud BigQuery (SQL) and OPC UA HA, but can easily be extended to other APIs and databases. Chrontext Architecture

Chrontext forms a semantic layer that allows self-service data access, abstracting away technical infrastructure. Users can create query-based inputs for data products, that maintains these data products as the knowledge graph is maintained, and that can be deployed across heterogeneous on-premise and cloud infrastructures with the same API.

Chrontext is a high-performance Python library built in Rust using Polars, and relies heavily on packages from the Oxigraph project. Chrontext works with Apache Arrow, prefers time-series transport using Apache Arrow Flight and delivers results as Polars DataFrames.

Please reach out to Data Treehouse if you would like help trying Chrontext, or require support for a different time-series backend.

Installing

Chrontext is in pip, just use:

pip install chrontext

The API is documented HERE.

Queries in python

We can make queries in Python. The code assumes that we have a SPARQL-endpoint and BigQuery set up with time-series.

from chrontext import *
import os
SCHEMA = os.getenv("SCHEMA")
BIGQUERY_CONN = os.getenv("BIGQUERY_CONN")

tables = [
    TimeseriesTable(
        resource_name="nist",
        schema=SCHEMA,
        time_series_table="nist2",
        value_column="VALUE",
        timestamp_column="TIMESTAMP",
        identifier_column="external_id",
    ),
]
bq_db = TimeseriesBigQueryDatabase(key=os.getenv("BIGQUERY_CONN"), tables=tables)
engine = Engine(timeseries_bigquery_db=bq_db, sparql_endpoint=SPARQL)
engine.init()

df = engine.query("""
    PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>
    PREFIX ct:<https://github.com/DataTreehouse/chrontext#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX rds: <https://github.com/DataTreehouse/solar_demo/rds_power#> 
    SELECT ?inv_path WHERE {
        # We are navigating th Solar PV site "Metropolis", identifying every inverter. 
        ?site a rds:Site .
        ?site rdfs:label "Metropolis" .
        ?site rds:functionalAspect+ ?inv .    
        ?inv a rds:TBB .                    # RDS code TBB: Inverter
        ?inv rds:path ?inv_path .
        
        # Find the timeseries associated with the inverter
        ?inv ct:hasTimeseries ?ts_pow .
        ?ts_pow rdfs:label "InvPDC_kW" .    
        DT {
            timestamp = ?t,
            timeseries = ?ts_pow, 
            interval = "10m",
            from = "2018-12-25T00:00:00Z",
            aggregation = "avg" }
        }
    ORDER BY ?inv_path ?t
""")

This produces the following DataFrame:

inv_path t ts_pow_value_avg
str datetime[ns] f64
=<Metropolis>.A1.RG1.TBB1 2018-12-25 00:00:00 0.0
=<Metropolis>.A5.RG9.TBB1 2019-01-01 04:50:00 0.0

Not much power being produced at night in the middle of winter :-)

API

The API is documented HERE.

References

Chrontext is joint work by Magnus Bakken and Professor Ahmet Soylu at OsloMet. To read more about Chrontext, read the article Chrontext: Portable Sparql Queries Over Contextualised Time Series Data in Industrial Settings.

License

All code produced since August 1st. 2023 is copyrighted to Data Treehouse AS with an Apache 2.0 license unless otherwise noted.

All code which was produced before August 1st. 2023 copyrighted to Prediktor AS with an Apache 2.0 license unless otherwise noted, and has been financed by The Research Council of Norway (grant no. 316656) and Prediktor AS as part of a PhD Degree. The code at this state is archived in the repository at https://github.com/DataTreehouse/chrontext.

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

chrontext-0.8.17.tar.gz (8.4 MB view hashes)

Uploaded Source

Built Distributions

chrontext-0.8.17-cp311-none-win_amd64.whl (23.5 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

chrontext-0.8.17-cp311-cp311-manylinux_2_28_x86_64.whl (29.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

chrontext-0.8.17-cp311-cp311-macosx_12_0_arm64.whl (20.7 MB view hashes)

Uploaded CPython 3.11 macOS 12.0+ ARM64

chrontext-0.8.17-cp311-cp311-macosx_11_0_arm64.whl (20.7 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

chrontext-0.8.17-cp310-none-win_amd64.whl (23.5 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

chrontext-0.8.17-cp310-cp310-manylinux_2_28_x86_64.whl (29.7 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

chrontext-0.8.17-cp310-cp310-macosx_12_0_arm64.whl (20.7 MB view hashes)

Uploaded CPython 3.10 macOS 12.0+ ARM64

chrontext-0.8.17-cp310-cp310-macosx_11_0_arm64.whl (20.7 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

chrontext-0.8.17-cp39-none-win_amd64.whl (23.5 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

chrontext-0.8.17-cp39-cp39-manylinux_2_28_x86_64.whl (29.7 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

chrontext-0.8.17-cp39-cp39-macosx_12_0_arm64.whl (20.7 MB view hashes)

Uploaded CPython 3.9 macOS 12.0+ ARM64

chrontext-0.8.17-cp39-cp39-macosx_11_0_arm64.whl (20.7 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

chrontext-0.8.17-cp38-none-win_amd64.whl (23.5 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

chrontext-0.8.17-cp38-cp38-manylinux_2_28_x86_64.whl (29.7 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.28+ x86-64

chrontext-0.8.17-cp38-cp38-macosx_12_0_arm64.whl (20.7 MB view hashes)

Uploaded CPython 3.8 macOS 12.0+ ARM64

chrontext-0.8.17-cp38-cp38-macosx_11_0_arm64.whl (20.7 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

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