Skip to content

Commit

Permalink
fetch report from kes
Browse files Browse the repository at this point in the history
  • Loading branch information
naushadmohammed committed Jun 12, 2024
1 parent e59af05 commit e6c5d41
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@
del parent_table[0]
parent_row = CategoryParentAssetRow(relationship=ref)
parent_table.append_row(parent_row)

#download report and save it to a file
with open("report.docx", "wb") as binary_file:
binary_file.write(activity.download_report())
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = kes-RHDHV
version = 1.dev9
version = 1.dev10
author = RoyalHaskoningDHV
author_email = [email protected]
description = KES python client
Expand Down
2 changes: 1 addition & 1 deletion src/kes/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ def open_activity_by_id(self, activity_id: UUID = os.getenv('ACTIVITY_ID', ''))
Returns:
An instance representing the requested Kes Activity.
"""
return Activity(self._table_stub, activity_id, "")
return Activity(self._table_stub, activity_id, "", self._project_stub)
23 changes: 20 additions & 3 deletions src/kes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


from functools import cached_property
from typing import List
from typing import List, Optional, ByteString
from uuid import UUID

from kes.proto.project_pb2 import ReadActivitiesReply, ReadActivitiesRequest
from kes.proto.project_pb2 import ReadActivitiesReply, ReadActivitiesRequest, DownloadReportRequest
from kes.proto.project_pb2_grpc import ProjectDetailStub
from kes.proto.table_pb2_grpc import TableStub
from kes.table import RowType, Table, TableDef
Expand All @@ -24,11 +24,13 @@ class Activity:
_id: UUID
_description: str
_stub: TableStub
_project_stub: ProjectDetailStub

def __init__(self, stub: TableStub, id: UUID, description: str):
def __init__(self, stub: TableStub, id: UUID, description: str, project_stub: ProjectDetailStub):
self._id = id
self._stub = stub
self._description = description
self._project_stub = project_stub

def build_table(self, table_def: TableDef[RowType]) -> Table[RowType]:
""" Create a table for this activity.
Expand All @@ -48,6 +50,21 @@ def build_table(self, table_def: TableDef[RowType]) -> Table[RowType]:
table_def.property_map
)

def download_report(self) -> Optional[ByteString]:
""" Download Report for the activity.
Returns:
Activity Report.
"""
reportData = bytearray()
request = DownloadReportRequest(activityId=str(self._id))
streamingReply = self._project_stub.downloadReport(request)

for reply in streamingReply:
reportData += reply.chunk

return reportData

@property
def id(self) -> UUID:
"""uuid: id of the activity."""
Expand Down

0 comments on commit e6c5d41

Please sign in to comment.