add 0 data for temps for consistent empty data handling
This commit is contained in:
1 parent
8fabca9868
commit
82a514f637
1 file changed
+23
-20
@@ -312,7 +312,7 @@ const InfrastructureDetails = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const buildTemps = (checks) => {
|
const buildTemps = (checks) => {
|
||||||
let numCores = 0;
|
let numCores = 1;
|
||||||
if (checks === null) return { temps: [], tempKeys: [] };
|
if (checks === null) return { temps: [], tempKeys: [] };
|
||||||
|
|
||||||
for (const check of checks) {
|
for (const check of checks) {
|
||||||
@@ -321,19 +321,16 @@ const InfrastructureDetails = () => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numCores === 0) return { temps: [], tempKeys: [] };
|
|
||||||
|
|
||||||
const temps = checks.map((check) => {
|
const temps = checks.map((check) => {
|
||||||
if (check.cpu.temperature.length > numCores) {
|
|
||||||
numCores = check.cpu.temperature.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there's no data, set the temperature to 0
|
// If there's no data, set the temperature to 0
|
||||||
if (check.cpu.temperature.length === 0) {
|
if (
|
||||||
|
check?.cpu?.temperature?.length === 0 ||
|
||||||
|
check?.cpu?.temperature === undefined ||
|
||||||
|
check?.cpu?.temperature === null
|
||||||
|
) {
|
||||||
check.cpu.temperature = Array(numCores).fill(0);
|
check.cpu.temperature = Array(numCores).fill(0);
|
||||||
}
|
}
|
||||||
|
const res = check?.cpu?.temperature?.reduce(
|
||||||
return check.cpu.temperature.reduce(
|
|
||||||
(acc, cur, idx) => {
|
(acc, cur, idx) => {
|
||||||
acc[`core${idx + 1}`] = cur;
|
acc[`core${idx + 1}`] = cur;
|
||||||
return acc;
|
return acc;
|
||||||
@@ -342,9 +339,16 @@ const InfrastructureDetails = () => {
|
|||||||
createdAt: check.createdAt,
|
createdAt: check.createdAt,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
return res;
|
||||||
});
|
});
|
||||||
// Slice to remove `createdAt` key
|
if (temps.length === 0 || !temps[0]) {
|
||||||
return { tempKeys: Object.keys(temps[0]).slice(1), temps };
|
return { temps: [], tempKeys: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
tempKeys: Object.keys(temps[0] || {}).filter((key) => key !== "createdAt"),
|
||||||
|
temps,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildAreaChartConfigs = (checks) => {
|
const buildAreaChartConfigs = (checks) => {
|
||||||
@@ -401,10 +405,13 @@ const InfrastructureDetails = () => {
|
|||||||
yLabel: "Temperature",
|
yLabel: "Temperature",
|
||||||
xTick: <TzTick />,
|
xTick: <TzTick />,
|
||||||
yDomain: [
|
yDomain: [
|
||||||
Math.min(...tempData.temps.flatMap((t) => tempData.tempKeys.map((k) => t[k]))) *
|
0,
|
||||||
0.9,
|
Math.max(
|
||||||
Math.max(...tempData.temps.flatMap((t) => tempData.tempKeys.map((k) => t[k]))) *
|
Math.max(
|
||||||
1.1,
|
...tempData.temps.flatMap((t) => tempData.tempKeys.map((k) => t[k]))
|
||||||
|
) * 1.1,
|
||||||
|
200
|
||||||
|
),
|
||||||
],
|
],
|
||||||
toolTip: (
|
toolTip: (
|
||||||
<TemperatureTooltip
|
<TemperatureTooltip
|
||||||
@@ -537,10 +544,6 @@ const InfrastructureDetails = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{areaChartConfigs.map((config) => {
|
{areaChartConfigs.map((config) => {
|
||||||
if (config?.data?.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseBox key={`${config.type}-${config.diskIndex ?? ""}`}>
|
<BaseBox key={`${config.type}-${config.diskIndex ?? ""}`}>
|
||||||
<Typography
|
<Typography
|
||||||
|
|||||||
Reference in new issue
Block a user