Skip to content

Commit

Permalink
Update RobotDBModel to reflect changes in API-spec
Browse files Browse the repository at this point in the history
  • Loading branch information
vetlek committed Apr 12, 2022
1 parent 2222b36 commit 6100203
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
56 changes: 28 additions & 28 deletions backend/src/flotilla/database/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ def read_event_by_id(db: Session, event_id: int) -> EventDBModel:
return event


def create_report(
def read_events_by_robot_id_and_time_span(
db: Session,
robot_id: int,
isar_mission_id: str,
echo_mission_id: int,
report_status: ReportStatus,
) -> int:
report: ReportDBModel = ReportDBModel(
robot_id=robot_id,
isar_mission_id=isar_mission_id,
echo_mission_id=echo_mission_id,
log="",
status=report_status,
start_time: datetime,
end_time: datetime,
) -> List[EventDBModel]:
return (
db.query(EventDBModel)
.filter(EventDBModel.robot_id == robot_id)
.filter(
and_(
EventDBModel.start_time < end_time,
EventDBModel.end_time > start_time,
)
)
.all()
)
db.add(report)
db.commit()
return report.id


def create_event(
Expand Down Expand Up @@ -111,20 +111,20 @@ def remove_event(db: Session, event_id: int) -> None:
return


def read_events_by_robot_id_and_time_span(
def create_report(
db: Session,
robot_id: int,
start_time: datetime,
end_time: datetime,
) -> List[EventDBModel]:
return (
db.query(EventDBModel)
.filter(EventDBModel.robot_id == robot_id)
.filter(
and_(
EventDBModel.start_time < end_time,
EventDBModel.end_time > start_time,
)
)
.all()
isar_mission_id: str,
echo_mission_id: int,
report_status: ReportStatus,
) -> int:
report: ReportDBModel = ReportDBModel(
robot_id=robot_id,
isar_mission_id=isar_mission_id,
echo_mission_id=echo_mission_id,
log="",
status=report_status,
)
db.add(report)
db.commit()
return report.id
16 changes: 15 additions & 1 deletion backend/src/flotilla/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
from flotilla_openapi.models.report import Report
from flotilla_openapi.models.report_entry import ReportEntry
from flotilla_openapi.models.robot import Robot
from sqlalchemy import Column, DateTime, Enum, ForeignKey, Integer, Interval, String
from sqlalchemy import (
Boolean,
Column,
DateTime,
Enum,
ForeignKey,
Integer,
Interval,
String,
)
from sqlalchemy.orm import backref, relationship

from flotilla.database.db import Base
Expand Down Expand Up @@ -49,6 +58,7 @@ class RobotDBModel(Base):
status = Column(Enum(RobotStatus))
host = Column(String)
port = Column(Integer)
enabled = Column(Boolean, default=True)
telemetry_topics = relationship("TopicDBModel", backref=backref("robot"))
streams = relationship("VideoStreamDBModel", backref=backref("robot"))
capabilities = relationship("CapabilityDBModel", backref=backref("robot"))
Expand All @@ -61,6 +71,10 @@ def get_api_robot(self) -> Robot:
model=self.model,
status=self.status.value,
capabilities=[cap.capability.value for cap in self.capabilities],
serial_number=self.serial_number,
host=self.host,
port=self.port,
enabled=self.enabled,
)


Expand Down
2 changes: 1 addition & 1 deletion backend/tests/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_read_event_by_id(event_id: int, session):


@pytest.mark.parametrize(
"start_time,duration,expected_len",
"start_time, duration, expected_len",
[
(datetime.now(tz=timezone.utc), timedelta(hours=1.5), 1),
(
Expand Down

0 comments on commit 6100203

Please sign in to comment.