Skip to content

Commit

Permalink
Merge branch 'main' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
pjdotson committed Sep 11, 2024
2 parents f6fe623 + bc31be1 commit 6aa75d7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
69 changes: 69 additions & 0 deletions client/py/examples/calculated_channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2024 Synnax Labs, Inc.
#
# Use of this software is governed by the Business Source License included in the file
# licenses/BSL.txt.
#
# As of the Change Date specified in that file, in accordance with the Business Source
# License, use of this software will be governed by the Apache License, Version 2.0,
# included in the file licenses/APL.txt.

import synnax as sy

"""
This example demonstrates how to calculate derived values from a set of channels and
write them to a new set of channels in Synnax in a streaming fashion. These channels,
typically referred to as "calculated" or "derived" channels, are useful for storing
values that are calculated from other channels.
For this example to run, you'll need to run the "stream_write.py" file also contained
in this directory BEFORE you run this script.
"""

# We've logged in via the CLI, so there's no need to provide credentials here.
# See https://docs.synnaxlabs.com/reference/python-client/get-started for more information.
client = sy.Synnax()

# We create a separate index channel to store the timestamps for the calculated values.
# These will store the same timestamps as the raw time channel, but will be used to
# index the calculated values.
derived_time_ch = client.channels.create(
name="derived_time",
is_index=True,
)

# We'll store the squared value of "stream_write_example_data_1" in this channel.
squared_example_data_1 = client.channels.create(
name="squared_example_data_1",
index=derived_time_ch.key,
data_type=sy.DataType.FLOAT32,
)

# We'll store the average of "stream_write_example_data_1" and "stream_write_example_data_2"
# in this channel.
average_example_data_1 = client.channels.create(
name="average_example_data_1",
index=derived_time_ch.key,
data_type=sy.DataType.FLOAT32,
)

with client.open_writer(
start=sy.TimeStamp.now(),
channels=["derived_time", "squared_example_data_1", "average_example_data_1"],
enable_auto_commit=True
) as writer:
with client.open_streamer(
["stream_write_example_time", "stream_write_example_data_1", "stream_write_example_data_2"],
) as s:
for fr in s:
time = fr["stream_write_example_time"]
# Square
squared = fr["stream_write_example_data_1"] ** 2
# Average
avg = (fr["stream_write_example_data_1"] + fr["stream_write_example_data_2"]) / 2
writer.write({
# Write back the same timestamps as the raw data, so they align
# correctly.
"derived_time": time,
"squared_example_data_1": squared,
"average_example_data_1": avg,
})
15 changes: 15 additions & 0 deletions docs/site/src/pages/reference/cluster/cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ synnax start -l localhost:9090 -p localhost:9091,localhost:9092
option: "--slow-consumer-timeout",
default: "2.5s",
description: "The duration after which a telemetry streamer will be closed by the server if it stops receiving messages. It's rarely necessary to change this value."
},
{
option: "--no-driver",
default: "false",
description: "Disables the driver for the Synnax database. This is useful when you want to run Synnax as a standalone server without any device integration."
},
{
option: "--disable-integrations",
default: "\"\"",
description: "Comma separated list of device integrations to disable. This is useful when you don't want particular integrations."
},
{
option: "--enable-integrations",
default: "ni,opc",
description: "Comma separated list of device integrations to enable. This is useful when you only want particular integrations. All integrations are enabled by default."
}
]}
/>
Expand Down
1 change: 1 addition & 0 deletions docs/site/src/pages/reference/python-client/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ perform various tasks.
| [Stream Write](https://github.com/synnaxlabs/synnax/tree/main/client/py/examples/stream_write.py) | Shows how to stream simulated sensor data to a set of channels. |
| [Live Stream](https://github.com/synnaxlabs/synnax/tree/main/client/py/examples/live_stream.py) | Shows how to live stream sensor data from a set of channels. Use this in conjunction with the `stream_write.py` example. |
| [Async Live Stream](https://github.com/synnaxlabs/synnax/tree/main/client/py/examples/live_stream_async.py) | Shows how to live stream sensor data from a set of channels in an asynchronous fashion. Use this in conjunction with the `stream_write.py` example. |
| [Calculated Channels](https://github.com/synnaxlabs/synnax/tree/main/client/py/examples/calculated_channels.py) | Shows how to create and write to channels that are calculated from other channels. |
| [Create Range](https://github.com/synnaxlabs/synnax/tree/main/client/py/examples/create_range.py) | Creates a range and reads data from it. |
| [Load](https://github.com/synnaxlabs/synnax/tree/main/client/py/examples/load.py) | Creates a simulated data acquisition computer that writes a large amount of data to a set of channels. |
| [Create Many Channels](https://github.com/synnaxlabs/synnax/tree/main/client/py/examples/create_many_channels.py) | Shows how to create large numbers of channels in a cluster. |
Expand Down

0 comments on commit 6aa75d7

Please sign in to comment.