2020-08-24 12:37:19 +02:00
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
|
2020-08-26 19:37:36 +02:00
|
|
|
// const host = 'http://localhost:3000';
|
|
|
|
const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com';
|
2020-08-24 12:37:19 +02:00
|
|
|
|
|
|
|
let errors = [];
|
|
|
|
|
|
|
|
async function fix() {
|
|
|
|
let res = await axios({
|
|
|
|
method: 'get',
|
|
|
|
url: host + '/samples?status[]=new&status[]=validated&status[]=deleted&fields[]=_id&fields[]=number',
|
|
|
|
auth: {
|
|
|
|
username: 'admin',
|
|
|
|
password: 'Abc123!#'
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
if (err.response) {
|
|
|
|
console.error(err.response.data);
|
|
|
|
errors.push(`Could not fetch samples: ${JSON.stringify(err.response.data)}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log(res.data);
|
|
|
|
// for all samples
|
2020-08-26 19:37:36 +02:00
|
|
|
for (let sampleIndex = 2000; sampleIndex < res.data.length; sampleIndex++) {
|
2020-08-24 12:37:19 +02:00
|
|
|
console.log(`SAMPLE ${sampleIndex}/${res.data.length}`);
|
|
|
|
const measurements = await axios({ // get all measurements
|
|
|
|
method: 'get',
|
|
|
|
url: host + '/measurement/sample/' + res.data[sampleIndex]._id,
|
|
|
|
auth: {
|
|
|
|
username: 'admin',
|
|
|
|
password: 'Abc123!#'
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
if (err.response) {
|
|
|
|
console.error(err.response.data);
|
|
|
|
errors.push(`Could not fetch measurements: ${JSON.stringify(err.response.data)}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (measurements && measurements.data) { // found measurements
|
|
|
|
for (let measurementIndex in measurements.data) {
|
|
|
|
console.log(`${measurementIndex}/${measurements.data.length}`);
|
|
|
|
const measurement = measurements.data[measurementIndex];
|
2020-08-26 19:37:36 +02:00
|
|
|
if (measurement.values.hasOwnProperty('dpt') && measurement.values.dpt) { // is spectrum
|
2020-08-24 12:37:19 +02:00
|
|
|
await axios({ // get all measurements
|
|
|
|
method: 'put',
|
|
|
|
url: host + '/measurement/' + measurement._id,
|
|
|
|
auth: {
|
|
|
|
username: 'admin',
|
|
|
|
password: 'Abc123!#'
|
|
|
|
},
|
|
|
|
data: {values: {dpt: measurement.values.dpt
|
|
|
|
.filter(e => e.length === 2)
|
|
|
|
.map(e => e.map(el => parseFloat(el)))
|
|
|
|
}}
|
|
|
|
}).catch(err => {
|
|
|
|
if (err.response) {
|
|
|
|
console.error(err.response.data);
|
|
|
|
errors.push(`Could not save measurements: ${JSON.stringify(err.response.data)}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
fix();
|