56 lines
1.1 KiB
TypeScript
56 lines
1.1 KiB
TypeScript
export type ReportTone = "excellent" | "good" | "warning" | "danger";
|
|
|
|
export function getSleepLevel(score: number): { label: string; tone: ReportTone } {
|
|
if (score >= 90) {
|
|
return { label: "优秀", tone: "excellent" };
|
|
}
|
|
|
|
if (score >= 75) {
|
|
return { label: "良好", tone: "good" };
|
|
}
|
|
|
|
if (score >= 60) {
|
|
return { label: "合格", tone: "warning" };
|
|
}
|
|
|
|
return { label: "异常", tone: "danger" };
|
|
}
|
|
|
|
export function getStatusTone(status: string): ReportTone {
|
|
if (status === "正常" || status === "优秀") {
|
|
return "excellent";
|
|
}
|
|
|
|
if (status === "良好") {
|
|
return "good";
|
|
}
|
|
|
|
if (status === "注意" || status === "合格") {
|
|
return "warning";
|
|
}
|
|
|
|
return "danger";
|
|
}
|
|
|
|
export function pickReportRecord<T>(
|
|
records: Record<string, Record<string, Record<string, T>>>,
|
|
dateKey: string,
|
|
roomKey: string,
|
|
deviceKey: string
|
|
): T {
|
|
const rooms = records[dateKey] ?? {};
|
|
const devices = rooms[roomKey] ?? {};
|
|
|
|
if (deviceKey in devices) {
|
|
return devices[deviceKey];
|
|
}
|
|
|
|
const fallback = Object.values(devices)[0];
|
|
|
|
if (!fallback) {
|
|
throw new Error("未找到报告数据");
|
|
}
|
|
|
|
return fallback;
|
|
}
|