Skip to content

Commit

Permalink
Handle the case where the query returns no transparency data
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Nov 21, 2024
1 parent 3de80c9 commit e3a88bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lvmapi/routers/transparency.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TransparencyData(BaseModel):
zero_point: Annotated[float, Field(description="Zero-point value")]


@router.get("/", summary="Transparency measurements")
@router.get("", summary="Transparency measurements")
async def route_get_transparency(
start_time: Annotated[
float | None,
Expand Down
11 changes: 10 additions & 1 deletion src/lvmapi/tools/transparency.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ async def get_transparency(start_time: float, end_time: float):
|> yield(name: "mean")
"""

SCHEMA: dict[str, polars.DataType] = {
"time": polars.Datetime(time_unit="ms", time_zone="UTC"),
"telescope": polars.String(),
"zero_point": polars.Float32(),
}

data = await query_influxdb(query)

if len(data) == 0:
return polars.DataFrame(None, schema=SCHEMA)

# Clean up the dataframe.
data = data.select(
time=polars.col._time,
telescope=polars.col._measurement.str.extract(r"lvm\.([a-z]+)\.guider"),
zero_point=polars.col._value,
)
).cast(SCHEMA) # type: ignore

return data

0 comments on commit e3a88bf

Please sign in to comment.