From 03e367ca30be3341dd0c68fdd3ae13d5dced8118 Mon Sep 17 00:00:00 2001 From: Thomas Sundvoll <35451859+tsundvoll@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:01:56 +0100 Subject: [PATCH] Set id in Inspection at instantiation of Image etc to be equal the incoming task.inspection_id --- src/isar_robot/inspections.py | 30 ++++++++++++------------------ src/isar_robot/robotinterface.py | 7 ++----- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/isar_robot/inspections.py b/src/isar_robot/inspections.py index 022dbd0..0d65fdc 100644 --- a/src/isar_robot/inspections.py +++ b/src/isar_robot/inspections.py @@ -40,7 +40,7 @@ ) -def create_image(task_actions: Union[TakeImage, TakeThermalImage]): +def create_image(task_actions: Union[TakeImage, TakeThermalImage]) -> Image: now: datetime = datetime.utcnow() image_metadata: ImageMetadata = ImageMetadata( start_time=now, @@ -51,15 +51,13 @@ def create_image(task_actions: Union[TakeImage, TakeThermalImage]): image_metadata.analysis_type = ["test1", "test2"] image_metadata.additional = task_actions.metadata - image: Image = Image(metadata=image_metadata) - filepath: Path = random.choice(list(example_images.iterdir())) - image.data = _read_data_from_file(filepath) + data = _read_data_from_file(filepath) - return image + return Image(metadata=image_metadata, id=task_actions.inspection_id, data=data) -def create_video(task_actions: TakeVideo): +def create_video(task_actions: TakeVideo) -> Video: now: datetime = datetime.utcnow() video_metadata: VideoMetadata = VideoMetadata( start_time=now, @@ -71,12 +69,10 @@ def create_video(task_actions: TakeVideo): video_metadata.analysis_type = ["test1", "test2"] video_metadata.additional = task_actions.metadata - video: Video = Video(metadata=video_metadata) - filepath: Path = random.choice(list(example_videos.iterdir())) - video.data = _read_data_from_file(filepath) + data = _read_data_from_file(filepath) - return video + return Video(metadata=video_metadata, id=task_actions.inspection_id, data=data) def create_thermal_video(task_actions: TakeThermalVideo): @@ -91,12 +87,12 @@ def create_thermal_video(task_actions: TakeThermalVideo): thermal_video_metadata.analysis_type = ["test1", "test2"] thermal_video_metadata.additional = task_actions.metadata - thermal_video: ThermalVideo = ThermalVideo(metadata=thermal_video_metadata) - filepath: Path = random.choice(list(example_thermal_videos.iterdir())) - thermal_video.data = _read_data_from_file(filepath) + data = _read_data_from_file(filepath) - return thermal_video + return ThermalVideo( + metadata=thermal_video_metadata, id=task_actions.inspection_id, data=data + ) def create_audio(task_actions: RecordAudio): @@ -111,12 +107,10 @@ def create_audio(task_actions: RecordAudio): audio_metadata.analysis_type = ["test1", "test2"] audio_metadata.additional = task_actions.metadata - audio: Audio = Audio(metadata=audio_metadata) - filepath: Path = random.choice(list(example_thermal_videos.iterdir())) - audio.data = _read_data_from_file(filepath) + data = _read_data_from_file(filepath) - return audio + return Audio(metadata=audio_metadata, id=task_actions.inspection_id, data=data) def _read_data_from_file(filename: Path) -> bytes: diff --git a/src/isar_robot/robotinterface.py b/src/isar_robot/robotinterface.py index d83ddf5..86d5bd4 100644 --- a/src/isar_robot/robotinterface.py +++ b/src/isar_robot/robotinterface.py @@ -8,7 +8,6 @@ from robot_interface.models.initialize import InitializeParams from robot_interface.models.inspection.inspection import Inspection from robot_interface.models.mission.mission import Mission -from robot_interface.models.mission.task import Task from robot_interface.models.mission.status import RobotStatus, TaskStatus from robot_interface.models.mission.task import ( InspectionTask, @@ -17,6 +16,7 @@ TakeThermalImage, TakeThermalVideo, TakeVideo, + Task, ) from robot_interface.models.robots.media import MediaConfig from robot_interface.robot_interface import RobotInterface @@ -24,10 +24,7 @@ from isar_robot import inspections, telemetry from isar_robot.config.settings import settings -from isar_robot.utilities import ( - is_localization_task, - is_return_to_home_task, -) +from isar_robot.utilities import is_localization_task, is_return_to_home_task class Robot(RobotInterface):