Skip to content

Commit

Permalink
docs: Add examples and update getting started (#40)
Browse files Browse the repository at this point in the history
* docs: Add examples and update getting started
  • Loading branch information
cameronwaterman committed Dec 14, 2022
1 parent eca4461 commit 1d76480
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
36 changes: 36 additions & 0 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,39 @@ Subscribe to tag changes
.. literalinclude:: ../examples/tag/subscribe_to_tag_changes.py
:language: python
:linenos:

Data Frame API
-------

Overview
~~~~~~~~

The :class:`.DataFrameClient` class is the primary entry point of the Data Frame API.

When constructing a :class:`.DataFrameClient`, you can pass an
:class:`.HttpConfiguration` (like one retrieved from the
:class:`.HttpConfigurationManager`), or let :class:`.DataFrameClient` use the
default connection. The default connection depends on your environment.

With a :class:`.DataFrameClient` object, you can:

* Create and delete Data Frame Tables.

* Modify table metadata and query for tables by their metadata.

* Append rows of data to a table, query for rows of data from a table, and decimate table data.

Examples
~~~~~~~~

Create and write data to a table

.. literalinclude:: ../examples/dataframe/create_write_data.py
:language: python
:linenos:

Query and read data from a table

.. literalinclude:: ../examples/dataframe/query_read_data.py
:language: python
:linenos:
36 changes: 36 additions & 0 deletions examples/dataframe/create_write_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import random
from datetime import datetime

from nisystemlink.clients.dataframe import DataFrameClient
from nisystemlink.clients.dataframe.models import (
AppendTableDataRequest,
Column,
ColumnType,
CreateTableRequest,
DataFrame,
DataType,
)

client = DataFrameClient()

# Create table
table_id = client.create_table(
CreateTableRequest(
name="Example Table",
columns=[
Column(name="index", dataType=DataType.Int32, columnType=ColumnType.Index),
Column(name="Float_Column", dataType=DataType.Float32),
Column(name="Timestamp_Column", dataType=DataType.Timestamp),
],
)
)

# Generate example data
frame = DataFrame(
data=[[i, random.random(), datetime.now().isoformat()] for i in range(100)]
)

# Write example data to table
client.append_table_data(
table_id, data=AppendTableDataRequest(frame=frame, endOfData=True)
)
26 changes: 26 additions & 0 deletions examples/dataframe/query_read_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from nisystemlink.clients.dataframe import DataFrameClient
from nisystemlink.clients.dataframe.models import (
DecimationMethod,
DecimationOptions,
QueryDecimatedDataRequest,
)

client = DataFrameClient()

# List a table
response = client.list_tables(take=1)
table = response.tables[0]

# Get table metadata by table id
client.get_table_metadata(table.id)

# Query decimated table data
request = QueryDecimatedDataRequest(
decimation=DecimationOptions(
x_column="index",
y_columns=["col1"],
intervals=1,
method=DecimationMethod.MaxMin,
)
)
client.query_decimated_data(table.id, request)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ doctest = "pytest --doctest-modules docs"
check = "black --check nisystemlink examples tests"
format = "black nisystemlink examples tests"
lint = "flake8 nisystemlink examples tests"
types = "mypy --config-file mypy.ini nisystemlink examples/tag tests"
types = "mypy --config-file mypy.ini nisystemlink examples tests"

[tool.pytest.ini_options]
addopts = "--strict-markers"
Expand Down

0 comments on commit 1d76480

Please sign in to comment.