From cad8494d7479358fb4c2b63c60cad30c1033920e Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Mon, 26 Aug 2024 15:22:52 -0400 Subject: [PATCH 1/6] Add more data on organizations --- docs/how-tos/sensor-data-query-sdk.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/how-tos/sensor-data-query-sdk.md b/docs/how-tos/sensor-data-query-sdk.md index 4a0b43e1fc..3c8575bfbd 100644 --- a/docs/how-tos/sensor-data-query-sdk.md +++ b/docs/how-tos/sensor-data-query-sdk.md @@ -76,9 +76,13 @@ pip install viam-sdk To access your machines using the Python SDK, you must use an API key: ```sh {class="command-line" data-prompt="$"} -viam organizations api-key create --org-id --name my-api-key +viam organizations api-key create --org-id= --name=my-api-key ``` +This command uses the Viam CLI. +You can use `viam organizations list` to retrieve your organization's ID. +For more information, go to the documentation on [installing the Viam CLI](/cli/#install) and [the `viam organizations` command](/cli/#organizations). + {{% /tablestep %}} {{% tablestep link="/appendix/apis/data-client/"%}} **2. Use the API key with the `data_client`** From fe039d4b20efc62b3156110c1aa11b5ecc9f3755 Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Wed, 28 Aug 2024 16:26:22 -0400 Subject: [PATCH 2/6] Edit script instructions --- docs/how-tos/sensor-data-query-sdk.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/how-tos/sensor-data-query-sdk.md b/docs/how-tos/sensor-data-query-sdk.md index 3c8575bfbd..ec54edf739 100644 --- a/docs/how-tos/sensor-data-query-sdk.md +++ b/docs/how-tos/sensor-data-query-sdk.md @@ -1,6 +1,6 @@ --- title: "Query sensor data with the Python SDK" -linkTitle: "Query sensor data with SDK" +linkTitle: "Query sensor data with an SDK" weight: 31 type: "docs" images: ["/services/icons/data-query.svg"] @@ -64,6 +64,16 @@ source .venv/bin/activate pip install viam-sdk ``` +{{% /tablestep %}} +{{% tablestep%}} +**2. Install requirements** + +To query data with the Python SDK, you will need `bson` from the `pymongo` package. To install `bson`, run the following command: + +```sh {class="command-line" data-prompt="$"} +pip install bson +``` + {{% /tablestep %}} {{< /table >}} @@ -87,7 +97,7 @@ For more information, go to the documentation on [installing the Viam CLI](/cli/ {{% tablestep link="/appendix/apis/data-client/"%}} **2. Use the API key with the `data_client`** -Use the API key and [`TabularDataByFilter()`](/appendix/apis/data-client/#tabulardatabyfilter), [`TabularDataBySQL()`](/appendix/apis/data-client/#tabulardatabysql), [`TabularDataByMQL()`](/appendix/apis/data-client/#tabulardatabymql), and[`DeleteTabularData()`](/appendix/apis/data-client/#deletetabulardata) to query data: +Use the API key and [`TabularDataByFilter()`](/appendix/apis/data-client/#tabulardatabyfilter), [`TabularDataBySQL()`](/appendix/apis/data-client/#tabulardatabysql), [`TabularDataByMQL()`](/appendix/apis/data-client/#tabulardatabymql), and[`DeleteTabularData()`](/appendix/apis/data-client/#deletetabulardata) to query data by creating and running the following Python script: ```python {class="line-numbers linkable-line-numbers" data-line="28-50"} import asyncio @@ -118,15 +128,15 @@ async def main(): # Instantiate a DataClient to run data client API methods on data_client = viam_client.data_client - my_filter = Filter(component_name="my-sensor") + my_filter = Filter(component_name="my-sensor") # Replace with your component name data, count, id = await data_client.tabular_data_by_filter( filter=my_filter, limit=5) # This query requests all stored data grouped by hour and calculates the # average, minimum, and maximum of the memory usage data = await data_client.tabular_data_by_mql( - organization_id='', + organization_id='', # Replace with your organization ID mql_binary=[ - bson.dumps({'$match': {'location_id': ''}}), + bson.dumps({'$match': {'location_id': ''}}), # Replace with your location ID bson.dumps({ "$group": { "_id": { @@ -149,6 +159,8 @@ if __name__ == '__main__': asyncio.run(main()) ``` +Make sure to replace the value in line 29 with your correct sensor name, line 35 with your organization ID which you can get by running `viam organizations list`, and line 37 with your location ID which you can get by running ` viam locations list`. + {{% /tablestep %}} {{< /table >}} From 1e9140fe09937e9c1f0513418998b1a8522c102b Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Wed, 28 Aug 2024 16:29:04 -0400 Subject: [PATCH 3/6] Apply suggestions from code review --- docs/how-tos/sensor-data-query-sdk.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/how-tos/sensor-data-query-sdk.md b/docs/how-tos/sensor-data-query-sdk.md index ec54edf739..58d1965597 100644 --- a/docs/how-tos/sensor-data-query-sdk.md +++ b/docs/how-tos/sensor-data-query-sdk.md @@ -90,8 +90,7 @@ viam organizations api-key create --org-id= --name=my-api-key ``` This command uses the Viam CLI. -You can use `viam organizations list` to retrieve your organization's ID. -For more information, go to the documentation on [installing the Viam CLI](/cli/#install) and [the `viam organizations` command](/cli/#organizations). +You can use [`viam organizations list`](/cli/#organizations) to retrieve your organization's ID. {{% /tablestep %}} {{% tablestep link="/appendix/apis/data-client/"%}} From 0e83b1db351def52492cc31aa171308d7c76f7c1 Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Wed, 28 Aug 2024 16:38:03 -0400 Subject: [PATCH 4/6] linter fixup --- docs/how-tos/sensor-data-query-sdk.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/how-tos/sensor-data-query-sdk.md b/docs/how-tos/sensor-data-query-sdk.md index 58d1965597..3c8aca378e 100644 --- a/docs/how-tos/sensor-data-query-sdk.md +++ b/docs/how-tos/sensor-data-query-sdk.md @@ -127,15 +127,15 @@ async def main(): # Instantiate a DataClient to run data client API methods on data_client = viam_client.data_client - my_filter = Filter(component_name="my-sensor") # Replace with your component name + my_filter = Filter(component_name="my-sensor") data, count, id = await data_client.tabular_data_by_filter( filter=my_filter, limit=5) # This query requests all stored data grouped by hour and calculates the # average, minimum, and maximum of the memory usage data = await data_client.tabular_data_by_mql( - organization_id='', # Replace with your organization ID + organization_id='', mql_binary=[ - bson.dumps({'$match': {'location_id': ''}}), # Replace with your location ID + bson.dumps({'$match': {'location_id': ''}}), bson.dumps({ "$group": { "_id": { @@ -158,7 +158,7 @@ if __name__ == '__main__': asyncio.run(main()) ``` -Make sure to replace the value in line 29 with your correct sensor name, line 35 with your organization ID which you can get by running `viam organizations list`, and line 37 with your location ID which you can get by running ` viam locations list`. +Make sure to replace the value in line 29 with your correct sensor name, line 35 with your organization ID which you can get by running `viam organizations list`, and line 37 with your location ID which you can get by running `viam locations list`. {{% /tablestep %}} {{< /table >}} From 45f4b186036dd81b033b46bb8056c6ea974c8652 Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Thu, 29 Aug 2024 10:52:28 -0400 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Naomi Pentrel <5212232+npentrel@users.noreply.github.com> --- docs/how-tos/sensor-data-query-sdk.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/how-tos/sensor-data-query-sdk.md b/docs/how-tos/sensor-data-query-sdk.md index 3c8aca378e..c8b1a288a8 100644 --- a/docs/how-tos/sensor-data-query-sdk.md +++ b/docs/how-tos/sensor-data-query-sdk.md @@ -68,7 +68,8 @@ pip install viam-sdk {{% tablestep%}} **2. Install requirements** -To query data with the Python SDK, you will need `bson` from the `pymongo` package. To install `bson`, run the following command: +To query data with the Python SDK, you will the `bson` package or the `pymongo` package. +To install `bson`, run the following command: ```sh {class="command-line" data-prompt="$"} pip install bson @@ -98,7 +99,7 @@ You can use [`viam organizations list`](/cli/#organizations) to retrieve your or Use the API key and [`TabularDataByFilter()`](/appendix/apis/data-client/#tabulardatabyfilter), [`TabularDataBySQL()`](/appendix/apis/data-client/#tabulardatabysql), [`TabularDataByMQL()`](/appendix/apis/data-client/#tabulardatabymql), and[`DeleteTabularData()`](/appendix/apis/data-client/#deletetabulardata) to query data by creating and running the following Python script: -```python {class="line-numbers linkable-line-numbers" data-line="28-50"} +```python {class="line-numbers linkable-line-numbers" data-line="29-51"} import asyncio import bson From 8293f7ed5d642003aad771c858ca53c5ac0e69f9 Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Thu, 29 Aug 2024 11:17:10 -0400 Subject: [PATCH 6/6] make places to change more obvious --- docs/how-tos/sensor-data-query-sdk.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/how-tos/sensor-data-query-sdk.md b/docs/how-tos/sensor-data-query-sdk.md index c8b1a288a8..342dfe8e8d 100644 --- a/docs/how-tos/sensor-data-query-sdk.md +++ b/docs/how-tos/sensor-data-query-sdk.md @@ -99,7 +99,11 @@ You can use [`viam organizations list`](/cli/#organizations) to retrieve your or Use the API key and [`TabularDataByFilter()`](/appendix/apis/data-client/#tabulardatabyfilter), [`TabularDataBySQL()`](/appendix/apis/data-client/#tabulardatabysql), [`TabularDataByMQL()`](/appendix/apis/data-client/#tabulardatabymql), and[`DeleteTabularData()`](/appendix/apis/data-client/#deletetabulardata) to query data by creating and running the following Python script: -```python {class="line-numbers linkable-line-numbers" data-line="29-51"} +{{% alert title="Note" color="note" %}} +Make sure to replace the value in line 30 with your correct sensor name, line 35 with your organization ID which you can get by running `viam organizations list`, and line 37 with your location ID which you can get by running `viam locations list`. +{{% /alert %}} + +```python {class="line-numbers linkable-line-numbers" data-line="29-54, 30, 37, 40"} import asyncio import bson @@ -128,15 +132,18 @@ async def main(): # Instantiate a DataClient to run data client API methods on data_client = viam_client.data_client + # TODO: replace "my-sensor" with your correct sensor name my_filter = Filter(component_name="my-sensor") data, count, id = await data_client.tabular_data_by_filter( filter=my_filter, limit=5) # This query requests all stored data grouped by hour and calculates the # average, minimum, and maximum of the memory usage data = await data_client.tabular_data_by_mql( - organization_id='', + # TODO: Replace with your organization ID + organization_id='', mql_binary=[ - bson.dumps({'$match': {'location_id': ''}}), + # TODO: Replace with your location ID + bson.dumps({'$match': {'location_id': ''}}), bson.dumps({ "$group": { "_id": { @@ -159,12 +166,10 @@ if __name__ == '__main__': asyncio.run(main()) ``` -Make sure to replace the value in line 29 with your correct sensor name, line 35 with your organization ID which you can get by running `viam organizations list`, and line 37 with your location ID which you can get by running `viam locations list`. - {{% /tablestep %}} {{< /table >}} -Adjust the Python script to query your data further. +Adjust the Python script to query your data further with the [`data_client` API](/appendix/apis/data-client/#api). ## Next steps