Skip to content

Query Builder

TimeSeriesQueryBuilder

A builder for developing RTDIP queries using any delta table.

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
class TimeSeriesQueryBuilder:
    """
    A builder for developing RTDIP queries using any delta table.
    """

    parameters: dict
    connection: ConnectionInterface
    close_connection: bool
    data_source: str
    tagname_column: str
    timestamp_column: str
    status_column: str
    value_column: str

    def connect(self, connection: ConnectionInterface):
        """
        Specifies the connection to be used for the query.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        connect = (
            TimeSeriesQueryBuilder()
            .connect(connection)
        )

        ```

        Args:
            connection: Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect)
        """
        self.connection = connection
        return self

    def source(
        self,
        source: str,
        tagname_column: str = "TagName",
        timestamp_column: str = "EventTime",
        status_column: Union[str, None] = "Status",
        value_column: str = "Value",
    ):
        """
        Specifies the source of the query.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        source = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source(
                source="{table_path}"
            )
        )

        ```

        Args:
            source (str): Source of the query can be a Unity Catalog table, Hive metastore table or path
            tagname_column (optional str): The column name in the source that contains the tagnames or series
            timestamp_column (optional str): The timestamp column name in the source
            status_column (optional str): The status column name in the source indicating `Good` or `Bad`. If this is not available, specify `None`
            value_column (optional str): The value column name in the source which is normally a float or string value for the time series event
        """
        self.data_source = "`.`".join(source.split("."))
        self.tagname_column = tagname_column
        self.timestamp_column = timestamp_column
        self.status_column = status_column
        self.value_column = value_column
        return self

    def raw(
        self,
        tagname_filter: [str],
        start_date: str,
        end_date: str,
        include_bad_data: bool = False,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A function to return back raw data.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .raw(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                start_date="2023-01-01",
                end_date="2023-01-31",
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe of raw timeseries data.
        """
        raw_parameters = {
            "source": self.data_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "include_bad_data": include_bad_data,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "supress_warning": True,
        }
        return raw.get(self.connection, raw_parameters)

    def resample(
        self,
        tagname_filter: [str],
        start_date: str,
        end_date: str,
        time_interval_rate: str,
        time_interval_unit: str,
        agg_method: str,
        include_bad_data: bool = False,
        pivot: bool = False,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A query to resample the source data.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .resample(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                start_date="2023-01-01",
                end_date="2023-01-31",
                time_interval_rate="15",
                time_interval_unit="minute",
                agg_method="first",
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            time_interval_rate (str): The time interval rate (numeric input)
            time_interval_unit (str): The time interval unit (second, minute, day, hour)
            agg_method (str): Aggregation Method (first, last, avg, min, max)
            include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
            pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe of resampled timeseries data.
        """

        resample_parameters = {
            "source": self.data_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "include_bad_data": include_bad_data,
            "time_interval_rate": time_interval_rate,
            "time_interval_unit": time_interval_unit,
            "agg_method": agg_method,
            "pivot": pivot,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "supress_warning": True,
        }

        return resample.get(self.connection, resample_parameters)

    def interpolate(
        self,
        tagname_filter: [str],
        start_date: str,
        end_date: str,
        time_interval_rate: str,
        time_interval_unit: str,
        agg_method: str,
        interpolation_method: str,
        include_bad_data: bool = False,
        pivot: bool = False,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        The Interpolate function will forward fill, backward fill or linearly interpolate the resampled data depending on the parameters specified.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .interpolate(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                start_date="2023-01-01",
                end_date="2023-01-31",
                time_interval_rate="15",
                time_interval_unit="minute",
                agg_method="first",
                interpolation_method="forward_fill",
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            time_interval_rate (str): The time interval rate (numeric input)
            time_interval_unit (str): The time interval unit (second, minute, day, hour)
            agg_method (str): Aggregation Method (first, last, avg, min, max)
            interpolation_method (str): Interpolation method (forward_fill, backward_fill, linear)
            include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
            pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe of interpolated timeseries data.
        """
        interpolation_parameters = {
            "source": self.data_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "include_bad_data": include_bad_data,
            "time_interval_rate": time_interval_rate,
            "time_interval_unit": time_interval_unit,
            "agg_method": agg_method,
            "interpolation_method": interpolation_method,
            "pivot": pivot,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "supress_warning": True,
        }

        return interpolate.get(self.connection, interpolation_parameters)

    def interpolation_at_time(
        self,
        tagname_filter: [str],
        timestamp_filter: [str],
        include_bad_data: bool = False,
        window_length: int = 1,
        pivot: bool = False,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A interpolation at time function which works out the linear interpolation at a specific time based on the points before and after.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .interpolation_at_time(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                timestamp_filter=["2023-01-01T09:30:00", "2023-01-02T12:00:00"],
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            timestamp_filter (list): List of timestamp or timestamps in the format YYY-MM-DDTHH:MM:SS or YYY-MM-DDTHH:MM:SS+zz:zz where %z is the timezone. (Example +00:00 is the UTC timezone)
            include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
            window_length (optional int): Add longer window time in days for the start or end of specified date to cater for edge cases
            pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe of interpolation at time timeseries data
        """
        interpolation_at_time_parameters = {
            "source": self.data_source,
            "tag_names": tagname_filter,
            "timestamps": timestamp_filter,
            "include_bad_data": include_bad_data,
            "window_length": window_length,
            "pivot": pivot,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "supress_warning": True,
        }

        return interpolation_at_time.get(
            self.connection, interpolation_at_time_parameters
        )

    def time_weighted_average(
        self,
        tagname_filter: [str],
        start_date: str,
        end_date: str,
        time_interval_rate: str,
        time_interval_unit: str,
        step: str,
        source_metadata: str = None,
        include_bad_data: bool = False,
        window_length: int = 1,
        pivot: bool = False,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A function that receives a dataframe of raw tag data and performs a time weighted averages.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .time_weighted_average(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                start_date="2023-01-01",
                end_date="2023-01-31",
                time_interval_rate="15",
                time_interval_unit="minute",
                step="true",
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            time_interval_rate (str): The time interval rate (numeric input)
            time_interval_unit (str): The time interval unit (second, minute, day, hour)
            step (str): data points with step "enabled" or "disabled". The options for step are "true", "false" or "metadata". "metadata" will retrieve the step value from the metadata table
            source_metadata (optional str): if step is set to "metadata", then this parameter must be populated with the source containing the tagname metadata with a column called "Step"
            include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
            window_length (optional int): Add longer window time in days for the start or end of specified date to cater for edge cases
            pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe of time weighted averages timeseries data
        """
        time_weighted_average_parameters = {
            "source": self.data_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "include_bad_data": include_bad_data,
            "time_interval_rate": time_interval_rate,
            "time_interval_unit": time_interval_unit,
            "step": step,
            "source_metadata": (
                None
                if source_metadata is None
                else "`.`".join(source_metadata.split("."))
            ),
            "window_length": window_length,
            "pivot": pivot,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "supress_warning": True,
        }

        return time_weighted_average.get(
            self.connection, time_weighted_average_parameters
        )

    def metadata(
        self,
        tagname_filter: [str] = None,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A query to retrieve metadata.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .metadata(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe of metadata
        """
        metadata_parameters = {
            "source": self.data_source,
            "tag_names": [] if tagname_filter is None else tagname_filter,
            "tagname_column": self.tagname_column,
            "limit": limit,
            "offset": offset,
            "supress_warning": True,
        }

        return metadata.get(self.connection, metadata_parameters)

    def latest(
        self,
        tagname_filter: [str] = None,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A query to retrieve latest event_values.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .latest(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe of events latest_values
        """
        latest_parameters = {
            "source": self.data_source,
            "tag_names": [] if tagname_filter is None else tagname_filter,
            "tagname_column": self.tagname_column,
            "limit": limit,
            "offset": offset,
            "supress_warning": True,
        }

        return latest.get(self.connection, latest_parameters)

    def circular_average(
        self,
        tagname_filter: [str],
        start_date: str,
        end_date: str,
        time_interval_rate: str,
        time_interval_unit: str,
        lower_bound: int,
        upper_bound: int,
        include_bad_data: bool = False,
        pivot: bool = False,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A function that receives a dataframe of raw tag data and computes the circular mean for samples in a range.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .circular_average(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                start_date="2023-01-01",
                end_date="2023-01-31",
                time_interval_rate="15",
                time_interval_unit="minute",
                lower_bound="0",
                upper_bound="360",
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            time_interval_rate (str): The time interval rate (numeric input)
            time_interval_unit (str): The time interval unit (second, minute, day, hour)
            lower_bound (int): Lower boundary for the sample range
            upper_bound (int): Upper boundary for the sample range
            include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
            pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe containing the circular averages
        """
        circular_average_parameters = {
            "source": self.data_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "include_bad_data": include_bad_data,
            "time_interval_rate": time_interval_rate,
            "time_interval_unit": time_interval_unit,
            "lower_bound": lower_bound,
            "upper_bound": upper_bound,
            "pivot": pivot,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "supress_warning": True,
        }

        return circular_average.get(self.connection, circular_average_parameters)

    def circular_standard_deviation(
        self,
        tagname_filter: [str],
        start_date: str,
        end_date: str,
        time_interval_rate: str,
        time_interval_unit: str,
        lower_bound: int,
        upper_bound: int,
        include_bad_data: bool = False,
        pivot: bool = False,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A function that receives a dataframe of raw tag data and computes the circular standard deviation for samples assumed to be in the range.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .circular_standard_deviation(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                start_date="2023-01-01",
                end_date="2023-01-31",
                time_interval_rate="15",
                time_interval_unit="minute",
                lower_bound="0",
                upper_bound="360",
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            time_interval_rate (str): The time interval rate (numeric input)
            time_interval_unit (str): The time interval unit (second, minute, day, hour)
            lower_bound (int): Lower boundary for the sample range
            upper_bound (int): Upper boundary for the sample range
            include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
            pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe containing the circular standard deviations
        """
        circular_stdev_parameters = {
            "source": self.data_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "include_bad_data": include_bad_data,
            "time_interval_rate": time_interval_rate,
            "time_interval_unit": time_interval_unit,
            "lower_bound": lower_bound,
            "upper_bound": upper_bound,
            "pivot": pivot,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "supress_warning": True,
        }

        return circular_standard_deviation.get(
            self.connection, circular_stdev_parameters
        )

    def summary(
        self,
        tagname_filter: [str],
        start_date: str,
        end_date: str,
        include_bad_data: bool = False,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A function to return back a summary of statistics.

        **Example:**
        ```python
        from rtdip_sdk.authentication.azure import DefaultAuth
        from rtdip_sdk.connectors import DatabricksSQLConnection
        from rtdip_sdk.queries import TimeSeriesQueryBuilder

        auth = DefaultAuth().authenticate()
        token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
        connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

        data = (
            TimeSeriesQueryBuilder()
            .connect(connection)
            .source("{table_path}")
            .summary(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                start_date="2023-01-01",
                end_date="2023-01-31",
            )
        )

        display(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
            limit (optional int): The number of rows to be returned
            offset (optional int): The number of rows to skip before returning rows

        Returns:
            DataFrame: A dataframe of raw timeseries data.
        """
        summary_parameters = {
            "source": self.data_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "include_bad_data": include_bad_data,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "supress_warning": True,
        }
        return summary.get(self.connection, summary_parameters)

connect(connection)

Specifies the connection to be used for the query.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

connect = (
    TimeSeriesQueryBuilder()
    .connect(connection)
)

Parameters:

Name Type Description Default
connection ConnectionInterface

Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect)

required
Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def connect(self, connection: ConnectionInterface):
    """
    Specifies the connection to be used for the query.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    connect = (
        TimeSeriesQueryBuilder()
        .connect(connection)
    )

    ```

    Args:
        connection: Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect)
    """
    self.connection = connection
    return self

source(source, tagname_column='TagName', timestamp_column='EventTime', status_column='Status', value_column='Value')

Specifies the source of the query.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

source = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source(
        source="{table_path}"
    )
)

Parameters:

Name Type Description Default
source str

Source of the query can be a Unity Catalog table, Hive metastore table or path

required
tagname_column optional str

The column name in the source that contains the tagnames or series

'TagName'
timestamp_column optional str

The timestamp column name in the source

'EventTime'
status_column optional str

The status column name in the source indicating Good or Bad. If this is not available, specify None

'Status'
value_column optional str

The value column name in the source which is normally a float or string value for the time series event

'Value'
Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def source(
    self,
    source: str,
    tagname_column: str = "TagName",
    timestamp_column: str = "EventTime",
    status_column: Union[str, None] = "Status",
    value_column: str = "Value",
):
    """
    Specifies the source of the query.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    source = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source(
            source="{table_path}"
        )
    )

    ```

    Args:
        source (str): Source of the query can be a Unity Catalog table, Hive metastore table or path
        tagname_column (optional str): The column name in the source that contains the tagnames or series
        timestamp_column (optional str): The timestamp column name in the source
        status_column (optional str): The status column name in the source indicating `Good` or `Bad`. If this is not available, specify `None`
        value_column (optional str): The value column name in the source which is normally a float or string value for the time series event
    """
    self.data_source = "`.`".join(source.split("."))
    self.tagname_column = tagname_column
    self.timestamp_column = timestamp_column
    self.status_column = status_column
    self.value_column = value_column
    return self

raw(tagname_filter, start_date, end_date, include_bad_data=False, limit=None, offset=None)

A function to return back raw data.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .raw(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        start_date="2023-01-01",
        end_date="2023-01-31",
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

required
start_date str

Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
end_date str

End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
include_bad_data optional bool

Include "Bad" data points with True or remove "Bad" data points with False

False
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of raw timeseries data.

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
def raw(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    include_bad_data: bool = False,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A function to return back raw data.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .raw(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            start_date="2023-01-01",
            end_date="2023-01-31",
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe of raw timeseries data.
    """
    raw_parameters = {
        "source": self.data_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "include_bad_data": include_bad_data,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "supress_warning": True,
    }
    return raw.get(self.connection, raw_parameters)

resample(tagname_filter, start_date, end_date, time_interval_rate, time_interval_unit, agg_method, include_bad_data=False, pivot=False, limit=None, offset=None)

A query to resample the source data.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .resample(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        start_date="2023-01-01",
        end_date="2023-01-31",
        time_interval_rate="15",
        time_interval_unit="minute",
        agg_method="first",
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

required
start_date str

Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
end_date str

End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
time_interval_rate str

The time interval rate (numeric input)

required
time_interval_unit str

The time interval unit (second, minute, day, hour)

required
agg_method str

Aggregation Method (first, last, avg, min, max)

required
include_bad_data optional bool

Include "Bad" data points with True or remove "Bad" data points with False

False
pivot optional bool

Pivot the data on the timestamp column with True or do not pivot the data with False

False
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of resampled timeseries data.

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
def resample(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    time_interval_rate: str,
    time_interval_unit: str,
    agg_method: str,
    include_bad_data: bool = False,
    pivot: bool = False,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A query to resample the source data.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .resample(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            start_date="2023-01-01",
            end_date="2023-01-31",
            time_interval_rate="15",
            time_interval_unit="minute",
            agg_method="first",
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        time_interval_rate (str): The time interval rate (numeric input)
        time_interval_unit (str): The time interval unit (second, minute, day, hour)
        agg_method (str): Aggregation Method (first, last, avg, min, max)
        include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
        pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe of resampled timeseries data.
    """

    resample_parameters = {
        "source": self.data_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "include_bad_data": include_bad_data,
        "time_interval_rate": time_interval_rate,
        "time_interval_unit": time_interval_unit,
        "agg_method": agg_method,
        "pivot": pivot,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "supress_warning": True,
    }

    return resample.get(self.connection, resample_parameters)

interpolate(tagname_filter, start_date, end_date, time_interval_rate, time_interval_unit, agg_method, interpolation_method, include_bad_data=False, pivot=False, limit=None, offset=None)

The Interpolate function will forward fill, backward fill or linearly interpolate the resampled data depending on the parameters specified.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .interpolate(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        start_date="2023-01-01",
        end_date="2023-01-31",
        time_interval_rate="15",
        time_interval_unit="minute",
        agg_method="first",
        interpolation_method="forward_fill",
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

required
start_date str

Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
end_date str

End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
time_interval_rate str

The time interval rate (numeric input)

required
time_interval_unit str

The time interval unit (second, minute, day, hour)

required
agg_method str

Aggregation Method (first, last, avg, min, max)

required
interpolation_method str

Interpolation method (forward_fill, backward_fill, linear)

required
include_bad_data optional bool

Include "Bad" data points with True or remove "Bad" data points with False

False
pivot optional bool

Pivot the data on the timestamp column with True or do not pivot the data with False

False
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of interpolated timeseries data.

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
def interpolate(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    time_interval_rate: str,
    time_interval_unit: str,
    agg_method: str,
    interpolation_method: str,
    include_bad_data: bool = False,
    pivot: bool = False,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    The Interpolate function will forward fill, backward fill or linearly interpolate the resampled data depending on the parameters specified.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .interpolate(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            start_date="2023-01-01",
            end_date="2023-01-31",
            time_interval_rate="15",
            time_interval_unit="minute",
            agg_method="first",
            interpolation_method="forward_fill",
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        time_interval_rate (str): The time interval rate (numeric input)
        time_interval_unit (str): The time interval unit (second, minute, day, hour)
        agg_method (str): Aggregation Method (first, last, avg, min, max)
        interpolation_method (str): Interpolation method (forward_fill, backward_fill, linear)
        include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
        pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe of interpolated timeseries data.
    """
    interpolation_parameters = {
        "source": self.data_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "include_bad_data": include_bad_data,
        "time_interval_rate": time_interval_rate,
        "time_interval_unit": time_interval_unit,
        "agg_method": agg_method,
        "interpolation_method": interpolation_method,
        "pivot": pivot,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "supress_warning": True,
    }

    return interpolate.get(self.connection, interpolation_parameters)

interpolation_at_time(tagname_filter, timestamp_filter, include_bad_data=False, window_length=1, pivot=False, limit=None, offset=None)

A interpolation at time function which works out the linear interpolation at a specific time based on the points before and after.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .interpolation_at_time(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        timestamp_filter=["2023-01-01T09:30:00", "2023-01-02T12:00:00"],
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

required
timestamp_filter list

List of timestamp or timestamps in the format YYY-MM-DDTHH:MM:SS or YYY-MM-DDTHH:MM:SS+zz:zz where %z is the timezone. (Example +00:00 is the UTC timezone)

required
include_bad_data optional bool

Include "Bad" data points with True or remove "Bad" data points with False

False
window_length optional int

Add longer window time in days for the start or end of specified date to cater for edge cases

1
pivot optional bool

Pivot the data on the timestamp column with True or do not pivot the data with False

False
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of interpolation at time timeseries data

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
def interpolation_at_time(
    self,
    tagname_filter: [str],
    timestamp_filter: [str],
    include_bad_data: bool = False,
    window_length: int = 1,
    pivot: bool = False,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A interpolation at time function which works out the linear interpolation at a specific time based on the points before and after.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .interpolation_at_time(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            timestamp_filter=["2023-01-01T09:30:00", "2023-01-02T12:00:00"],
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        timestamp_filter (list): List of timestamp or timestamps in the format YYY-MM-DDTHH:MM:SS or YYY-MM-DDTHH:MM:SS+zz:zz where %z is the timezone. (Example +00:00 is the UTC timezone)
        include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
        window_length (optional int): Add longer window time in days for the start or end of specified date to cater for edge cases
        pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe of interpolation at time timeseries data
    """
    interpolation_at_time_parameters = {
        "source": self.data_source,
        "tag_names": tagname_filter,
        "timestamps": timestamp_filter,
        "include_bad_data": include_bad_data,
        "window_length": window_length,
        "pivot": pivot,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "supress_warning": True,
    }

    return interpolation_at_time.get(
        self.connection, interpolation_at_time_parameters
    )

time_weighted_average(tagname_filter, start_date, end_date, time_interval_rate, time_interval_unit, step, source_metadata=None, include_bad_data=False, window_length=1, pivot=False, limit=None, offset=None)

A function that receives a dataframe of raw tag data and performs a time weighted averages.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .time_weighted_average(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        start_date="2023-01-01",
        end_date="2023-01-31",
        time_interval_rate="15",
        time_interval_unit="minute",
        step="true",
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

required
start_date str

Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
end_date str

End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
time_interval_rate str

The time interval rate (numeric input)

required
time_interval_unit str

The time interval unit (second, minute, day, hour)

required
step str

data points with step "enabled" or "disabled". The options for step are "true", "false" or "metadata". "metadata" will retrieve the step value from the metadata table

required
source_metadata optional str

if step is set to "metadata", then this parameter must be populated with the source containing the tagname metadata with a column called "Step"

None
include_bad_data optional bool

Include "Bad" data points with True or remove "Bad" data points with False

False
window_length optional int

Add longer window time in days for the start or end of specified date to cater for edge cases

1
pivot optional bool

Pivot the data on the timestamp column with True or do not pivot the data with False

False
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of time weighted averages timeseries data

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
def time_weighted_average(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    time_interval_rate: str,
    time_interval_unit: str,
    step: str,
    source_metadata: str = None,
    include_bad_data: bool = False,
    window_length: int = 1,
    pivot: bool = False,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A function that receives a dataframe of raw tag data and performs a time weighted averages.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .time_weighted_average(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            start_date="2023-01-01",
            end_date="2023-01-31",
            time_interval_rate="15",
            time_interval_unit="minute",
            step="true",
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        time_interval_rate (str): The time interval rate (numeric input)
        time_interval_unit (str): The time interval unit (second, minute, day, hour)
        step (str): data points with step "enabled" or "disabled". The options for step are "true", "false" or "metadata". "metadata" will retrieve the step value from the metadata table
        source_metadata (optional str): if step is set to "metadata", then this parameter must be populated with the source containing the tagname metadata with a column called "Step"
        include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
        window_length (optional int): Add longer window time in days for the start or end of specified date to cater for edge cases
        pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe of time weighted averages timeseries data
    """
    time_weighted_average_parameters = {
        "source": self.data_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "include_bad_data": include_bad_data,
        "time_interval_rate": time_interval_rate,
        "time_interval_unit": time_interval_unit,
        "step": step,
        "source_metadata": (
            None
            if source_metadata is None
            else "`.`".join(source_metadata.split("."))
        ),
        "window_length": window_length,
        "pivot": pivot,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "supress_warning": True,
    }

    return time_weighted_average.get(
        self.connection, time_weighted_average_parameters
    )

metadata(tagname_filter=None, limit=None, offset=None)

A query to retrieve metadata.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .metadata(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

None
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of metadata

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
def metadata(
    self,
    tagname_filter: [str] = None,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A query to retrieve metadata.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .metadata(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe of metadata
    """
    metadata_parameters = {
        "source": self.data_source,
        "tag_names": [] if tagname_filter is None else tagname_filter,
        "tagname_column": self.tagname_column,
        "limit": limit,
        "offset": offset,
        "supress_warning": True,
    }

    return metadata.get(self.connection, metadata_parameters)

latest(tagname_filter=None, limit=None, offset=None)

A query to retrieve latest event_values.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .latest(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

None
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of events latest_values

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
def latest(
    self,
    tagname_filter: [str] = None,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A query to retrieve latest event_values.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .latest(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe of events latest_values
    """
    latest_parameters = {
        "source": self.data_source,
        "tag_names": [] if tagname_filter is None else tagname_filter,
        "tagname_column": self.tagname_column,
        "limit": limit,
        "offset": offset,
        "supress_warning": True,
    }

    return latest.get(self.connection, latest_parameters)

circular_average(tagname_filter, start_date, end_date, time_interval_rate, time_interval_unit, lower_bound, upper_bound, include_bad_data=False, pivot=False, limit=None, offset=None)

A function that receives a dataframe of raw tag data and computes the circular mean for samples in a range.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .circular_average(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        start_date="2023-01-01",
        end_date="2023-01-31",
        time_interval_rate="15",
        time_interval_unit="minute",
        lower_bound="0",
        upper_bound="360",
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

required
start_date str

Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
end_date str

End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
time_interval_rate str

The time interval rate (numeric input)

required
time_interval_unit str

The time interval unit (second, minute, day, hour)

required
lower_bound int

Lower boundary for the sample range

required
upper_bound int

Upper boundary for the sample range

required
include_bad_data optional bool

Include "Bad" data points with True or remove "Bad" data points with False

False
pivot optional bool

Pivot the data on the timestamp column with True or do not pivot the data with False

False
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe containing the circular averages

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
def circular_average(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    time_interval_rate: str,
    time_interval_unit: str,
    lower_bound: int,
    upper_bound: int,
    include_bad_data: bool = False,
    pivot: bool = False,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A function that receives a dataframe of raw tag data and computes the circular mean for samples in a range.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .circular_average(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            start_date="2023-01-01",
            end_date="2023-01-31",
            time_interval_rate="15",
            time_interval_unit="minute",
            lower_bound="0",
            upper_bound="360",
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        time_interval_rate (str): The time interval rate (numeric input)
        time_interval_unit (str): The time interval unit (second, minute, day, hour)
        lower_bound (int): Lower boundary for the sample range
        upper_bound (int): Upper boundary for the sample range
        include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
        pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe containing the circular averages
    """
    circular_average_parameters = {
        "source": self.data_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "include_bad_data": include_bad_data,
        "time_interval_rate": time_interval_rate,
        "time_interval_unit": time_interval_unit,
        "lower_bound": lower_bound,
        "upper_bound": upper_bound,
        "pivot": pivot,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "supress_warning": True,
    }

    return circular_average.get(self.connection, circular_average_parameters)

circular_standard_deviation(tagname_filter, start_date, end_date, time_interval_rate, time_interval_unit, lower_bound, upper_bound, include_bad_data=False, pivot=False, limit=None, offset=None)

A function that receives a dataframe of raw tag data and computes the circular standard deviation for samples assumed to be in the range.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .circular_standard_deviation(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        start_date="2023-01-01",
        end_date="2023-01-31",
        time_interval_rate="15",
        time_interval_unit="minute",
        lower_bound="0",
        upper_bound="360",
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

required
start_date str

Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
end_date str

End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
time_interval_rate str

The time interval rate (numeric input)

required
time_interval_unit str

The time interval unit (second, minute, day, hour)

required
lower_bound int

Lower boundary for the sample range

required
upper_bound int

Upper boundary for the sample range

required
include_bad_data optional bool

Include "Bad" data points with True or remove "Bad" data points with False

False
pivot optional bool

Pivot the data on the timestamp column with True or do not pivot the data with False

False
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe containing the circular standard deviations

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
def circular_standard_deviation(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    time_interval_rate: str,
    time_interval_unit: str,
    lower_bound: int,
    upper_bound: int,
    include_bad_data: bool = False,
    pivot: bool = False,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A function that receives a dataframe of raw tag data and computes the circular standard deviation for samples assumed to be in the range.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .circular_standard_deviation(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            start_date="2023-01-01",
            end_date="2023-01-31",
            time_interval_rate="15",
            time_interval_unit="minute",
            lower_bound="0",
            upper_bound="360",
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        time_interval_rate (str): The time interval rate (numeric input)
        time_interval_unit (str): The time interval unit (second, minute, day, hour)
        lower_bound (int): Lower boundary for the sample range
        upper_bound (int): Upper boundary for the sample range
        include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
        pivot (optional bool): Pivot the data on the timestamp column with True or do not pivot the data with False
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe containing the circular standard deviations
    """
    circular_stdev_parameters = {
        "source": self.data_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "include_bad_data": include_bad_data,
        "time_interval_rate": time_interval_rate,
        "time_interval_unit": time_interval_unit,
        "lower_bound": lower_bound,
        "upper_bound": upper_bound,
        "pivot": pivot,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "supress_warning": True,
    }

    return circular_standard_deviation.get(
        self.connection, circular_stdev_parameters
    )

summary(tagname_filter, start_date, end_date, include_bad_data=False, limit=None, offset=None)

A function to return back a summary of statistics.

Example:

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import TimeSeriesQueryBuilder

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

data = (
    TimeSeriesQueryBuilder()
    .connect(connection)
    .source("{table_path}")
    .summary(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        start_date="2023-01-01",
        end_date="2023-01-31",
    )
)

display(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

required
start_date str

Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
end_date str

End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
include_bad_data optional bool

Include "Bad" data points with True or remove "Bad" data points with False

False
limit optional int

The number of rows to be returned

None
offset optional int

The number of rows to skip before returning rows

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of raw timeseries data.

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
def summary(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    include_bad_data: bool = False,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A function to return back a summary of statistics.

    **Example:**
    ```python
    from rtdip_sdk.authentication.azure import DefaultAuth
    from rtdip_sdk.connectors import DatabricksSQLConnection
    from rtdip_sdk.queries import TimeSeriesQueryBuilder

    auth = DefaultAuth().authenticate()
    token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
    connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

    data = (
        TimeSeriesQueryBuilder()
        .connect(connection)
        .source("{table_path}")
        .summary(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            start_date="2023-01-01",
            end_date="2023-01-31",
        )
    )

    display(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        include_bad_data (optional bool): Include "Bad" data points with True or remove "Bad" data points with False
        limit (optional int): The number of rows to be returned
        offset (optional int): The number of rows to skip before returning rows

    Returns:
        DataFrame: A dataframe of raw timeseries data.
    """
    summary_parameters = {
        "source": self.data_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "include_bad_data": include_bad_data,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "supress_warning": True,
    }
    return summary.get(self.connection, summary_parameters)