Skip to content

Commit 1d76480

Browse files
author
Cameron Waterman
authored
docs: Add examples and update getting started (#40)
* docs: Add examples and update getting started
1 parent eca4461 commit 1d76480

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

docs/getting_started.rst

+36
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,39 @@ Subscribe to tag changes
7575
.. literalinclude:: ../examples/tag/subscribe_to_tag_changes.py
7676
:language: python
7777
:linenos:
78+
79+
Data Frame API
80+
-------
81+
82+
Overview
83+
~~~~~~~~
84+
85+
The :class:`.DataFrameClient` class is the primary entry point of the Data Frame API.
86+
87+
When constructing a :class:`.DataFrameClient`, you can pass an
88+
:class:`.HttpConfiguration` (like one retrieved from the
89+
:class:`.HttpConfigurationManager`), or let :class:`.DataFrameClient` use the
90+
default connection. The default connection depends on your environment.
91+
92+
With a :class:`.DataFrameClient` object, you can:
93+
94+
* Create and delete Data Frame Tables.
95+
96+
* Modify table metadata and query for tables by their metadata.
97+
98+
* Append rows of data to a table, query for rows of data from a table, and decimate table data.
99+
100+
Examples
101+
~~~~~~~~
102+
103+
Create and write data to a table
104+
105+
.. literalinclude:: ../examples/dataframe/create_write_data.py
106+
:language: python
107+
:linenos:
108+
109+
Query and read data from a table
110+
111+
.. literalinclude:: ../examples/dataframe/query_read_data.py
112+
:language: python
113+
:linenos:
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import random
2+
from datetime import datetime
3+
4+
from nisystemlink.clients.dataframe import DataFrameClient
5+
from nisystemlink.clients.dataframe.models import (
6+
AppendTableDataRequest,
7+
Column,
8+
ColumnType,
9+
CreateTableRequest,
10+
DataFrame,
11+
DataType,
12+
)
13+
14+
client = DataFrameClient()
15+
16+
# Create table
17+
table_id = client.create_table(
18+
CreateTableRequest(
19+
name="Example Table",
20+
columns=[
21+
Column(name="index", dataType=DataType.Int32, columnType=ColumnType.Index),
22+
Column(name="Float_Column", dataType=DataType.Float32),
23+
Column(name="Timestamp_Column", dataType=DataType.Timestamp),
24+
],
25+
)
26+
)
27+
28+
# Generate example data
29+
frame = DataFrame(
30+
data=[[i, random.random(), datetime.now().isoformat()] for i in range(100)]
31+
)
32+
33+
# Write example data to table
34+
client.append_table_data(
35+
table_id, data=AppendTableDataRequest(frame=frame, endOfData=True)
36+
)

examples/dataframe/query_read_data.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from nisystemlink.clients.dataframe import DataFrameClient
2+
from nisystemlink.clients.dataframe.models import (
3+
DecimationMethod,
4+
DecimationOptions,
5+
QueryDecimatedDataRequest,
6+
)
7+
8+
client = DataFrameClient()
9+
10+
# List a table
11+
response = client.list_tables(take=1)
12+
table = response.tables[0]
13+
14+
# Get table metadata by table id
15+
client.get_table_metadata(table.id)
16+
17+
# Query decimated table data
18+
request = QueryDecimatedDataRequest(
19+
decimation=DecimationOptions(
20+
x_column="index",
21+
y_columns=["col1"],
22+
intervals=1,
23+
method=DecimationMethod.MaxMin,
24+
)
25+
)
26+
client.query_decimated_data(table.id, request)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ doctest = "pytest --doctest-modules docs"
5454
check = "black --check nisystemlink examples tests"
5555
format = "black nisystemlink examples tests"
5656
lint = "flake8 nisystemlink examples tests"
57-
types = "mypy --config-file mypy.ini nisystemlink examples/tag tests"
57+
types = "mypy --config-file mypy.ini nisystemlink examples tests"
5858

5959
[tool.pytest.ini_options]
6060
addopts = "--strict-markers"

0 commit comments

Comments
 (0)