diff --git a/captain/routes/cloud.py b/captain/routes/cloud.py index 5c501b21d..5d4fae934 100644 --- a/captain/routes/cloud.py +++ b/captain/routes/cloud.py @@ -144,6 +144,7 @@ class Measurement(BaseModel): pass_: Optional[bool] completion_time: float = Field(..., alias="completionTime") created_at: str = Field(..., alias="createdAt") + unit: str class Session(BaseModel): @@ -160,7 +161,7 @@ class Session(BaseModel): MeasurementType = Literal["boolean", "dataframe", "scalar"] -def make_payload(data: MeasurementData): +def make_payload(data: MeasurementData, unit: str): match data: case bool(): return {"type": "boolean", "value": data} @@ -172,7 +173,7 @@ def make_payload(data: MeasurementData): return {"type": "dataframe", "value": value} case int() | float(): - return {"type": "scalar", "value": data} + return {"type": "scalar", "value": data, "unit": unit} case _: raise TypeError(f"Unsupported data type: {type(data)}") @@ -277,9 +278,10 @@ async def post_cloud_session(_: Response, body: Session): payload = body.model_dump(by_alias=True) payload["createdAt"] = utcnow_str() for i, m in enumerate(payload["measurements"]): - m["data"] = make_payload(get_measurement(body.measurements[i])) + m["data"] = make_payload(get_measurement(body.measurements[i]), m["unit"]) m["pass"] = m.pop("pass_") m["durationMs"] = int(m.pop("completionTime") * 1000) + del m["unit"] response = requests.post(url, json=payload, headers=headers_builder()) if response.status_code == 200: return Response(status_code=200, content=json.dumps(response.json())) diff --git a/src/renderer/lib/api.ts b/src/renderer/lib/api.ts index bbdb942a6..e8049c9e8 100644 --- a/src/renderer/lib/api.ts +++ b/src/renderer/lib/api.ts @@ -234,6 +234,7 @@ export const postSession = ( pass_: elem.status === "pass", completionTime: elem.completionTime ?? 0, createdAt: elem.createdAt!, + unit: elem.unit ?? "", }); } }); @@ -263,6 +264,7 @@ const Measurement = z.object({ pass_: z.boolean().optional(), completionTime: z.number(), createdAt: z.string(), + unit: z.string(), }); export type Measurement = z.infer;