ecopipeline 0.8.10__py3-none-any.whl → 0.8.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ecopipeline/extract/extract.py +98 -75
- {ecopipeline-0.8.10.dist-info → ecopipeline-0.8.12.dist-info}/METADATA +1 -1
- {ecopipeline-0.8.10.dist-info → ecopipeline-0.8.12.dist-info}/RECORD +6 -6
- {ecopipeline-0.8.10.dist-info → ecopipeline-0.8.12.dist-info}/WHEEL +0 -0
- {ecopipeline-0.8.10.dist-info → ecopipeline-0.8.12.dist-info}/licenses/LICENSE +0 -0
- {ecopipeline-0.8.10.dist-info → ecopipeline-0.8.12.dist-info}/top_level.txt +0 -0
ecopipeline/extract/extract.py
CHANGED
|
@@ -767,7 +767,8 @@ def pull_egauge_data(config: ConfigManager, eGauge_ids: list, eGauge_usr : str,
|
|
|
767
767
|
|
|
768
768
|
os.chdir(original_directory)
|
|
769
769
|
|
|
770
|
-
def tb_api_to_df(config: ConfigManager, startTime: datetime = None, endTime: datetime = None, create_csv : bool = True, query_hours :
|
|
770
|
+
def tb_api_to_df(config: ConfigManager, startTime: datetime = None, endTime: datetime = None, create_csv : bool = True, query_hours : float = 1,
|
|
771
|
+
sensor_keys : list = [], seperate_keys : bool = False):
|
|
771
772
|
"""
|
|
772
773
|
Function connects to the things board manager api to pull data and returns a dataframe.
|
|
773
774
|
|
|
@@ -785,7 +786,7 @@ def tb_api_to_df(config: ConfigManager, startTime: datetime = None, endTime: dat
|
|
|
785
786
|
is local time from the data's index.
|
|
786
787
|
create_csv : bool
|
|
787
788
|
create csv files as you process such that API need not be relied upon for reprocessing
|
|
788
|
-
query_hours :
|
|
789
|
+
query_hours : float
|
|
789
790
|
number of hours to query at a time from ThingsBoard API
|
|
790
791
|
|
|
791
792
|
Returns
|
|
@@ -794,80 +795,102 @@ def tb_api_to_df(config: ConfigManager, startTime: datetime = None, endTime: dat
|
|
|
794
795
|
Pandas Dataframe containing data from the API pull with column headers the same as the variable names in the data from the pull.
|
|
795
796
|
Will return with index in UTC so needs to be converted after to appropriate timezone
|
|
796
797
|
"""
|
|
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
|
-
if len(keys) <= 0:
|
|
824
|
-
raise Exception(f"No sensors available at ThingsBoard site with id {config.api_device_id}")
|
|
825
|
-
key_string = ','.join(keys)
|
|
826
|
-
params = {
|
|
827
|
-
'keys': key_string,
|
|
828
|
-
'startTs': f'{int(startTime.timestamp())*1000}',
|
|
829
|
-
'endTs': f'{int(endTime.timestamp())*1000}',
|
|
830
|
-
'orderBy': 'ASC',
|
|
831
|
-
'useStrictDataTypes': 'false'
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
# Headers
|
|
835
|
-
headers = {
|
|
836
|
-
'accept': 'application/json',
|
|
837
|
-
'X-Authorization': f'Bearer {token}'
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
try:
|
|
841
|
-
response = requests.get(url, headers=headers, params=params)
|
|
842
|
-
if response.status_code == 200:
|
|
843
|
-
response_json = response.json()
|
|
844
|
-
data = {}
|
|
845
|
-
for key, records in response_json.items():
|
|
846
|
-
try:
|
|
847
|
-
series = pd.Series(
|
|
848
|
-
data={record['ts']: float(record['value']) for record in records}
|
|
849
|
-
)
|
|
850
|
-
data[key] = series
|
|
851
|
-
except:
|
|
852
|
-
print_statement = f"Could not convert {key} values to floats."
|
|
853
|
-
# print(print_statement)
|
|
854
|
-
df = pd.DataFrame(data)
|
|
855
|
-
df.index = pd.to_datetime(df.index, unit='ms')
|
|
798
|
+
df = pd.DataFrame()
|
|
799
|
+
if len(sensor_keys) <= 0:
|
|
800
|
+
token = config.get_thingsboard_token()
|
|
801
|
+
key_list = _get_tb_keys(config, token)
|
|
802
|
+
if len(key_list) <= 0:
|
|
803
|
+
raise Exception(f"No sensors available at ThingsBoard site with id {config.api_device_id}")
|
|
804
|
+
return tb_api_to_df(config, startTime, endTime, create_csv, query_hours, key_list, seperate_keys)
|
|
805
|
+
if seperate_keys:
|
|
806
|
+
df_list = []
|
|
807
|
+
for sensor_key in sensor_keys:
|
|
808
|
+
df_list.append(tb_api_to_df(config, startTime, endTime, False, query_hours, [sensor_key], False))
|
|
809
|
+
df = pd.concat(df_list)
|
|
810
|
+
else:
|
|
811
|
+
# not seperate_keys:
|
|
812
|
+
if endTime is None:
|
|
813
|
+
endTime = datetime.now()
|
|
814
|
+
if startTime is None:
|
|
815
|
+
# 28 hours to ensure encapsulation of last day
|
|
816
|
+
startTime = endTime - timedelta(hours=28)
|
|
817
|
+
|
|
818
|
+
if endTime - timedelta(hours=query_hours) > startTime:
|
|
819
|
+
time_diff = endTime - startTime
|
|
820
|
+
midpointTime = startTime + time_diff / 2
|
|
821
|
+
df_1 = tb_api_to_df(config, startTime, midpointTime, query_hours=query_hours, sensor_keys=sensor_keys, create_csv=False)#True if startTime >= datetime(2025,7,13,9) and startTime <= datetime(2025,7,13,10) else csv_pass_down)
|
|
822
|
+
df_2 = tb_api_to_df(config, midpointTime, endTime, query_hours=query_hours, sensor_keys=sensor_keys,create_csv=False)#True if endTime >= datetime(2025,7,13,9) and endTime <= datetime(2025,7,13,10) else csv_pass_down)
|
|
823
|
+
df = pd.concat([df_1, df_2])
|
|
856
824
|
df = df.sort_index()
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
825
|
+
df = df.groupby(df.index).mean()
|
|
826
|
+
else:
|
|
827
|
+
url = f'https://thingsboard.cloud/api/plugins/telemetry/DEVICE/{config.api_device_id}/values/timeseries'
|
|
828
|
+
token = config.get_thingsboard_token()
|
|
829
|
+
key_string = ','.join(sensor_keys)
|
|
830
|
+
params = {
|
|
831
|
+
'keys': key_string,
|
|
832
|
+
'startTs': f'{int(startTime.timestamp())*1000}',
|
|
833
|
+
'endTs': f'{int(endTime.timestamp())*1000}',
|
|
834
|
+
'orderBy': 'ASC',
|
|
835
|
+
'useStrictDataTypes': 'false',
|
|
836
|
+
'interval' : '0',
|
|
837
|
+
'agg' : 'NONE'
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
# Headers
|
|
841
|
+
headers = {
|
|
842
|
+
'accept': 'application/json',
|
|
843
|
+
'X-Authorization': f'Bearer {token}'
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
try:
|
|
847
|
+
response = requests.get(url, headers=headers, params=params)
|
|
848
|
+
if response.status_code == 200:
|
|
849
|
+
response_json = response.json()
|
|
850
|
+
# if create_csv:
|
|
851
|
+
# json_filename = f"{startTime.strftime('%Y%m%d%H%M%S')}.json"
|
|
852
|
+
# print(f"filename: {json_filename}, url: {url}, params: {params}")
|
|
853
|
+
# original_directory = os.getcwd()
|
|
854
|
+
# os.chdir(config.data_directory)
|
|
855
|
+
# with open(json_filename, 'w') as f:
|
|
856
|
+
# json.dump(response_json, f, indent=4) # indent=4 makes it human-readable
|
|
857
|
+
# os.chdir(original_directory)
|
|
858
|
+
|
|
859
|
+
data = {}
|
|
860
|
+
for key, records in response_json.items():
|
|
861
|
+
try:
|
|
862
|
+
series = pd.Series(
|
|
863
|
+
data={record['ts']: _get_float_value(record['value']) for record in records}
|
|
864
|
+
)
|
|
865
|
+
data[key] = series
|
|
866
|
+
except:
|
|
867
|
+
print_statement = f"Could not convert {key} values to floats."
|
|
868
|
+
print(print_statement)
|
|
869
|
+
df = pd.DataFrame(data)
|
|
870
|
+
df.index = pd.to_datetime(df.index, unit='ms')
|
|
871
|
+
df = df.sort_index()
|
|
872
|
+
else:
|
|
873
|
+
print(f"Failed to make GET request. Status code: {response.status_code} {response.json()}")
|
|
874
|
+
df = pd.DataFrame()
|
|
875
|
+
except Exception as e:
|
|
876
|
+
traceback.print_exc()
|
|
877
|
+
print(f"An error occurred: {e}")
|
|
878
|
+
df = pd.DataFrame()
|
|
879
|
+
# save to file
|
|
880
|
+
if create_csv:
|
|
881
|
+
filename = f"{startTime.strftime('%Y%m%d%H%M%S')}.csv"
|
|
882
|
+
original_directory = os.getcwd()
|
|
883
|
+
os.chdir(config.data_directory)
|
|
884
|
+
df.to_csv(filename, index_label='time_pt')
|
|
885
|
+
os.chdir(original_directory)
|
|
886
|
+
return df
|
|
887
|
+
|
|
888
|
+
def _get_float_value(value):
|
|
889
|
+
try:
|
|
890
|
+
ret_val = float(value)
|
|
891
|
+
return ret_val
|
|
892
|
+
except (ValueError, TypeError):
|
|
893
|
+
return None
|
|
871
894
|
|
|
872
895
|
def _get_tb_keys(config: ConfigManager, token : str) -> List[str]:
|
|
873
896
|
url = f'https://thingsboard.cloud/api/plugins/telemetry/DEVICE/{config.api_device_id}/keys/timeseries'
|
|
@@ -2,7 +2,7 @@ ecopipeline/__init__.py,sha256=d48mO5La6OrQDkRe_qqoY6lUx7x-e8krOH388jmWjwU,218
|
|
|
2
2
|
ecopipeline/event_tracking/__init__.py,sha256=q49j46fXMUjNUPzL4FvXEppB93i3lUni-QUZpp61tt0,64
|
|
3
3
|
ecopipeline/event_tracking/event_tracking.py,sha256=LOCLE7ju320O7CrwnWRIqHRa2uAqoq-KvXZ3zWQ2S74,13224
|
|
4
4
|
ecopipeline/extract/__init__.py,sha256=gQ3sak6NJ63Gpo-hZXrtZfeKOTHLRyAVXfTgxxRpqPo,675
|
|
5
|
-
ecopipeline/extract/extract.py,sha256=
|
|
5
|
+
ecopipeline/extract/extract.py,sha256=i5e-mL4KiJfmWMFnKwvCW_BdPELGJiYKRk6FbvcEi1U,51106
|
|
6
6
|
ecopipeline/load/__init__.py,sha256=NLa_efQJZ8aP-J0Y5xx9DP7mtfRH9jY6Jz1ZMZN_BAA,292
|
|
7
7
|
ecopipeline/load/load.py,sha256=Ptxr0MOjns_HeVSmZsLLApHJGB-z6XOB2m8LNiVaD7E,23860
|
|
8
8
|
ecopipeline/transform/__init__.py,sha256=hYb4F64fXdXtjBSYCqv6gLFBwKZjjnl0z7s291pFE98,2505
|
|
@@ -12,8 +12,8 @@ ecopipeline/transform/transform.py,sha256=S8fpAb45XBcYzeGNkxELiHM8-1jlNQqADV7_m-
|
|
|
12
12
|
ecopipeline/utils/ConfigManager.py,sha256=-g1wtExdvhYO5Y6Q3cRbywa__DxRMFruLrB4YanwaPY,12168
|
|
13
13
|
ecopipeline/utils/__init__.py,sha256=ccWUR0m7gD9DfcgsxBCLOfi4lho6RdYuB2Ugy_g6ZdQ,28
|
|
14
14
|
ecopipeline/utils/unit_convert.py,sha256=VFh1we2Y8KV3u21BeWb-U3TlZJXo83q5vdxxkpgcuME,3064
|
|
15
|
-
ecopipeline-0.8.
|
|
16
|
-
ecopipeline-0.8.
|
|
17
|
-
ecopipeline-0.8.
|
|
18
|
-
ecopipeline-0.8.
|
|
19
|
-
ecopipeline-0.8.
|
|
15
|
+
ecopipeline-0.8.12.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
ecopipeline-0.8.12.dist-info/METADATA,sha256=j4dFIoOVhvTICE2htIZhbUJPZmE6lpVuWDGk33BdBNc,2330
|
|
17
|
+
ecopipeline-0.8.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
18
|
+
ecopipeline-0.8.12.dist-info/top_level.txt,sha256=WOPFJH2LIgKqm4lk2OnFF5cgVkYibkaBxIxgvLgO7y0,12
|
|
19
|
+
ecopipeline-0.8.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|