Skip to content

Commit

Permalink
fixing telemetry data label (#481)
Browse files Browse the repository at this point in the history
* fixing telemetry data label

* lint fixing
  • Loading branch information
Thibault authored and GitHub committed Aug 7, 2025
1 parent 5d71dcc commit 6c94bfd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 34 deletions.
44 changes: 33 additions & 11 deletions backend/src/api/grafana/controllers/grafana.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ module.exports = {
field: "solarPanelTemp2",
measurement: "fc",
},
{
refId: "solarPanelTemp3",
field: "solarPanelTemp3",
measurement: "fc",
},
{
refId: "solarPanelTemp4",
field: "solarPanelTemp4",
Expand All @@ -42,14 +37,11 @@ module.exports = {
field: "solarPanelTemp5",
measurement: "fc",
},
{
refId: "solarPanelTemp6",
field: "solarPanelTemp6",
measurement: "fc",
},
];
const tempFields = [];
for (let i = 0; i <= 13; i++) {
if (satSQL === "hypso1" && (i === 12 || i === 13)) continue;
if (satSQL === "hypso2" && i === 10) continue;
tempFields.push({
refId: `tempPanelData${i}`,
field: `temp_${i}`,
Expand Down Expand Up @@ -85,11 +77,41 @@ module.exports = {
}

const data = await response.json();
const createNameForTemp = (i) => {
let name = `Panel ${i + 1}`;
if (i <= 3) {
name = `MPPT Conv ${i + 1}`;
} else if (i <= 7) {
name = `OUT Conv ${i + 1 - 4}`;
} else if (satSQL === "hypso1" && i <= 11) {
name = `BP ${i + 1 - 8}`;
} else if (satSQL === "hypso2" && i <= 13) {
if (i <= 9) {
name = `BP ${i + 1 - 8}`;
} else if (i === 11) {
name = "BP 4";
} else if (i >= 12 && i <= 13) {
name = `Ext. Board ${i - 10}`;
}
}
return name;
};

const values = fields.reduce((acc, item) => {
const result = data.results[item.refId];
if (result && result.frames && result.frames.length > 0) {
acc[item.refId] = result.frames[0].data.values; // Store as key-value pair
if (item.refId.startsWith("tempPanelData")) {
// Handle temperature data with specific refId logic
let i = parseInt(item.refId.replace("tempPanelData", ""), 10);
acc[item.refId] = {
array: result.frames[0].data.values,
name: createNameForTemp(i), // Create name based on index
}; // Store as an object with array and panelIndex
} else {
acc[item.refId] = result.frames[0].data.values; // Store as key-value pair
}
}
console.log(acc["tempPanelData10"]);
return acc;
}, {});
// Return the data to the client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function SatTelemetry({
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [data, setData] = useState<any>(null);
// Fetch telemetry data from the backend)

useEffect(() => {
async function fetchTelemetryData() {
Expand Down Expand Up @@ -117,15 +118,26 @@ export default function SatTelemetry({
};

const tempPanelChart = [];
let satName = "";
if (noradID !== undefined) {
satName = satNumToEntry[noradID as SatelliteNumber]?.name || "";
}

for (let i = 0; i <= 13; i++) {
if (satName === "HYPSO-1" && (i === 12 || i === 13)) continue;
if (satName === "HYPSO-2" && i === 10) continue;
// Skip panel 10 for HYPSO-2

const tempData = data?.[`tempPanelData${i}`];
if (tempData && !checkLine(tempData[1])) {
console.log(`tempPanelData${i}`, checkLine(tempData?.array[1]));
// Check if tempData is defined and has
if (tempData && !checkLine(tempData.array[1])) {
tempPanelChart.push({
name: `Panel ${i}`,
data: tempData[0]
name: tempData.name || `Panel ${i}`,
data: tempData.array[0]
.map((timestamp: number, index: number) => [
timestamp,
tempData[1][index], // Assuming you need to divide by 1000
tempData.array[1][index], // Assuming you need to divide by 1000
])
.filter(
([timestamp]: number[]) => timestamp <= currentTime,
Expand All @@ -140,25 +152,21 @@ export default function SatTelemetry({
}

const solarPanelTempData = [
data?.solarPanelTemp1,
data?.solarPanelTemp2,
data?.solarPanelTemp3,
data?.solarPanelTemp4,
data?.solarPanelTemp5,
data?.solarPanelTemp6,
{ array: data?.solarPanelTemp1, panelIndex: "1" },
{ array: data?.solarPanelTemp2, panelIndex: "2" },
{ array: data?.solarPanelTemp4, panelIndex: "4" },
{ array: data?.solarPanelTemp5, panelIndex: "5" },
].filter((temp) => temp); // Filter out any undefined values
const solarPanelChartData = solarPanelTempData.map(
(tempData, panelIndex) => ({
name: `Solar Panel ${panelIndex + 1}`,
data: tempData[0]
.map((timestamp: number, index: number) => [
timestamp,
tempData[1][index], // Assuming you need to divide by 1000
])
.filter(([timestamp]: number[]) => timestamp <= currentTime), // Filter out future timestamps
color: `hsl(${panelIndex * 60}, 70%, 50%)`, // Different color for each panel
}),
);
const solarPanelChartData = solarPanelTempData.map((tempData) => ({
name: `Solar Panel ${tempData.panelIndex}`,
data: tempData.array[0]
.map((timestamp: number, index: number) => [
timestamp,
tempData.array[1][index], // Assuming you need to divide by 1000
])
.filter(([timestamp]: number[]) => timestamp <= currentTime), // Filter out future timestamps
color: `hsl(${parseInt(tempData.panelIndex) * 60}, 70%, 50%)`, // Different color for each panel
}));

{
/* Uptime Data */
Expand Down Expand Up @@ -198,7 +206,7 @@ export default function SatTelemetry({
},

{
title: "EPS Solar Panel Temperatures",
title: "FC Solar Panel Temperatures",
yAxisTitle: "Temperature (°C)",
series: solarPanelChartData,
valueSuffix: " °C",
Expand Down

0 comments on commit 6c94bfd

Please sign in to comment.