### Install PyClarify using pip Source: https://github.com/clarify/pyclarify/blob/main/docs/source/landing.md Installs the PyClarify package from the Python Package Index (PyPI). This is the recommended method for installing the SDK. ```sh pip install pyclarify ``` -------------------------------- ### PublishSignalsResponse Success Example Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Example of a successful response from the `publish_signals` method, showing created and updated items. ```python >>> jsonrpc = '2.0' ... id = '1' ... result = PublishSignalsResponse( ... itemsBySignal = {'SIGNAL_ID': SaveSummary( ... id='ITEM_ID', ... created=True, ... updated=False )}) ... error = None ``` -------------------------------- ### Successful Response Example Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Example of a successful response from `select_items`, returning a pydantic model with meta and data. ```python >>> jsonrpc = '2.0' ... id = '1' ... result = Selection( ... meta={ ... 'total': -1, ... 'groupIncludedByType': True ... }, ... data=[ ... ItemSelectView( ... id='c5i41fjsbu8cohpkcpvg', ... type='items', ... meta=ResourceMetadata( ... annotations={ ... "docs-clarify-io/example/environment": "office" ... }, ... attributesHash='7602afa2fe611e0c8eff17f7936e108ee29e6817', ... relationshipsHash='5f36b2220a14b54ee5ea290645ee34d943ea5be5', ... updatedAt=datetime.datetime(2022, 3, 25, 9, 58, 20, 264000, tzinfo=datetime.timezone.utc), ... createdAt=datetime.datetime(2021, 10, 11, 13, 48, 46, 958000, tzinfo=datetime.timezone.utc) ... ), ... attributes=Item( ... name='Dunder ReBond Inventory Level', ... valueType=, ... description='How many reams of the Dunder ReBond we have in the warehouse.', ... labels={ ... 'type': ['Recycled', 'Bond'], ... 'location': ['Scranton'], ... 'threat-level': ['Midnight'] ... }, ... engUnit='', ... enumValues={}, ... sourceType=, ... sampleInterval=None, ... gapDetection=datetime.timedelta(seconds=7200), ... visible=True ... ), ... relationships={} ... ), ... ItemSelectView(...), ... ... ... ] ... ), ... error=None ``` -------------------------------- ### Install PyClarify Source: https://github.com/clarify/pyclarify/blob/main/README.md Install the PyClarify package using pip or conda. Ensure you have Python 3.7+ and pip installed. ```shell pip install pyclarify ``` ```shell conda install pyclarify ``` -------------------------------- ### SaveSignalsResponse Success Example Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Example of a successful response from the `save_signals` method, detailing created and updated signals. ```python >>> jsonrpc = '2.0' ... id = '1' ... result = SaveSignalsResponse( ... signalsByInput={ ... 'INPUT_ID': SaveSummary(id='SIGNAL_ID', created=True, updated=False) ... } ... ) ... error = None ``` -------------------------------- ### NotEqual Filter Example Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/filter.md Use the NotEqual class for negated equality matches. Import from pyclarify.query. ```python >>> from pyclarify.query import NotEqual >>> filter_value = NotEqual(value="bar") ``` -------------------------------- ### Error Response Example Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Example of an error response from `select_items`, returning a pydantic model with error details. ```python >>> jsonrpc = '2.0' ... id = '1' ... result = None ... error = Error( ... code = '-32602', ... message = 'Invalid params', ... data = ErrorData(trace = , params = {}) ... ) ``` -------------------------------- ### Equal Filter Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/filter.md Example of creating an 'Equal' filter to match resources where a field's value is exactly equal to the specified value. ```python >>> from pyclarify.query import Equal >>> filter_value = Equal(value="foo") ``` -------------------------------- ### Less Filter Example Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/filter.md Use the Less class to match resources where a field's value is less than a specified value. Import from pyclarify.query. ```python >>> from pyclarify.query import Less >>> filter_value = Less(value=10) ``` -------------------------------- ### Get Items with Sorting Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Retrieve 100 items and sort them by name in ascending order. ```python >>> client.select_items( ... limit = 100, ... sort = ["name"], ... ) ``` -------------------------------- ### LessOrEqual Filter Example Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/filter.md Use the LessOrEqual class to match resources where a field's value is less than or equal to a specified value. Import from pyclarify.query. ```python >>> from pyclarify.query import LessOrEqual >>> filter_value = LessOrEqual(value=10) ``` -------------------------------- ### Successful Signal Selection Response Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Example of a successful response from `select_signals` when `total=True` and `include=['item']`. It includes metadata, signal data, and included item data. ```python >>> jsonrpc='2.0' ... id='1' ... result=Selection( ... meta=SelectionMeta( ... total=725, ... groupIncludedByType=True ... ), ... data=[ ... SignalSelectView( ... id='c5fg083sab1b6pm3u290', ... type='signals', ... meta=ResourceMetadata( ... annotations={ ... "docs-clarify-io/example/environment": "office" ... }, ... attributesHash='9ae4eb17c8b3b9f24cea06f09a1a4cab34569077', ... relationshipsHash='02852897e7fe1e7896360b3c3914c5207d2af6fa', ... updatedAt=datetime.datetime(2022, 3, 17, 12, 17, 10, 199000, tzinfo=datetime.timezone.utc), ... createdAt=datetime.datetime(2021, 10, 7, 14, 11, 44, 897000, tzinfo=datetime.timezone.utc) ... ), ... attributes=SavedSignal( ... name='Total reams of paper', ... description='Total count of reams of paper in inventory', ... labels={ ... 'type': ['Recycled', 'Bond'], ... 'location': ['Scranton'] ... }, ... sourceType=, ... valueType=, ... engUnit='', ... enumValues={}, ... sampleInterval=None, ... gapDetection=None, ... input='inventory_recycled_bond', ... integration=None, ... item=None ... ), ... relationships=RelationshipsDict( ... integration=RelationshipData( ... data=RelationshipMetadata( ... type='integrations', ... id='c5e3u8coh8drsbpi4cvg' ... ) ... ), ... item=RelationshipData(data=None) ... ) ... ), ... ... ... ], ... included=IncludedField( ... integration=None, ... items=[ ... ItemSelectView( ... id='c5i41fjsbu8cohpkcpvg', ... type='items', ... meta=ResourceMetadata( ... annotations={ ... "docs-clarify-io/example/environment": "office" ... }, ... attributesHash='7602afa2fe611e0c8eff17f7936e108ee29e6817', ... relationshipsHash='5f36b2220a14b54ee5ea290645ee34d943ea5be5', ... updatedAt=datetime.datetime(2022, 3, 25, 9, 58, 20, 264000, tzinfo=datetime.timezone.utc), ... createdAt=datetime.datetime(2021, 10, 11, 13, 48, 46, 958000, tzinfo=datetime.timezone.utc) ... ), ... attributes=Item( ... name='Dunder ReBond Inventory Level', ... valueType=, ... description='How many reams of the Dunder ReBond we have in the warehouse.', ... labels={ ... 'type': ['Recycled', 'Bond'], ... 'location': ['Scranton'], ... 'threat-level': ['Midnight'] ... }, ... engUnit='', ... enumValues={}, ... sourceType=, ... sampleInterval=None, ... gapDetection=datetime.timedelta(seconds=7200), ... visible=True ... ) ... ) ... ... ... ] ... ) ... ) ... error=None ``` -------------------------------- ### Retrieve DataFrame with Filter Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Fetch data using a filter to select specific items. The example uses a `NotEqual` filter on the 'name' field. ```python client.data_frame( filter = query.Filter(fields={"name": query.NotEqual(value="Air Temperature")}), ) ``` -------------------------------- ### In Filter Example Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/filter.md Use the In class to match resources where a field's value is present in a specified list. Import from pyclarify.query. ```python >>> from pyclarify.query import In >>> filter_value = In(value=["foo", "bar"]) ``` -------------------------------- ### Selecting Items with JSON:API Format Source: https://github.com/clarify/pyclarify/blob/main/CHANGELOG.md Example of using `client.select_items` to query resources with filtering, sorting, and pagination. This method now responds in JSON:API format and does not retrieve data frames. ```python client.select_items( filter = query.Filter(fields={"name": query.NotEqual(value="Air Temperature")}), skip = 0, limit = 10, sort = ["-id", "name"], total=True ) ``` -------------------------------- ### Get Sampled Data with Rollup Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Use rollup for faster data sampling compared to window_size. This snippet shows how to retrieve sampled data with a specified rollup interval and limits. ```pycon >>> r = client.data_frame( ... rollup = "PT5M", ... limit = 5, ... skip = 3, ... ) >>> r.result.data ... DataFrame( ... times=[datetime.datetime(2022, 9, 5, 11, 5, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 5, 11, 10, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 5, 11, 15, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 5, 11, 30, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 5, 11, 35, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 6, 13, 40, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 6, 13, 45, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 6, 13, 50, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 7, 13, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 7, 13, 5, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 7, 13, 10, tzinfo=datetime.timezone.utc)], ... series={ ... 'cbpmaq6rpn52969vfl1g_avg': [1.0, 5.0, 5.875, 6.8, 4.2, 7.0, 3.6, 5.0, 2.0, 2.2, 4.25], ... 'cbpmaq6rpn52969vfl1g_count': [2.0, 10.0, 8.0, 5.0, 5.0, 3.0, 5.0, 2.0, 1.0, 5.0, 4.0], ... 'cbpmaq6rpn52969vfl1g_max': [1.0, 9.0, 9.0, 9.0, 8.0, 9.0, 6.0, 6.0, 2.0, 6.0, 8.0], ... 'cbpmaq6rpn52969vfl1g_min': [1.0, 0.0, 0.0, 5.0, 1.0, 6.0, 0.0, 4.0, 2.0, 0.0, 0.0], ... 'cbpmaq6rpn52969vfl1g_sum': [2.0, 50.0, 47.0, 34.0, 21.0, 21.0, 18.0, 10.0, 2.0, 11.0, 17.0], ... 'cbpmaq6rpn52969vfl20_avg': [5.0, 4.7, 3.75, 3.6, 5.2, 7.333333333333333, 3.6, 7.0, 9.0, 3.6, 6.75], ... 'cbpmaq6rpn52969vfl20_count': [2.0, 10.0, 8.0, 5.0, 5.0, 3.0, 5.0, 2.0, 1.0, 5.0, 4.0], ... 'cbpmaq6rpn52969vfl20_max': [8.0, 9.0, 8.0, 7.0, 9.0, 9.0, 8.0, 9.0, 9.0, 8.0, 9.0], ... 'cbpmaq6rpn52969vfl20_min': [2.0, 1.0, 0.0, 1.0, 2.0, 4.0, 0.0, 5.0, 9.0, 0.0, 1.0], ... 'cbpmaq6rpn52969vfl20_sum': [10.0, 47.0, 30.0, 18.0, 26.0, 22.0, 18.0, 14.0, 9.0, 18.0, 27.0], ... 'cbpmaq6rpn52969vfl2g_avg': [8.0, 3.7, 4.75, 1.6, 3.6, 2.0, 5.6, 8.5, 4.0, 3.8, 5.0], ... 'cbpmaq6rpn52969vfl2g_count': [2.0, 10.0, 8.0, 5.0, 5.0, 3.0, 5.0, 2.0, 1.0, 5.0, 4.0], ... 'cbpmaq6rpn52969vfl2g_max': [8.0, 9.0, 9.0, 5.0, 8.0, 5.0, 9.0, 9.0, 4.0, 8.0, 7.0], ... 'cbpmaq6rpn52969vfl2g_min': [8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 8.0, 4.0, 0.0, 1.0], ... 'cbpmaq6rpn52969vfl2g_sum': [16.0, 37.0, 38.0, 8.0, 18.0, 6.0, 28.0, 17.0, 4.0, 19.0, 20.0], ... 'cbpmaq6rpn52969vfl30_avg': [2.0, 5.6, 3.875, 3.2, 5.2, 4.666666666666667, 5.0, 4.5, 7.0, 5.8, 8.0], ... 'cbpmaq6rpn52969vfl30_count': [2.0, 10.0, 8.0, 5.0, 5.0, 3.0, 5.0, 2.0, 1.0, 5.0, 4.0], ... 'cbpmaq6rpn52969vfl30_max': [3.0, 9.0, 7.0, 9.0, 9.0, 8.0, 7.0, 8.0, 7.0, 9.0, 9.0], ... 'cbpmaq6rpn52969vfl30_min': [1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 2.0, 1.0, 7.0, 1.0, 6.0], ... 'cbpmaq6rpn52969vfl30_sum': [4.0, 56.0, 31.0, 16.0, 26.0, 14.0, 25.0, 9.0, 7.0, 29.0, 32.0], ... 'cbpmaq6rpn52969vfl3g_avg': [1.5, 3.3, 6.75, 5.8, 4.8, 5.666666666666667, 3.8, 6.5, 5.0, 3.0, 3.25], ... 'cbpmaq6rpn52969vfl3g_count': [2.0, 10.0, 8.0, 5.0, 5.0, 3.0, 5.0, 2.0, 1.0, 5.0, 4.0], ... 'cbpmaq6rpn52969vfl3g_max': [2.0, 9.0, 9.0, 9.0, 9.0, 7.0, 8.0, 8.0, 5.0, 7.0, 5.0], ... 'cbpmaq6rpn52969vfl3g_min': [1.0, 1.0, 4.0, 1.0, 1.0, 3.0, 0.0, 5.0, 5.0, 0.0, 0.0], ... 'cbpmaq6rpn52969vfl3g_sum': [3.0, 33.0, 54.0, 29.0, 24.0, 17.0, 19.0, 13.0, 5.0, 15.0, 13.0] ... }) ``` -------------------------------- ### Retrieve DataFrame with Custom Window Size Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Adjust the `window_size` parameter to handle high-resolution data or mitigate JSON decoding errors. This example sets a window size of 20 days. ```python client.data_frame( window_size = "P20DT", limit = 5, skip = 3, ) ``` -------------------------------- ### Filter Items with Regex Source: https://github.com/clarify/pyclarify/blob/main/README.md Apply filters using regular expressions to select specific items based on their labels. This example selects items with 'Raspberry' in their unit-type label. ```python from pyclarify.query import Filter, Regex only_raspberries = Filter( fields={ "labels.unit-type": Regex(value="Raspberry") } ) response = client.select_items( filter=only_raspberries ) ``` -------------------------------- ### Query Signals with Total and Include Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Retrieve signals, including the total count of matching signals in the metadata and related 'item' data. This is useful for getting counts and associated details. ```python >>> client.select_signals( ... total= True, ... include = ["item"] ... ) ``` -------------------------------- ### Initialize Client Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Instantiate the Client class with the path to your Clarify credentials JSON file. ```python >>> client = Client("./clarify-credentials.json") ``` -------------------------------- ### Get Single Item in Time Range Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Fetch aggregated data for a single item within a specified date and time range. Use 'gte' for the start time and 'lt' for the end time. The rollup parameter defines the time interval. ```python >>> r = client.evaluate(items=[item1], gte="2022-08-10T00:00:00Z", lt="2022-08-30T00:00:00Z", rollup="PT10M") >>> print(r.result.data.to_pandas()) ... i1 ... 2022-08-10 09:50:00+00:00 8.0 ... 2022-08-10 10:00:00+00:00 9.0 ... 2022-08-25 11:30:00+00:00 8.0 ... 2022-08-30 15:10:00+00:00 2.0 ... 2022-08-30 15:20:00+00:00 9.0 ... 2022-08-30 15:30:00+00:00 9.0 ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/clarify/pyclarify/blob/main/CONTRIBUTING.md Build HTML documentation files locally by navigating to the docs directory and running the make html command. ```bash cd docs make html ``` -------------------------------- ### Initialize Clarify Client Source: https://github.com/clarify/pyclarify/blob/main/README.md Initialize the Clarify Client by providing the path to your credentials file. This is the first step to interacting with the Clarify API. ```python from pyclarify import Client client = Client("clarify-credentials.json") ``` -------------------------------- ### Run Unit Tests Source: https://github.com/clarify/pyclarify/blob/main/CONTRIBUTING.md Initiate unit tests for all new functionality from the root directory of the project. ```bash python -m unittest discover -s tests/ ``` -------------------------------- ### Create Item with All Attributes Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/items.md Instantiate the Item model with all available parameters, including description, labels, engineering unit, sample interval, and gap detection. ```python >>> item = Item( ... name="My new item" ... description="This item is an example." ... labels={ ... "environment": ["dev", "mocking"], ... "unit":["cloud"] ... } ... engUnit="℃" ... sampleInterval="PT30S" ... gapDetection="PT5M" ... ) ``` -------------------------------- ### Create and Combine Filters Source: https://github.com/clarify/pyclarify/blob/main/CHANGELOG.md Demonstrates how to create individual filters using various operators and combine them using logical AND. Use this for complex query construction. ```python from pyclarify import filter f1 = filter.Filter(fields={"name": filter.NotEqual(value="Lufttemperatur")}) f2 = filter.Filter(fields={"labels.unit-type": filter.NotIn(value=["Flåte", "Merde 5"])}) f1.to_query() >>> {'name': {'$ne': 'Lufttemperatur'}} f3 = f1 & f2 f3.to_query() >>> { >>> '$and': [ >>> {'name': {'$ne': 'Lufttemperatur'}}, >>> {'labels.unit-type': {'$nin': ['Flåte', 'Merde 5']}} >>> ] >>>} ``` -------------------------------- ### Client Class Initialization Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Initializes the Client class with Clarify API credentials. The credentials are provided via a path to a JSON file obtained from the Clarify integrations page. ```APIDOC ## Client Class ### Description The Client class is the primary interface for interacting with the Clarify API using JSON-RPC. It requires authentication credentials upon initialization. ### Parameters * **clarify_credentials** (*path to json file*) – Path to the Clarify credentials JSON file. ### Example ```python from pyclarify import Client client = Client("./clarify-credentials.json") ``` ``` -------------------------------- ### Get a Specific Number of Items Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Retrieve a maximum of 1000 items. ```python >>> client.select_items( ... limit = 1000, ... ) ``` -------------------------------- ### Get Total Number of Signals Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Retrieve the total count of signals, indicated by `total=True`. ```python >>> client.select_items( ... total= True, ... ) ``` -------------------------------- ### Create a Simple Calculation Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/evaluate.md Create a Calculation model with a basic formula. Assumes items with aliases 'i1' and 'i2' exist. ```python calculation = Calculation( formula="i1 + i2" alias="c1" ) ``` -------------------------------- ### Create Minimal Item Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/items.md Instantiate the Item model with only the required 'name' parameter. ```python >>> item = Item(name="My new item") ``` -------------------------------- ### Selecting Signals with JSON:API Format and Includes Source: https://github.com/clarify/pyclarify/blob/main/CHANGELOG.md Demonstrates how to use `client.select_signals` to retrieve signals, applying filters, sorting, pagination, and including related resources. This method now responds in JSON:API format. ```python client.select_signals( filter = Filter(fields={"name": filter.NotEqual(value="Air Temperature")}), limit = 10, skip = 0, sort = ["-id"], total= True, include = ["item"] ) ``` -------------------------------- ### Greater Than Filter Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/filter.md Example of creating a 'Greater' filter to match resources where a field's value is strictly greater than the specified value. ```python >>> from pyclarify.query import Greater >>> filter_value = Greater(value=10) ``` -------------------------------- ### Create Signal with All Attributes Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/signals.md Create a Signal object, specifying all available attributes including description, labels, engineering unit, sample interval, and gap detection. ```python >>> signal = Signal( ... name="My new signal" ... description="This signal is an example." ... labels={ ... "environment": ["dev", "mocking"], ... "unit":["cloud"] ... } ... engUnit="℃" ... sampleInterval="PT30S" ... gapDetection="PT5M" ... ) ``` -------------------------------- ### Publish Items with pyclarify Source: https://github.com/clarify/pyclarify/blob/main/README.md Use the Item class to create and publish signals with associated metadata. Ensure you have your credentials configured. ```python from pyclarify import Item client = Client("./clarify-credentials.json") item = Item( name = "Home temperature", description = "Temperature in the bedroom", labels = {"data-source": ["Raspberry Pi"], "location": ["Home"]}, visible=True ) response = client.publish_signals( signal_ids=[''], items=[item], create_only=False ) ``` -------------------------------- ### Greater Than or Equal To Filter Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/filter.md Example of creating a 'GreaterOrEqual' filter to match resources where a field's value is greater than or equal to the specified value. ```python >>> from pyclarify.query import GreaterOrEqual >>> filter_value = GreaterOrEqual(value=10) ``` -------------------------------- ### Publish Signals using Dictionary Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Publish signals to create items, using a dictionary to map signal IDs to Item objects. The Item class must be imported. ```python >>> from pyclarify import Item >>> item = Item( ... name = "Home temperature", ... description = "Temperature in the bedroom", ... labels = { ... "data-source": ["Raspberry Pi"], ... "location": ["Home"] ... }, ... visible=True ... ) >>> items_dict = { ... "": item ... } >>> response = client.publish_signals( ... items_by_signal=item_dict ... ) ``` -------------------------------- ### Create and Save Signals Source: https://github.com/clarify/pyclarify/blob/main/README.md Create a Signal object with a name, description, and labels, then save it using the ClarifyClient. The `create_only` parameter controls whether to create new signals or update existing ones. ```python from pyclarify import Signal signal = Signal( name = "Home temperature", description = "Temperature in the bedroom", labels = {"data-source": ["Raspberry Pi"], "location": ["Home"]} ) response = client.save_signals( input_ids=["INPUT_ID"], signals=[signal], create_only=False ) ``` -------------------------------- ### Get Data with Relationships Source: https://github.com/clarify/pyclarify/blob/main/README.md Retrieve data as a DataFrame, including related item information, by applying a filter. This is useful for analyzing data with associated metadata. ```python response = client.data_frame( filter=only_raspberries, include=["item"] ) ``` -------------------------------- ### Create Item Aggregation with All Attributes Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/evaluate.md Instantiate ItemAggregation with all possible parameters: id, aggregation, state, lead, lag, and alias. ```python item_aggregation = ItemAggregation( id="cbpmaq6rpn52969vfl00", aggregation="max", state=1, lead=1, lag=1, alias="i1" ) ``` -------------------------------- ### Import Calculation Model Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/evaluate.md Import the Calculation model from the pyclarify library. ```python from pyclarify import Calculation ``` -------------------------------- ### Import Signal Class Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/signals.md Import the Signal class from the pyclarify library to begin creating signals. ```python >>> from pyclarify import Signal ``` -------------------------------- ### Create a Minimal Group Aggregation Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/evaluate.md Create a GroupAggregation model with the minimum required parameters: query, timeAggregation, groupAggregationMethod, and alias. ```python group_aggregation = GroupAggregation( query=ResourceQuery(filter={}), timeAggregation="max", groupAggregationMethod="max" alias="g1" ) ``` -------------------------------- ### Get Single Item Aggregation Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Retrieve aggregated data for a single item. Specify the item ID, aggregation type, and an alias. The rollup parameter defines the time interval for aggregation. ```python >>> item = ItemAggregation( ... id="cbpmaq6rpn52969vfl00", ... aggregation="max", ... alias="i1" ... ) >>> r = client.evaluate(items=[item1], rollup="PT10M") >>> print(r.result.data.to_pandas()) ... i1 ... 2023-10-20 10:20:00+00:00 6.0 ... 2023-10-20 10:30:00+00:00 9.0 ... 2023-10-20 10:40:00+00:00 8.0 ``` -------------------------------- ### Clone Pyclarify Repository Source: https://github.com/clarify/pyclarify/blob/main/CONTRIBUTING.md Clone the Pyclarify repository and navigate into the project directory. ```bash git clone git@github.com:clarify/pyclarify.git cd pyclarify ``` -------------------------------- ### Retrieve DataFrame with Time Range Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Get data within a specified time window using `gte` (greater than or equal to) and `lt` (less than) parameters. Dates should be in ISO 8601 format. ```python client.data_frame( gte="2022-01-01T01:01:01Z", lt="2022-01-09T01:01:01Z", ) ``` -------------------------------- ### Insert Data into Clarify Source: https://github.com/clarify/pyclarify/blob/main/docs/source/landing.md Demonstrates how to insert time-series data into Clarify using the PyClarify client. Ensure you have a 'credentials.json' file with valid Clarify integration credentials. ```python from pyclarify import Client data = { "times": ["2023-10-27T00:00:00+02:00"], "series": { "temperature": [19], "pressure": [1025] } } client = Client("credentials.json") client.insert(data) ``` -------------------------------- ### Query Signals with Limit and Sort Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Fetch up to 100 signals and sort the results alphabetically by signal name. This helps in organizing the retrieved data. ```python >>> client.select_signals( ... limit = 100, ... sort = ["name"], ... ) ``` -------------------------------- ### Create Minimal Item Aggregation Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/evaluate.md Instantiate ItemAggregation with required parameters: id, aggregation, and alias. ```python item_aggregation = ItemAggregation( id="cbpmaq6rpn52969vfl0g", aggregation="max", alias="i2" ) ``` -------------------------------- ### Create a Group Aggregation with All Attributes Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/evaluate.md Create a GroupAggregation model with all optional parameters set, including state, lead, and lag, in addition to the required parameters. ```python group_aggregation = GroupAggregation( query=ResourceQuery(filter={}), timeAggregationMethod="max", groupAggregationMethod="max", state=1, lead=1, lag=1, alias="g1" ) ``` -------------------------------- ### Import Item Model Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/items.md Import the Item model from the pyclarify library. ```python >>> from pyclarify import Item ``` -------------------------------- ### Populate Signals with DataFrame Source: https://github.com/clarify/pyclarify/blob/main/README.md Use the DataFrame class to structure time-series data and insert it into your signals. Ensure the 'times' and 'series' keys are correctly formatted. ```python from pyclarify import DataFrame data = DataFrame( series={"INPUT_ID_1": [1, None], "INPUT_ID_2": [None, 5]}, times = ["2021-11-01T21:50:06Z", "2021-11-02T21:50:06Z"], ) response = client.insert(data) ``` -------------------------------- ### Import ItemAggregation Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/evaluate.md Import the ItemAggregation class from the pyclarify library. ```python from pyclarify import ItemAggregation ``` -------------------------------- ### Create Minimal Signal Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/signals.md Instantiate a Signal object with only the required 'name' attribute. ```python >>> signal = Signal(name="My new signal") ``` -------------------------------- ### Create and Chain Filters Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/filter.md Demonstrates how to create individual filters using specific comparison operators and chain them together using the '&' operator. The `to_query()` method converts the filter object into a MongoDB query format. ```python >>> from pyclarify import query >>> f1 = query.Filter(fields={"name": query.NotEqual(value="Lufttemperatur")}) >>> f2 = query.Filter(fields={"labels.unit-type": query.NotIn(value=["Flåte", "Merde 5"])}) >>> f1.to_query() ... {'name': {'$ne': 'Lufttemperatur'}} >>> f3 = f1 & f2 >>> f3.to_query() ... { ... '$and': [ ... {'name': {'$ne': 'Lufttemperatur'}}, ... {'labels.unit-type': {'$nin': ['Flåte', 'Merde 5']}} ... ] ... } ``` -------------------------------- ### Query with Multiple Parameters Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Use multiple query parameters including filter, skip, limit, sort, and total. ```python >>> client.select_items( ... filter = query.Filter(fields={"name": query.NotEqual(value="Air Temperature")}), ... skip = 3, ... limit = 10, ... sort = ["-id", "name"], ... total=True, ... ) ``` -------------------------------- ### Import GroupAggregation Model Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/views/evaluate.md Import the GroupAggregation model from the pyclarify library. ```python from pyclarify import GroupAggregation ``` -------------------------------- ### Save Signals using Dictionary Source: https://github.com/clarify/pyclarify/blob/main/docs/source/reference/client/index.md Save signals by providing a dictionary mapping input IDs to Signal objects. Ensure the Signal class is imported. ```python >>> from pyclarify import Signal >>> signal = Signal( ... name = "Home temperature", ... description = "Temperature in the bedroom", ... labels = { ... "data-source": ["Raspberry Pi"], ... "location": ["Home"] ... } ... ) >>> input_dict = { ... "" : signal ... } >>> response = client.save_signals( ... signals_by_input=input_dict ... ) ```