diff --git a/backend/src/api/grafana/controllers/grafana.js b/backend/src/api/grafana/controllers/grafana.js index 90b5ef3..1560f47 100644 --- a/backend/src/api/grafana/controllers/grafana.js +++ b/backend/src/api/grafana/controllers/grafana.js @@ -27,11 +27,6 @@ module.exports = { field: "solarPanelTemp2", measurement: "fc", }, - { - refId: "solarPanelTemp3", - field: "solarPanelTemp3", - measurement: "fc", - }, { refId: "solarPanelTemp4", field: "solarPanelTemp4", @@ -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}`, @@ -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 diff --git a/frontend/src/app/satellites/[satelliteSlug]/_infoSat/satTelemetry.tsx b/frontend/src/app/satellites/[satelliteSlug]/_infoSat/satTelemetry.tsx index 58cedbc..06c5759 100644 --- a/frontend/src/app/satellites/[satelliteSlug]/_infoSat/satTelemetry.tsx +++ b/frontend/src/app/satellites/[satelliteSlug]/_infoSat/satTelemetry.tsx @@ -21,6 +21,7 @@ export default function SatTelemetry({ const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [data, setData] = useState(null); + // Fetch telemetry data from the backend) useEffect(() => { async function fetchTelemetryData() { @@ -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, @@ -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 */ @@ -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",