Skip to content

Commit

Permalink
delete recording implementation with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Chafetz committed Aug 29, 2023
1 parent 7cf3207 commit 17d3e52
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 125 deletions.
256 changes: 131 additions & 125 deletions foxglove_data_platform/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def decoder(message_content: bytes):

T = TypeVar("T")


try:
from mcap_ros1.decoder import DecoderFactory as Ros1DecoderFactory

Expand Down Expand Up @@ -100,9 +99,9 @@ class OutputFormat(Enum):

class ProgressBufferReader(IO[Any]):
def __init__(
self,
buf: Union[bytes, IO[Any]],
callback: Optional[SizeProgressCallback] = None,
self,
buf: Union[bytes, IO[Any]],
callback: Optional[SizeProgressCallback] = None,
):
self.__callback = callback
self.__progress = 0
Expand Down Expand Up @@ -148,9 +147,9 @@ def json_or_raise(response: requests.Response):


def _download_stream_with_progress(
url: str,
headers: Optional[dict] = None,
callback: Optional[ProgressCallback] = None,
url: str,
headers: Optional[dict] = None,
callback: Optional[ProgressCallback] = None,
):
response = requests.get(url, headers=headers, stream=True)
response.raise_for_status()
Expand All @@ -175,13 +174,13 @@ def __url__(self, path: str):
return f"https://{self.__host}{path}"

def create_event(
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: datetime.datetime,
end: Optional[datetime.datetime],
metadata: Optional[Dict[str, str]] = {},
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: datetime.datetime,
end: Optional[datetime.datetime],
metadata: Optional[Dict[str, str]] = {},
):
"""
Creates a new event.
Expand Down Expand Up @@ -215,9 +214,9 @@ def create_event(
return _event_dict(json_or_raise(response))

def delete_event(
self,
*,
event_id: str,
self,
*,
event_id: str,
):
"""
Deletes an event.
Expand All @@ -231,17 +230,17 @@ def delete_event(
return json_or_raise(response)

def get_events(
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
sort_by: Optional[str] = None,
sort_order: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
start: Optional[datetime.datetime] = None,
end: Optional[datetime.datetime] = None,
query: Optional[str] = None,
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
sort_by: Optional[str] = None,
sort_order: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
start: Optional[datetime.datetime] = None,
end: Optional[datetime.datetime] = None,
query: Optional[str] = None,
):
"""
Retrieves events.
Expand Down Expand Up @@ -278,14 +277,14 @@ def get_events(
return [_event_dict(event) for event in json_or_raise(response)]

def get_messages(
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: datetime.datetime,
end: datetime.datetime,
topics: List[str] = [],
decoder_factories: Optional[List[DecoderFactory]] = None,
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: datetime.datetime,
end: datetime.datetime,
topics: List[str] = [],
decoder_factories: Optional[List[DecoderFactory]] = None,
):
"""
Returns a list of tuples of (topic, raw mcap record, decoded message).
Expand Down Expand Up @@ -319,12 +318,12 @@ def get_messages(
]

def download_recording_data(
self,
*,
id: str,
output_format: OutputFormat = OutputFormat.mcap0,
include_attachments: bool = False,
callback: Optional[ProgressCallback] = None,
self,
*,
id: str,
output_format: OutputFormat = OutputFormat.mcap0,
include_attachments: bool = False,
callback: Optional[ProgressCallback] = None,
):
"""
Returns raw data bytes for a recording.
Expand All @@ -351,15 +350,15 @@ def download_recording_data(
return _download_stream_with_progress(json["link"], callback=callback)

def download_data(
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: datetime.datetime,
end: datetime.datetime,
topics: List[str] = [],
output_format: OutputFormat = OutputFormat.mcap0,
callback: Optional[ProgressCallback] = None,
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: datetime.datetime,
end: datetime.datetime,
topics: List[str] = [],
output_format: OutputFormat = OutputFormat.mcap0,
callback: Optional[ProgressCallback] = None,
) -> bytes:
"""
Returns raw data bytes for a device and time range.
Expand Down Expand Up @@ -391,13 +390,13 @@ def download_data(
return _download_stream_with_progress(json["link"], callback=callback)

def get_coverage(
self,
*,
start: datetime.datetime,
end: datetime.datetime,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
tolerance: Optional[int] = None,
self,
*,
start: datetime.datetime,
end: datetime.datetime,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
tolerance: Optional[int] = None,
):
"""
List coverage ranges for data.
Expand Down Expand Up @@ -433,7 +432,7 @@ def get_coverage(
]

def get_device(
self, *, device_id: Optional[str] = None, device_name: Optional[str] = None
self, *, device_id: Optional[str] = None, device_name: Optional[str] = None
):
"""
Gets a single device by name or id.
Expand Down Expand Up @@ -479,10 +478,10 @@ def get_devices(self):
]

def create_device(
self,
*,
name: str,
properties: Optional[Dict[str, Union[str, bool, float, int]]] = None,
self,
*,
name: str,
properties: Optional[Dict[str, Union[str, bool, float, int]]] = None,
):
"""
Creates a new device.
Expand All @@ -507,12 +506,12 @@ def create_device(
}

def update_device(
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
new_name: Optional[str] = None,
properties: Optional[Dict[str, Union[str, bool, float, int]]] = None,
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
new_name: Optional[str] = None,
properties: Optional[Dict[str, Union[str, bool, float, int]]] = None,
):
"""
Updates a device.
Expand Down Expand Up @@ -544,7 +543,7 @@ def update_device(
}

def delete_device(
self, *, device_id: Optional[str] = None, device_name: Optional[str] = None
self, *, device_id: Optional[str] = None, device_name: Optional[str] = None
):
"""
Deletes an existing device.
Expand Down Expand Up @@ -577,20 +576,27 @@ def delete_import(self, *, device_id: Optional[str] = None, import_id: str):
)
json_or_raise(response)

def delete_recording(self, *, recording_id: str):
response = requests.delete(
self.__url__(f"/recordings/{recording_id}"),
headers=self.__headers
)
json_or_raise(response)

def get_imports(
self,
*,
device_id: Optional[str] = None,
start: Optional[datetime.datetime] = None,
end: Optional[datetime.datetime] = None,
data_start: Optional[datetime.datetime] = None,
data_end: Optional[datetime.datetime] = None,
include_deleted: bool = False,
filename: Optional[str] = None,
sort_by: Optional[str] = None,
sort_order: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
self,
*,
device_id: Optional[str] = None,
start: Optional[datetime.datetime] = None,
end: Optional[datetime.datetime] = None,
data_start: Optional[datetime.datetime] = None,
data_end: Optional[datetime.datetime] = None,
include_deleted: bool = False,
filename: Optional[str] = None,
sort_by: Optional[str] = None,
sort_order: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
):
"""
Fetches imports.
Expand Down Expand Up @@ -644,20 +650,20 @@ def get_imports(
]

def get_recordings(
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: Optional[datetime.datetime] = None,
end: Optional[datetime.datetime] = None,
path: Optional[str] = None,
site_id: Optional[str] = None,
edge_site_id: Optional[str] = None,
import_status: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
sort_by: Optional[str] = None,
sort_order: Optional[str] = None,
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: Optional[datetime.datetime] = None,
end: Optional[datetime.datetime] = None,
path: Optional[str] = None,
site_id: Optional[str] = None,
edge_site_id: Optional[str] = None,
import_status: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
sort_by: Optional[str] = None,
sort_order: Optional[str] = None,
):
"""Fetches recordings.
Expand Down Expand Up @@ -724,16 +730,16 @@ def get_recordings(
return out

def get_attachments(
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
recording_id: Optional[str] = None,
site_id: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
sort_by: Optional[str] = None,
sort_order: Optional[str] = None,
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
recording_id: Optional[str] = None,
site_id: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
sort_by: Optional[str] = None,
sort_order: Optional[str] = None,
):
"""List recording attachments.
Expand Down Expand Up @@ -781,10 +787,10 @@ def get_attachments(
]

def download_attachment(
self,
*,
id: str,
callback: Optional[ProgressCallback] = None,
self,
*,
id: str,
callback: Optional[ProgressCallback] = None,
):
"""Download an attachment by ID.
Expand All @@ -799,13 +805,13 @@ def download_attachment(
)

def get_topics(
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: datetime.datetime,
end: datetime.datetime,
include_schemas: bool = False,
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
start: datetime.datetime,
end: datetime.datetime,
include_schemas: bool = False,
):
response = requests.get(
self.__url__("/v1/data/topics"),
Expand Down Expand Up @@ -836,13 +842,13 @@ def get_topics(
return results

def upload_data(
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
filename: str,
data: Union[bytes, IO[Any]],
callback: Optional[SizeProgressCallback] = None,
self,
*,
device_id: Optional[str] = None,
device_name: Optional[str] = None,
filename: str,
data: Union[bytes, IO[Any]],
callback: Optional[SizeProgressCallback] = None,
):
"""
Uploads data in bytes.
Expand Down
Loading

0 comments on commit 17d3e52

Please sign in to comment.