Skip to content

Commit

Permalink
Merge branch 'koonpeng/hammer-jazzy-base' into ac/fix-build
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Jul 18, 2024
2 parents 4484e98 + c55d86f commit 98180a6
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 189 deletions.
80 changes: 40 additions & 40 deletions packages/api-client/lib/openapi/api.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/api-client/lib/version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// THIS FILE IS GENERATED
export const version = {
rmfServer: 'd027eea607b0ccbd8ce18ec320fb83b06ea6aa3e',
rmfServer: '4484e98b95f71637026e2ce89d14d31033e5d615',
openapiGenerator: '',
};
30 changes: 15 additions & 15 deletions packages/api-client/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,39 +890,39 @@ export default {
in: 'query',
required: false,
schema: {
type: 'string',
anyOf: [{ type: 'string' }, { type: 'null' }],
description:
'\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
title: 'Request Time Between',
},
description:
'\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
},
{
name: 'start_time_between',
in: 'query',
required: false,
schema: {
type: 'string',
anyOf: [{ type: 'string' }, { type: 'null' }],
description:
'\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
title: 'Start Time Between',
},
description:
'\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
},
{
name: 'finish_time_between',
in: 'query',
required: false,
schema: {
type: 'string',
anyOf: [{ type: 'string' }, { type: 'null' }],
description:
'\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
title: 'Finish Time Between',
},
description:
'\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
},
{
name: 'limit',
Expand Down Expand Up @@ -1078,14 +1078,14 @@ export default {
in: 'query',
required: false,
schema: {
type: 'string',
anyOf: [{ type: 'string' }, { type: 'null' }],
description:
'\n The period of time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n "-60000" - Fetches logs in the last minute.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
default: '-60000',
title: 'Between',
},
description:
'\n The period of time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n "-60000" - Fetches logs in the last minute.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
},
{
name: 'authorization',
Expand Down Expand Up @@ -2113,14 +2113,14 @@ export default {
in: 'query',
required: false,
schema: {
type: 'string',
anyOf: [{ type: 'string' }, { type: 'null' }],
description:
'\n The period of time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n "-60000" - Fetches logs in the last minute.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
default: '-60000',
title: 'Between',
},
description:
'\n The period of time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n "-60000" - Fetches logs in the last minute.\n ',
'\n The period of request time to fetch, in unix millis.\n\n This can be either a comma separated string or a string prefixed with \'-\' to fetch the last X millis.\n\n Example:\n "1000,2000" - Fetch resources between unix millis 1000 and 2000.\n "-60000" - Fetch resources in the last minute.\n ',
},
{
name: 'authorization',
Expand Down
47 changes: 13 additions & 34 deletions packages/api-server/api_server/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from fastapi import Depends, Query

Expand All @@ -24,58 +24,37 @@ def pagination_query(
)


def between_query(
between: str = Query(
"-60000",
description="""
The period of time to fetch, in unix millis.
This can be either a comma separated string or a string prefixed with '-' to fetch the last X millis.
Example:
"1000,2000" - Fetches logs between unix millis 1000 and 2000.
"-60000" - Fetches logs in the last minute.
""",
),
now: int = Depends(ros_time.now),
) -> tuple[int, int]:
if between.startswith("-"):
period = (now - int(between[1:]), now)
else:
parts = between.split(",")
period = (int(parts[0]), int(parts[1]))
return period


def time_between_query(alias: str):
def time_between_query(alias: str, *, default: str | None = None):
def dep(
time_between: str = Query(
None,
time_between: str | None = Query(
default,
alias=alias,
description="""
The period of request time to fetch, in unix millis.
This must be a comma separated string, 'X,Y' to fetch between X millis and Y millis inclusive.
This can be either a comma separated string or a string prefixed with '-' to fetch the last X millis.
Example:
"1000,2000" - Fetches logs between unix millis 1000 and 2000.
"1000,2000" - Fetch resources between unix millis 1000 and 2000.
"-60000" - Fetch resources in the last minute.
""",
),
now: int = Depends(ros_time.now),
) -> tuple[datetime, datetime] | None:
if time_between is None:
return None
if time_between.startswith("-"):
# Cap at 0 millis
period = (
datetime.fromtimestamp(0),
datetime.fromtimestamp(now / 1000),
datetime.fromtimestamp(
(now - int(time_between[1:])) / 1000, timezone.utc
),
datetime.fromtimestamp(now / 1000, timezone.utc),
)
else:
parts = time_between.split(",")
period = (
datetime.fromtimestamp(int(parts[0]) / 1000),
datetime.fromtimestamp(int(parts[1]) / 1000),
datetime.fromtimestamp(int(parts[0]) / 1000, timezone.utc),
datetime.fromtimestamp(int(parts[1]) / 1000, timezone.utc),
)
return period

Expand Down
4 changes: 2 additions & 2 deletions packages/api-server/api_server/fast_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from fastapi.exceptions import HTTPException
from fastapi.requests import HTTPConnection
from fastapi.routing import APIRoute
from reactivex import Observable, of
from reactivex import Observable
from reactivex.abc import DisposableBase
from starlette.routing import compile_path

Expand Down Expand Up @@ -243,7 +243,7 @@ def _match_routes(
return match, r
return None

async def _on_connect(self, sid: str, environ: dict, auth: dict | None):
async def _on_connect(self, sid: str, environ: dict, auth: dict | None = None):
logger = get_logger(HTTPConnection(environ))
user = (
await self._socketio_connect(sid, environ, auth)
Expand Down
15 changes: 9 additions & 6 deletions packages/api-server/api_server/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ def __init__(
ros_node: rclpy.node.Node,
rmf_events: RmfEvents,
rmf_repo: RmfRepository,
loop: asyncio.AbstractEventLoop,
*,
logger: logging.Logger | None = None,
):
self._cached_files = cached_files
self._ros_node = ros_node
self._rmf_events = rmf_events
self._rmf_repo = rmf_repo
self._loop = loop
self._logger = logger or logging.getLogger()

self._door_req = self._ros_node.create_publisher(
Expand Down Expand Up @@ -171,7 +173,7 @@ async def save(door_state: DoorState):
self._rmf_events.door_states.on_next(door_state)
logging.debug("%s", door_state)

asyncio.create_task(save(DoorState.model_validate(msg)))
self._loop.create_task(save(DoorState.model_validate(msg)))

door_states_sub = self._ros_node.create_subscription(
RmfDoorState,
Expand All @@ -188,7 +190,7 @@ async def save(lift_state: LiftState):
logging.debug("%s", lift_state)

dic = message_to_ordereddict(msg)
asyncio.create_task(save(LiftState(**dic)))
self._loop.create_task(save(LiftState(**dic)))

lift_states_sub = self._ros_node.create_subscription(
RmfLiftState,
Expand All @@ -204,7 +206,7 @@ async def save(dispenser_state: DispenserState):
self._rmf_events.dispenser_states.on_next(dispenser_state)
logging.debug("%s", dispenser_state)

asyncio.create_task(save(DispenserState.model_validate(msg)))
self._loop.create_task(save(DispenserState.model_validate(msg)))

dispenser_states_sub = self._ros_node.create_subscription(
RmfDispenserState,
Expand All @@ -220,7 +222,7 @@ async def save(ingestor_state: IngestorState):
self._rmf_events.ingestor_states.on_next(ingestor_state)
logging.debug("%s", ingestor_state)

asyncio.create_task(save(IngestorState.model_validate(msg)))
self._loop.create_task(save(IngestorState.model_validate(msg)))

ingestor_states_sub = self._ros_node.create_subscription(
RmfIngestorState,
Expand All @@ -237,7 +239,7 @@ async def save(building_map: BuildingMap):
logging.debug("%s", building_map)

bm = self._process_building_map(cast(RmfBuildingMap, msg))
asyncio.create_task(save(bm))
self._loop.create_task(save(bm))

map_sub = self._ros_node.create_subscription(
RmfBuildingMap,
Expand Down Expand Up @@ -266,7 +268,7 @@ async def save(beachandle_state: BeaconState):
activated=msg.activated,
level=msg.level,
)
asyncio.create_task(save(bs))
self._loop.create_task(save(bs))

beachandle_sub = self._ros_node.create_subscription(
RmfBeaconState,
Expand Down Expand Up @@ -407,4 +409,5 @@ def get_rmf_gateway():
get_ros_node(),
get_rmf_events(),
RmfRepository(User.get_system_user()),
asyncio.get_event_loop(),
)
4 changes: 2 additions & 2 deletions packages/api-server/api_server/repositories/alerts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import datetime
from datetime import datetime, timezone

from fastapi import Depends

Expand Down Expand Up @@ -66,7 +66,7 @@ async def acknowledge_alert(self, alert_id: str) -> Alert | None:
return acknowledged_alert_pydantic

ack_time = datetime.now()
epoch = datetime.fromtimestamp(0)
epoch = datetime.fromtimestamp(0, timezone.utc)
ack_unix_millis = round((ack_time - epoch).total_seconds() * 1000)
new_id = f"{alert_id}__{ack_unix_millis}"

Expand Down
14 changes: 9 additions & 5 deletions packages/api-server/api_server/repositories/fleets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from typing import Annotated, Sequence, cast

from fastapi import Depends
Expand Down Expand Up @@ -32,15 +33,18 @@ async def get_fleet_state(self, name: str) -> FleetState | None:
return FleetState(**cast(dict, result.data))

async def get_fleet_log(
self, name: str, between: tuple[int, int]
self, name: str, between: tuple[datetime, datetime] | None
) -> FleetLog | None:
"""
:param between: The period in unix millis to fetch.
"""
between_filters = {
"unix_millis_time__gte": between[0],
"unix_millis_time__lte": between[1],
}
if between:
between_filters = {
"unix_millis_time__gte": between[0].timestamp() * 1000,
"unix_millis_time__lte": between[1].timestamp() * 1000,
}
else:
between_filters = {}
result = cast(
ttm.FleetLog | None,
await ttm.FleetLog.get_or_none(name=name).prefetch_related(
Expand Down
Loading

0 comments on commit 98180a6

Please sign in to comment.