Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
616 changes: 616 additions & 0 deletions Untitled.ipynb

Large diffs are not rendered by default.

375 changes: 157 additions & 218 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ classifiers = [


[tool.poetry.dependencies]
python = ">=3.8,<4.0"
python = ">=3.9,<3.13"
grpcio = { version = "^1.51" }
grpcio_tools = { version = "^1.51" }
tqdm = { version = "^4.64" }
protobuf = { version = "^4.21" }
requests = { version = "^2.28" }
pyjwt = { version = "^2.6" }
boto3 = { version = "^1.26" }
pandas = "^2.2.3"
numpy = "1.26.0"

[tool.poetry.group.dev.dependencies]
black = { version = "^23.1" }
Expand Down
3 changes: 3 additions & 0 deletions src/pennsieve/pennsieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .protos import agent_pb2, agent_pb2_grpc
from .protos.agent_pb2_grpc import AgentStub
from .session import APISession, APISessionProvider
from .timeSeries import TimeSeries
from .userProfile import UserProfile

# Set it up to get info messages:
Expand Down Expand Up @@ -109,6 +110,7 @@ def __init__(
self._datasets = None
self.dataset = None
self.manifest = None
self.timeseries = None
if http_api_client is None:
self.http_api = self.build_no_auth_http_api_client()
else:
Expand Down Expand Up @@ -164,6 +166,7 @@ def connect(
)

self.manifest = Manifest(self.stub)
self.timeseries = TimeSeries(self.stub)
print("Please set the dataset with use_dataset([name])")
return self

Expand Down
2 changes: 1 addition & 1 deletion src/pennsieve/protos/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ message GetTimeseriesChannelsResponse {
message GetTimeseriesRangeRequest {
string dataset_id = 1;
string package_id = 2;
string channel_id = 3;
repeated string channel_ids = 3;
float start_time = 4;
float end_time = 5;
bool refresh = 6;
Expand Down
272 changes: 136 additions & 136 deletions src/pennsieve/protos/agent_pb2.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[formatters] reported by reviewdog 🐶

_globals['DESCRIPTOR']._options = None
_globals['DESCRIPTOR']._serialized_options = b'Z+github.com/pennsieve/pennsieve-agent/api/v1'
_globals['_PULLREQUEST']._serialized_start=36
_globals['_PULLREQUEST']._serialized_end=63
_globals['_SUBSCRIBEREQUEST']._serialized_start=65
_globals['_SUBSCRIBEREQUEST']._serialized_end=95
_globals['_RESETCACHEREQUEST']._serialized_start=97
_globals['_RESETCACHEREQUEST']._serialized_end=140
_globals['_GETTIMESERIESCHANNELSREQUEST']._serialized_start=142
_globals['_GETTIMESERIESCHANNELSREQUEST']._serialized_end=229
_globals['_TIMESERIESCHANNEL']._serialized_start=231
_globals['_TIMESERIESCHANNEL']._serialized_end=342
_globals['_GETTIMESERIESCHANNELSRESPONSE']._serialized_start=344
_globals['_GETTIMESERIESCHANNELSRESPONSE']._serialized_end=415
_globals['_GETTIMESERIESRANGEREQUEST']._serialized_start=418
_globals['_GETTIMESERIESRANGEREQUEST']._serialized_end=584
_globals['_GETTIMESERIESRANGERESPONSE']._serialized_start=587
_globals['_GETTIMESERIESRANGERESPONSE']._serialized_end=1140
_globals['_GETTIMESERIESRANGERESPONSE_CHANNELINFO']._serialized_start=855
_globals['_GETTIMESERIESRANGERESPONSE_CHANNELINFO']._serialized_end=930
_globals['_GETTIMESERIESRANGERESPONSE_RANGEDATA']._serialized_start=932
_globals['_GETTIMESERIESRANGERESPONSE_RANGEDATA']._serialized_end=1019
_globals['_GETTIMESERIESRANGERESPONSE_ERRORDATA']._serialized_start=1021
_globals['_GETTIMESERIESRANGERESPONSE_ERRORDATA']._serialized_end=1046
_globals['_GETTIMESERIESRANGERESPONSE_MESSAGETYPE']._serialized_start=1048
_globals['_GETTIMESERIESRANGERESPONSE_MESSAGETYPE']._serialized_end=1124
_globals['_SUBSCRIBERESPONSE']._serialized_start=1143
_globals['_SUBSCRIBERESPONSE']._serialized_end=2249
_globals['_SUBSCRIBERESPONSE_EVENTRESPONSE']._serialized_start=1467
_globals['_SUBSCRIBERESPONSE_EVENTRESPONSE']._serialized_end=1499
_globals['_SUBSCRIBERESPONSE_UPLOADRESPONSE']._serialized_start=1502
_globals['_SUBSCRIBERESPONSE_UPLOADRESPONSE']._serialized_end=1710
_globals['_SUBSCRIBERESPONSE_UPLOADRESPONSE_UPLOADSTATUS']._serialized_start=1655
_globals['_SUBSCRIBERESPONSE_UPLOADRESPONSE_UPLOADSTATUS']._serialized_end=1710
_globals['_SUBSCRIBERESPONSE_DOWNLOADSTATUSRESPONSE']._serialized_start=1713
_globals['_SUBSCRIBERESPONSE_DOWNLOADSTATUSRESPONSE']._serialized_end=1922
_globals['_SUBSCRIBERESPONSE_DOWNLOADSTATUSRESPONSE_DOWNLOADSTATUS']._serialized_start=1865
_globals['_SUBSCRIBERESPONSE_DOWNLOADSTATUSRESPONSE_DOWNLOADSTATUS']._serialized_end=1922
_globals['_SUBSCRIBERESPONSE_SYNCRESPONSE']._serialized_start=1925
_globals['_SUBSCRIBERESPONSE_SYNCRESPONSE']._serialized_end=2110
_globals['_SUBSCRIBERESPONSE_SYNCRESPONSE_SYNCSTATUS']._serialized_start=2057
_globals['_SUBSCRIBERESPONSE_SYNCRESPONSE_SYNCSTATUS']._serialized_end=2110
_globals['_SUBSCRIBERESPONSE_MESSAGETYPE']._serialized_start=2112
_globals['_SUBSCRIBERESPONSE_MESSAGETYPE']._serialized_end=2233
_globals['_SIMPLESTATUSRESPONSE']._serialized_start=2251
_globals['_SIMPLESTATUSRESPONSE']._serialized_end=2289
_globals['_CANCELUPLOADREQUEST']._serialized_start=2291
_globals['_CANCELUPLOADREQUEST']._serialized_end=2353
_globals['_CANCELDOWNLOADREQUEST']._serialized_start=2355
_globals['_CANCELDOWNLOADREQUEST']._serialized_end=2422
_globals['_CREATEMANIFESTREQUEST']._serialized_start=2424
_globals['_CREATEMANIFESTREQUEST']._serialized_end=2526
_globals['_CREATEMANIFESTRESPONSE']._serialized_start=2528
_globals['_CREATEMANIFESTRESPONSE']._serialized_end=2590
_globals['_ADDTOMANIFESTREQUEST']._serialized_start=2592
_globals['_ADDTOMANIFESTREQUEST']._serialized_end=2714
_globals['_REMOVEFROMMANIFESTREQUEST']._serialized_start=2716
_globals['_REMOVEFROMMANIFESTREQUEST']._serialized_end=2785
_globals['_VERSIONREQUEST']._serialized_start=2787
_globals['_VERSIONREQUEST']._serialized_end=2803
_globals['_VERSIONRESPONSE']._serialized_start=2805
_globals['_VERSIONRESPONSE']._serialized_end=2858
_globals['_PINGREQUEST']._serialized_start=2860
_globals['_PINGREQUEST']._serialized_end=2873
_globals['_PINGRESPONSE']._serialized_start=2875
_globals['_PINGRESPONSE']._serialized_end=2906
_globals['_STOPREQUEST']._serialized_start=2908
_globals['_STOPREQUEST']._serialized_end=2921
_globals['_STOPRESPONSE']._serialized_start=2923
_globals['_STOPRESPONSE']._serialized_end=2954
_globals['_LISTMANIFESTSREQUEST']._serialized_start=2956
_globals['_LISTMANIFESTSREQUEST']._serialized_end=2978
_globals['_LISTMANIFESTSRESPONSE']._serialized_start=2981
_globals['_LISTMANIFESTSRESPONSE']._serialized_end=3247
_globals['_LISTMANIFESTSRESPONSE_MANIFEST']._serialized_start=3062
_globals['_LISTMANIFESTSRESPONSE_MANIFEST']._serialized_end=3247
_globals['_DELETEMANIFESTREQUEST']._serialized_start=3249
_globals['_DELETEMANIFESTREQUEST']._serialized_end=3293
_globals['_LISTMANIFESTFILESREQUEST']._serialized_start=3295
_globals['_LISTMANIFESTFILESREQUEST']._serialized_end=3373
_globals['_LISTMANIFESTFILESRESPONSE']._serialized_start=3376
_globals['_LISTMANIFESTFILESRESPONSE']._serialized_end=3776
_globals['_LISTMANIFESTFILESRESPONSE_FILEUPLOAD']._serialized_start=3462
_globals['_LISTMANIFESTFILESRESPONSE_FILEUPLOAD']._serialized_end=3626
_globals['_LISTMANIFESTFILESRESPONSE_STATUSTYPE']._serialized_start=3629
_globals['_LISTMANIFESTFILESRESPONSE_STATUSTYPE']._serialized_end=3776
_globals['_UPLOADMANIFESTREQUEST']._serialized_start=3778
_globals['_UPLOADMANIFESTREQUEST']._serialized_end=3822
_globals['_GETUSERREQUEST']._serialized_start=3824
_globals['_GETUSERREQUEST']._serialized_end=3840
_globals['_USERRESPONSE']._serialized_start=3843
_globals['_USERRESPONSE']._serialized_end=4055
_globals['_SWITCHPROFILEREQUEST']._serialized_start=4057
_globals['_SWITCHPROFILEREQUEST']._serialized_end=4096
_globals['_REAUTHENTICATEREQUEST']._serialized_start=4098
_globals['_REAUTHENTICATEREQUEST']._serialized_end=4121
_globals['_USEDATASETREQUEST']._serialized_start=4123
_globals['_USEDATASETREQUEST']._serialized_end=4162
_globals['_USEDATASETRESPONSE']._serialized_start=4164
_globals['_USEDATASETRESPONSE']._serialized_end=4204
_globals['_SYNCMANIFESTREQUEST']._serialized_start=4206
_globals['_SYNCMANIFESTREQUEST']._serialized_end=4248
_globals['_SYNCMANIFESTRESPONSE']._serialized_start=4250
_globals['_SYNCMANIFESTRESPONSE']._serialized_end=4375
_globals['_RESETMANIFESTREQUEST']._serialized_start=4377
_globals['_RESETMANIFESTREQUEST']._serialized_end=4420
_globals['_RELOCATEMANIFESTFILESREQUEST']._serialized_start=4422
_globals['_RELOCATEMANIFESTFILESREQUEST']._serialized_end=4509
_globals['_STARTWORKFLOWREQUEST']._serialized_start=4511
_globals['_STARTWORKFLOWREQUEST']._serialized_end=4576
_globals['_WORKFLOWRESPONSE']._serialized_start=4579
_globals['_WORKFLOWRESPONSE']._serialized_end=4729
_globals['_WORKFLOWRESPONSE_WORKFLOWTYPE']._serialized_start=4694
_globals['_WORKFLOWRESPONSE_WORKFLOWTYPE']._serialized_end=4729
_globals['_REGISTERREQUEST']._serialized_start=4731
_globals['_REGISTERREQUEST']._serialized_end=4816
_globals['_REGISTERRESPONSE']._serialized_start=4818
_globals['_REGISTERRESPONSE']._serialized_end=4856
_globals['_ACCOUNT']._serialized_start=4858
_globals['_ACCOUNT']._serialized_end=4941
_globals['_ACCOUNT_ACCOUNTTYPE']._serialized_start=4908
_globals['_ACCOUNT_ACCOUNTTYPE']._serialized_end=4941
_globals['_CREDENTIALS']._serialized_start=4943
_globals['_CREDENTIALS']._serialized_end=4973
_globals['_MAPREQUEST']._serialized_start=4975
_globals['_MAPREQUEST']._serialized_end=5030
_globals['_DOWNLOADREQUEST']._serialized_start=5033
_globals['_DOWNLOADREQUEST']._serialized_end=5242
_globals['_DOWNLOADREQUEST_DOWNLOADTYPE']._serialized_start=5194
_globals['_DOWNLOADREQUEST_DOWNLOADTYPE']._serialized_end=5234
_globals['_DOWNLOADDATASETREQUEST']._serialized_start=5244
_globals['_DOWNLOADDATASETREQUEST']._serialized_end=5311
_globals['_DOWNLOADPACKAGEREQUEST']._serialized_start=5313
_globals['_DOWNLOADPACKAGEREQUEST']._serialized_end=5384
_globals['_DOWNLOADRESPONSE']._serialized_start=5387
_globals['_DOWNLOADRESPONSE']._serialized_end=5532
_globals['_DOWNLOADRESPONSE_RESPONSETYPE']._serialized_start=5485
_globals['_DOWNLOADRESPONSE_RESPONSETYPE']._serialized_end=5532
_globals['_MAPDIFFREQUEST']._serialized_start=5534
_globals['_MAPDIFFREQUEST']._serialized_end=5564
_globals['_FILEINFO']._serialized_start=5566
_globals['_FILEINFO']._serialized_end=5641
_globals['_PACKAGESTATUS']._serialized_start=5644
_globals['_PACKAGESTATUS']._serialized_end=5834
_globals['_PACKAGESTATUS_STATUSTYPE']._serialized_start=5742
_globals['_PACKAGESTATUS_STATUSTYPE']._serialized_end=5834
_globals['_MAPDIFFRESPONSE']._serialized_start=5836
_globals['_MAPDIFFRESPONSE']._serialized_end=5887
_globals['_AGENT']._serialized_start=5890
_globals['_AGENT']._serialized_end=7908

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions src/pennsieve/timeSeries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

import numpy as np
import pandas as pd
from .protos import agent_pb2
from .protos.agent_pb2 import GetTimeseriesChannelsResponse
import pandas as pd

class TimeSeries:
"""
A class to represent operations on manifest.

Methods:
--------
create(base_path):
creates a new manifest with file(s) located in base_path
add(manifest_id, base_path, targetBasePath='', recursive=True, files=None):
adds a file(s) from base_path to a manifest with manifest_id
in order to store them at targetBasePath on the server
remove_file(manifest_id, file_id):
removes a file with file_id from manifest with manifest_id
delete(manifest_id):
deletes a manifest with manifest_id
list_manifests():
lists all available manifests
get_manifest(manifest_id=None):
gets the most recent manifest, or the manifest specified by manifest_id
set_manifest(manifest_id=None):
sets the manifest specified by manifest_id
list_files(manifest_id, offset, limit):
lists files for manifest with manifest_id, starting from the number defined by offset
upload(manifest_id):
initiates the upload of files definied in manifest with manifest_id
start_upload(manifest_id):
see: upload(manifest_id)
cancel_upload(manifest_id, cancel_all=True):
cancels the upload session for manifest_id or all upload sessions
relocate_files(manifest_id, path, target_path):
changes the target path of the manifest
sync(manifest_id):
synchronizes the state of the manifest between local and cloud server
reset(manifest_id):
allows users to reset the status for all files in a manifest
"""

def __init__(self, stub):
"""Initialization of the timeseries class.

Parameters:
-----------
stub : object
Stub of an Agent
"""
self._stub = stub

def getChannels(self, dataset_id, package_id, refresh) -> GetTimeseriesChannelsResponse:
request = agent_pb2.GetTimeseriesChannelsRequest(
dataset_id=dataset_id, package_id=package_id, refresh=refresh
)
response = self._stub.GetTimeseriesChannels(request=request)
return response.channel

def getRangeForChannels(
self,
dataset_id,
package_id,
channel_ids,
start_time,
end_time,
is_refresh,
is_relative_time,
):
request = agent_pb2.GetTimeseriesRangeRequest(
dataset_id=dataset_id,
package_id=package_id,
channel_ids=channel_ids,
start_time=start_time,
end_time=end_time,
refresh=is_refresh,
relative_time=is_relative_time,
)

resultMap = {}
for response in self._stub.GetTimeseriesRangeForChannels(request=request):
if response.type == 2:
continue
if response.type == 1:
values = list(response.data.data)
index = np.linspace(response.data.start, response.data.end, len(values))
newVec = pd.Series(values, index=index, name=response.data.channel_id)
if response.data.channel_id in resultMap:
resultMap[response.data.channel_id] = pd.concat(
[resultMap[response.data.channel_id], newVec]
)
else:
resultMap[response.data.channel_id] = newVec

result = pd.DataFrame()
for key in resultMap:
result[key] = resultMap[key]

return result


Comment on lines +102 to +103
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[formatters] reported by reviewdog 🐶

Suggested change