Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set id in Inspection at instantiation of Image etc #181

Merged
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
30 changes: 12 additions & 18 deletions src/isar_robot/inspections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions src/isar_robot/robotinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,17 +16,15 @@
TakeThermalImage,
TakeThermalVideo,
TakeVideo,
Task,
)
from robot_interface.models.robots.media import MediaConfig
from robot_interface.robot_interface import RobotInterface
from robot_interface.telemetry.mqtt_client import MqttTelemetryPublisher

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):
Expand Down
14 changes: 5 additions & 9 deletions tests/test_inspections.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
from alitra import Frame, Position
from robot_interface.models.mission.task import (
RecordAudio,
TakeImage,
TakeThermalVideo,
)
from robot_interface.models.mission.task import RecordAudio, TakeImage, TakeThermalVideo

from isar_robot import inspections

target = Position(x=0, y=0, z=0, frame=Frame("robot"))


def test_create_image():
def test_create_image() -> None:
task_actions = TakeImage(target=target)

inspection_image = inspections.create_image(task_actions)

assert inspection_image.metadata.file_type == "jpg"


def test_create_video():
def test_create_video() -> None:
task_actions = TakeImage(target=target)

inspection_video = inspections.create_video(task_actions)

assert inspection_video.metadata.file_type == "mp4"


def test_create_thermal_video():
def test_create_thermal_video() -> None:
task_actions = TakeThermalVideo(target=target, duration=10)

inspection_video = inspections.create_thermal_video(task_actions)
Expand All @@ -35,7 +31,7 @@ def test_create_thermal_video():
assert inspection_video.metadata.duration == 10


def test_create_audio():
def test_create_audio() -> None:
task_actions = RecordAudio(target=target, duration=10)

inspection_recording = inspections.create_audio(task_actions)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_telemetry.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from isar_robot.telemetry import _get_battery_level, _get_pressure_level


def test_get_battery_level():
def test_get_battery_level() -> None:
for _ in range(100):
pressure_level: float = _get_battery_level()
assert pressure_level >= 50
assert pressure_level <= 100


def test_get_pressure_level():
def test_get_pressure_level() -> None:
for _ in range(100):
pressure_level: float = _get_pressure_level()
assert pressure_level >= 0.011
Expand Down
Loading