Skip to content

Commit f6655b9

Browse files
committed
ADCS JSON issues fixed.
1 parent 269d34f commit f6655b9

5 files changed

Lines changed: 65 additions & 20 deletions

File tree

server/controllers/adcsController.js

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { logInfoMsgPrefix, logWarnMsgPrefix, logErrorMsgPrefix } = require('../utils/utils');
2-
const { magFieldMeasurements, angVelocityMeasurements, adcsTags, magFieldMeasurementsTag, magFieldMeasurementsFields, angVelocityMeasurementsTag, angVelocityMeasurementsFields } = require('../measurements/adcsMeasurements');
3-
2+
const { adcsTags, magFieldMeasurementsTag, magFieldMeasurementsFields, angVelocityMeasurementsTag, angVelocityMeasurementsFields } = require('../measurements/adcsMeasurements');
3+
const angVelocityMeasurements = require('../measurements/adcsMeasurements');
4+
const magFieldMeasurements = require('../measurements/adcsMeasurements');
45
/**
56
* adcs.js
67
* @brief This file contains the controller functions for the ADCS API
@@ -53,22 +54,42 @@ const getMagFieldData = async (req, res) => {
5354
}
5455

5556
try {
56-
const data = await magFieldMeasurements(variant, start, end);
57-
console.log(logInfoMsgPrefix('ADCS magnetic field data fetched successfully'));
58-
res.status(200).json({
59-
variant: variant,
60-
start: start,
61-
end: end,
62-
data: data
57+
const queryResult = await magFieldMeasurements.magFieldMeasurements(variant, start, end);
58+
59+
const merged = {};
60+
61+
queryResult.forEach(item => {
62+
const time = item._time;
63+
64+
if (!merged[time]) {
65+
merged[time] = {
66+
variant: item.variant,
67+
timestamp: time,
68+
LSB: null,
69+
X: null,
70+
Y: null,
71+
Z: null
72+
};
73+
}
74+
75+
const axis = item._field.toUpperCase();
76+
merged[time][axis] = item._value;
77+
6378
});
79+
80+
const finalOutput = Object.values(merged);
81+
console.log(logInfoMsgPrefix('ADCS magnetic field data fetched successfully'));
82+
83+
res.status(200).json(finalOutput);
84+
6485
} catch (error) {
6586
console.error(logErrorMsgPrefix('Error fetching ADCS magnetic field data'), error);
6687
res.status(500).json({ error: 'Internal server error' });
6788
}
6889
};
6990

7091
const getAngVelocityData = async (req, res) => {
71-
console.log(logInfoMsgPrefix('ADCS angular velocityy check'), 'request_body:', req.body);
92+
console.log(logInfoMsgPrefix('ADCS angular velocity check'), 'request_body:', req.body);
7293
const variant = req.params.variant;
7394
let { start, end } = req.query; // extract query parameters
7495

@@ -114,14 +135,33 @@ const getAngVelocityData = async (req, res) => {
114135
}
115136

116137
try {
117-
const data = await angVelocityMeasurements(variant, start, end);
118-
console.log(logInfoMsgPrefix('ADCS angular velocity data fetched successfully'));
119-
res.status(200).json({
120-
variant: variant,
121-
start: start,
122-
end: end,
123-
data: data
138+
const queryResult = await angVelocityMeasurements.angVelocityMeasurements(variant, start, end);
139+
140+
const merged = {};
141+
142+
queryResult.forEach(item => {
143+
const time = item._time;
144+
145+
if (!merged[time]) {
146+
merged[time] = {
147+
variant: item.variant,
148+
timestamp: time,
149+
X: null,
150+
Y: null,
151+
Z: null
152+
};
153+
}
154+
155+
const axis = item._field.toUpperCase();
156+
merged[time][axis] = item._value;
157+
124158
});
159+
160+
const finalOutput = Object.values(merged);
161+
console.log(logInfoMsgPrefix('ADCS angular velocity data fetched successfully'));
162+
163+
res.status(200).json(finalOutput);
164+
125165
} catch (error) {
126166
console.error(logErrorMsgPrefix('Error fetching ADCS angular velocity data'), error);
127167
res.status(500).json({ error: 'Internal server error' });

server/controllers/payloadController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const getWellData = async (req, res, field) => {
6666
timestamp: item._time,
6767
[field]: item._value
6868
}));
69-
69+
7070
res.status(200).json(formattedResult);
7171
console.log(logInfoMsgPrefix(`Well ${field} data fetched successfully: ${wellNum}`));
7272
} catch (error) {

server/measurements/adcsMeasurements.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ async function magFieldMeasurements(variant_num, start, end) {
3333
|> filter(fn: (r) => r["_measurement"] == "${magFieldMeasurementsTag}")
3434
|> filter(fn: (r) => r["host"] == "${adcsTags}")
3535
|> filter(fn: (r) => r["variant"] == "${variant_num}")
36-
|> keep(columns: ["_time", "_value", "variant", _field])
37-
|> group(columns: ["_time])`;
36+
|> keep(columns: ["_time", "_value", "variant", "_field"])
37+
`;
3838
return new Promise((resolve, reject) => {
3939
let result = [];
4040
queryApi.queryRows(query, {

tools/telemetryInputCli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
!examples/data_temp.csv
44
!examples/data_lumin.csv
55
!examples/data_angvel.csv
6+
!examples/data_magField.csv
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variant,timestamp,LSB,X,Y,Z
2+
1,1756749600,65536,4,6,7
3+
1,1756836000,65536,4,7,9
4+
2,1756922400,65536,5,9,2

0 commit comments

Comments
 (0)