Skip to content

Commit

Permalink
Uploading unit (#1165)
Browse files Browse the repository at this point in the history
* Uploading Unit for Scalar value

* chore: removing log
  • Loading branch information
LatentDream authored Apr 17, 2024
1 parent 6b0dd17 commit 67c55d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions captain/routes/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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}
Expand All @@ -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)}")

Expand Down Expand Up @@ -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()))
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export const postSession = (
pass_: elem.status === "pass",
completionTime: elem.completionTime ?? 0,
createdAt: elem.createdAt!,
unit: elem.unit ?? "",
});
}
});
Expand Down Expand Up @@ -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<typeof Measurement>;

Expand Down

0 comments on commit 67c55d6

Please sign in to comment.