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
  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
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
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
    metadata_source: str
    metadata_tagname_column: str
    metadata_uom_column: str

    def __init__(self):
        self.metadata_source = None
        self.metadata_tagname_column = None
        self.metadata_uom_column = None

    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="{tablename_or_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 m_source(
        self,
        metadata_source: str,
        metadata_tagname_column: str = "TagName",
        metadata_uom_column: str = "UoM",
    ):
        """
        Specifies the Metadata source of the query. This is only required if display_uom is set to True or Step is set to "metadata". Otherwise, it is optional.

        **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="{tablename_or_path}"
            )
            .m_source(
                metadata_source="{metadata_table_or_path}"
                metadata_tagname_column="TagName",
                metadata_uom_column="UoM")
        )

        ```

        Args:
            metadata_source (str): Source of the query can be a Unity Catalog table, Hive metastore table or path
            metadata_tagname_column (optional str): The column name in the source that contains the tagnames or series
            metadata_uom_column (optional str): The column name in the source that contains the unit of measure
        """
        self.metadata_source = "`.`".join(metadata_source.split("."))
        self.metadata_tagname_column = metadata_tagname_column
        self.metadata_uom_column = metadata_uom_column
        return self

    def raw(
        self,
        tagname_filter: [str],
        start_date: str,
        end_date: str,
        include_bad_data: bool = False,
        display_uom: 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("{tablename_or_path}")
            .raw(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                start_date="2023-01-01",
                end_date="2023-01-31",
            )
        )

        print(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
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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,
            "metadata_source": self.metadata_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "include_bad_data": include_bad_data,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if "display_uom" in raw_parameters and raw_parameters["display_uom"] is True:
            if raw_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        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,
        display_uom: 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("{tablename_or_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",
            )
        )

        print(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
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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,
            "metadata_source": self.metadata_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,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if (
            "display_uom" in resample_parameters
            and resample_parameters["display_uom"] is True
        ):
            if resample_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        return resample.get(self.connection, resample_parameters)

    def plot(
        self,
        tagname_filter: [str],
        start_date: str,
        end_date: str,
        time_interval_rate: str,
        time_interval_unit: str,
        include_bad_data: bool = False,
        pivot: bool = False,
        display_uom: bool = False,
        limit: int = None,
        offset: int = None,
    ) -> DataFrame:
        """
        A query to plot the source data for a time interval for Min, Max, First, Last and an Exception Value(Status = Bad), if it exists.

        **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("{tablename_or_path}")
            .plot(
                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",
            )
        )

        print(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)
            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
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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.
        """

        plot_parameters = {
            "source": self.data_source,
            "metadata_source": self.metadata_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "time_interval_rate": time_interval_rate,
            "time_interval_unit": time_interval_unit,
            "include_bad_data": include_bad_data,
            "pivot": pivot,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if "display_uom" in plot_parameters and plot_parameters["display_uom"] is True:
            if plot_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        return plot.get(self.connection, plot_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,
        display_uom: 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("{tablename_or_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",
            )
        )

        print(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
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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,
            "metadata_source": self.metadata_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,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if (
            "display_uom" in interpolation_parameters
            and interpolation_parameters["display_uom"] is True
        ):
            if interpolation_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        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,
        display_uom: 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("{tablename_or_path}")
            .interpolation_at_time(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                timestamp_filter=["2023-01-01T09:30:00", "2023-01-02T12:00:00"],
            )
        )

        print(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
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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,
            "metadata_source": self.metadata_source,
            "tag_names": tagname_filter,
            "timestamps": timestamp_filter,
            "include_bad_data": include_bad_data,
            "window_length": window_length,
            "pivot": pivot,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if (
            "display_uom" in interpolation_at_time_parameters
            and interpolation_at_time_parameters["display_uom"] is True
        ):
            if interpolation_at_time_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        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,
        display_uom: 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("{tablename_or_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",
            )
        )

        print(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
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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,
            "metadata_source": self.metadata_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,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if (
            "display_uom" in time_weighted_average_parameters
            and time_weighted_average_parameters["display_uom"] is True
        ):
            if time_weighted_average_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        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("{tablename_or_path}")
            .metadata(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            )
        )

        print(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,
        display_uom: bool = False,
        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("{tablename_or_path}")
            .latest(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            )
        )

        print(data)

        ```

        Args:
            tagname_filter (list str): List of tagnames to filter on the source
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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,
            "metadata_source": self.metadata_source,
            "tag_names": [] if tagname_filter is None else tagname_filter,
            "tagname_column": self.tagname_column,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if (
            "display_uom" in latest_parameters
            and latest_parameters["display_uom"] is True
        ):
            if latest_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        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,
        display_uom: 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("{tablename_or_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",
            )
        )

        print(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
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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,
            "metadata_source": self.metadata_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,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if (
            "display_uom" in circular_average_parameters
            and circular_average_parameters["display_uom"] is True
        ):
            if circular_average_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        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,
        display_uom: 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("{tablename_or_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",
            )
        )

        print(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
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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,
            "metadata_source": self.metadata_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,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if (
            "display_uom" in circular_stdev_parameters
            and circular_stdev_parameters["display_uom"] is True
        ):
            if circular_stdev_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        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,
        display_uom: 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("{tablename_or_path}")
            .summary(
                tagname_filter=["{tag_name_1}", "{tag_name_2}"],
                start_date="2023-01-01",
                end_date="2023-01-31",
            )
        )

        print(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
            display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
            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,
            "metadata_source": self.metadata_source,
            "tag_names": tagname_filter,
            "start_date": start_date,
            "end_date": end_date,
            "include_bad_data": include_bad_data,
            "display_uom": display_uom,
            "limit": limit,
            "offset": offset,
            "tagname_column": self.tagname_column,
            "timestamp_column": self.timestamp_column,
            "status_column": self.status_column,
            "value_column": self.value_column,
            "metadata_tagname_column": self.metadata_tagname_column,
            "metadata_uom_column": self.metadata_uom_column,
            "supress_warning": True,
        }

        if (
            "display_uom" in summary_parameters
            and summary_parameters["display_uom"] is True
        ):
            if summary_parameters["metadata_source"] is None:
                raise ValueError(
                    "display_uom True requires metadata_source to be populated"
                )

        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
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
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="{tablename_or_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
 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
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="{tablename_or_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

m_source(metadata_source, metadata_tagname_column='TagName', metadata_uom_column='UoM')

Specifies the Metadata source of the query. This is only required if display_uom is set to True or Step is set to "metadata". Otherwise, it is optional.

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="{tablename_or_path}"
    )
    .m_source(
        metadata_source="{metadata_table_or_path}"
        metadata_tagname_column="TagName",
        metadata_uom_column="UoM")
)

Parameters:

Name Type Description Default
metadata_source str

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

required
metadata_tagname_column optional str

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

'TagName'
metadata_uom_column optional str

The column name in the source that contains the unit of measure

'UoM'
Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
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
def m_source(
    self,
    metadata_source: str,
    metadata_tagname_column: str = "TagName",
    metadata_uom_column: str = "UoM",
):
    """
    Specifies the Metadata source of the query. This is only required if display_uom is set to True or Step is set to "metadata". Otherwise, it is optional.

    **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="{tablename_or_path}"
        )
        .m_source(
            metadata_source="{metadata_table_or_path}"
            metadata_tagname_column="TagName",
            metadata_uom_column="UoM")
    )

    ```

    Args:
        metadata_source (str): Source of the query can be a Unity Catalog table, Hive metastore table or path
        metadata_tagname_column (optional str): The column name in the source that contains the tagnames or series
        metadata_uom_column (optional str): The column name in the source that contains the unit of measure
    """
    self.metadata_source = "`.`".join(metadata_source.split("."))
    self.metadata_tagname_column = metadata_tagname_column
    self.metadata_uom_column = metadata_uom_column
    return self

raw(tagname_filter, start_date, end_date, include_bad_data=False, display_uom=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("{tablename_or_path}")
    .raw(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        start_date="2023-01-01",
        end_date="2023-01-31",
    )
)

print(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
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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
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
def raw(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    include_bad_data: bool = False,
    display_uom: 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("{tablename_or_path}")
        .raw(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            start_date="2023-01-01",
            end_date="2023-01-31",
        )
    )

    print(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
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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,
        "metadata_source": self.metadata_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "include_bad_data": include_bad_data,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if "display_uom" in raw_parameters and raw_parameters["display_uom"] is True:
        if raw_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    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, display_uom=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("{tablename_or_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",
    )
)

print(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
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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
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
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,
    display_uom: 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("{tablename_or_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",
        )
    )

    print(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
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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,
        "metadata_source": self.metadata_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,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if (
        "display_uom" in resample_parameters
        and resample_parameters["display_uom"] is True
    ):
        if resample_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    return resample.get(self.connection, resample_parameters)

plot(tagname_filter, start_date, end_date, time_interval_rate, time_interval_unit, include_bad_data=False, pivot=False, display_uom=False, limit=None, offset=None)

A query to plot the source data for a time interval for Min, Max, First, Last and an Exception Value(Status = Bad), if it exists.

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("{tablename_or_path}")
    .plot(
        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",
    )
)

print(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
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
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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
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
def plot(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    time_interval_rate: str,
    time_interval_unit: str,
    include_bad_data: bool = False,
    pivot: bool = False,
    display_uom: bool = False,
    limit: int = None,
    offset: int = None,
) -> DataFrame:
    """
    A query to plot the source data for a time interval for Min, Max, First, Last and an Exception Value(Status = Bad), if it exists.

    **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("{tablename_or_path}")
        .plot(
            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",
        )
    )

    print(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)
        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
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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.
    """

    plot_parameters = {
        "source": self.data_source,
        "metadata_source": self.metadata_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "time_interval_rate": time_interval_rate,
        "time_interval_unit": time_interval_unit,
        "include_bad_data": include_bad_data,
        "pivot": pivot,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if "display_uom" in plot_parameters and plot_parameters["display_uom"] is True:
        if plot_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    return plot.get(self.connection, plot_parameters)

interpolate(tagname_filter, start_date, end_date, time_interval_rate, time_interval_unit, agg_method, interpolation_method, include_bad_data=False, pivot=False, display_uom=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("{tablename_or_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",
    )
)

print(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
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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
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
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,
    display_uom: 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("{tablename_or_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",
        )
    )

    print(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
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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,
        "metadata_source": self.metadata_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,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if (
        "display_uom" in interpolation_parameters
        and interpolation_parameters["display_uom"] is True
    ):
        if interpolation_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    return interpolate.get(self.connection, interpolation_parameters)

interpolation_at_time(tagname_filter, timestamp_filter, include_bad_data=False, window_length=1, pivot=False, display_uom=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("{tablename_or_path}")
    .interpolation_at_time(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        timestamp_filter=["2023-01-01T09:30:00", "2023-01-02T12:00:00"],
    )
)

print(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
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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
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
def interpolation_at_time(
    self,
    tagname_filter: [str],
    timestamp_filter: [str],
    include_bad_data: bool = False,
    window_length: int = 1,
    pivot: bool = False,
    display_uom: 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("{tablename_or_path}")
        .interpolation_at_time(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            timestamp_filter=["2023-01-01T09:30:00", "2023-01-02T12:00:00"],
        )
    )

    print(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
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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,
        "metadata_source": self.metadata_source,
        "tag_names": tagname_filter,
        "timestamps": timestamp_filter,
        "include_bad_data": include_bad_data,
        "window_length": window_length,
        "pivot": pivot,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if (
        "display_uom" in interpolation_at_time_parameters
        and interpolation_at_time_parameters["display_uom"] is True
    ):
        if interpolation_at_time_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    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, display_uom=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("{tablename_or_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",
    )
)

print(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
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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
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
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,
    display_uom: 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("{tablename_or_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",
        )
    )

    print(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
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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,
        "metadata_source": self.metadata_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,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if (
        "display_uom" in time_weighted_average_parameters
        and time_weighted_average_parameters["display_uom"] is True
    ):
        if time_weighted_average_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    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("{tablename_or_path}")
    .metadata(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
    )
)

print(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
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
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("{tablename_or_path}")
        .metadata(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        )
    )

    print(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, display_uom=False, 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("{tablename_or_path}")
    .latest(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
    )
)

print(data)

Parameters:

Name Type Description Default
tagname_filter list str

List of tagnames to filter on the source

None
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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 events latest_values

Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_series_query_builder.py
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
def latest(
    self,
    tagname_filter: [str] = None,
    display_uom: bool = False,
    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("{tablename_or_path}")
        .latest(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        )
    )

    print(data)

    ```

    Args:
        tagname_filter (list str): List of tagnames to filter on the source
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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,
        "metadata_source": self.metadata_source,
        "tag_names": [] if tagname_filter is None else tagname_filter,
        "tagname_column": self.tagname_column,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if (
        "display_uom" in latest_parameters
        and latest_parameters["display_uom"] is True
    ):
        if latest_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    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, display_uom=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("{tablename_or_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",
    )
)

print(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
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
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,
    display_uom: 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("{tablename_or_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",
        )
    )

    print(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
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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,
        "metadata_source": self.metadata_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,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if (
        "display_uom" in circular_average_parameters
        and circular_average_parameters["display_uom"] is True
    ):
        if circular_average_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    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, display_uom=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("{tablename_or_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",
    )
)

print(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
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
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,
    display_uom: 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("{tablename_or_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",
        )
    )

    print(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
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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,
        "metadata_source": self.metadata_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,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if (
        "display_uom" in circular_stdev_parameters
        and circular_stdev_parameters["display_uom"] is True
    ):
        if circular_stdev_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    return circular_standard_deviation.get(
        self.connection, circular_stdev_parameters
    )

summary(tagname_filter, start_date, end_date, include_bad_data=False, display_uom=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("{tablename_or_path}")
    .summary(
        tagname_filter=["{tag_name_1}", "{tag_name_2}"],
        start_date="2023-01-01",
        end_date="2023-01-31",
    )
)

print(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
display_uom optional bool

Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated

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
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
def summary(
    self,
    tagname_filter: [str],
    start_date: str,
    end_date: str,
    include_bad_data: bool = False,
    display_uom: 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("{tablename_or_path}")
        .summary(
            tagname_filter=["{tag_name_1}", "{tag_name_2}"],
            start_date="2023-01-01",
            end_date="2023-01-31",
        )
    )

    print(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
        display_uom (optional bool): Display the unit of measure with True or False. Defaults to False. If True, metadata_source must be populated
        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,
        "metadata_source": self.metadata_source,
        "tag_names": tagname_filter,
        "start_date": start_date,
        "end_date": end_date,
        "include_bad_data": include_bad_data,
        "display_uom": display_uom,
        "limit": limit,
        "offset": offset,
        "tagname_column": self.tagname_column,
        "timestamp_column": self.timestamp_column,
        "status_column": self.status_column,
        "value_column": self.value_column,
        "metadata_tagname_column": self.metadata_tagname_column,
        "metadata_uom_column": self.metadata_uom_column,
        "supress_warning": True,
    }

    if (
        "display_uom" in summary_parameters
        and summary_parameters["display_uom"] is True
    ):
        if summary_parameters["metadata_source"] is None:
            raise ValueError(
                "display_uom True requires metadata_source to be populated"
            )

    return summary.get(self.connection, summary_parameters)