Browse Source

sorting pluviometer data in chart according to collection date and time

master
analuizaff 3 years ago
parent
commit
87f8f8f13e
  1. 2
      src/app/api/Ingestion/sendFormAnswer.js
  2. 50
      src/app/components/AssembleModalObject.js

2
src/app/api/Ingestion/sendFormAnswer.js

@ -3,7 +3,7 @@ import appIngestion from "./appIngestion";
const endpoint = "/api/wpdAppIngestion?"; const endpoint = "/api/wpdAppIngestion?";
async function sendFormAnswer(ingestionObject) { async function sendFormAnswer(ingestionObject) {
console.log(JSON.stringify(ingestionObject));
// console.log(JSON.stringify(ingestionObject));
const response = await appIngestion.post( const response = await appIngestion.post(
endpoint, endpoint,

50
src/app/components/AssembleModalObject.js

@ -60,11 +60,12 @@ function getLogo(name, situation) {
} }
} }
function verifymeasureDates(labels, measureDate, day) {
function verifymeasureDates(labels, measureDate, day, dt) {
// console.log(measureDate); // console.log(measureDate);
if (labels == null || !labels.find((f) => f == measureDate)) { if (labels == null || !labels.find((f) => f == measureDate)) {
labels.push(measureDate); labels.push(measureDate);
day.label = measureDate; day.label = measureDate;
day.date_format = dt;
return true; return true;
} }
@ -72,14 +73,19 @@ function verifymeasureDates(labels, measureDate, day) {
} }
const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => { const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => {
var day = { label: null, values: [] };
var day = { label: null, date_format: null, values: [] };
var time = null; var time = null;
var dt = null; var dt = null;
var measure = { rainGauge: null, dateTime: null, comment: null }; var measure = { rainGauge: null, dateTime: null, comment: null };
var measureDate = null; var measureDate = null;
var fieldsAnswers = null;
if (pluvForm.formsanswersuserinformer == userId) { if (pluvForm.formsanswersuserinformer == userId) {
pluvForm.array_to_json.find((field) => { pluvForm.array_to_json.find((field) => {
if (field.fieldname == "date") { if (field.fieldname == "date") {
fieldsAnswers = moment(
field.fieldsanswersvalue,
"DD-MM-YYYY"
).toObject();
measureDate = moment(field.fieldsanswersvalue, "DD-MM-YYYY").format( measureDate = moment(field.fieldsanswersvalue, "DD-MM-YYYY").format(
"DD/MM" "DD/MM"
); );
@ -93,6 +99,16 @@ const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => {
} }
}); });
var data_sort = new Date(
fieldsAnswers.years,
fieldsAnswers.months,
fieldsAnswers.date,
"13",
"00",
"00",
"00"
);
// console.log(data_sort);
measure.dateTime = moment(dt + "T" + time, "DD-MM-YYYYTHH:mm").format( measure.dateTime = moment(dt + "T" + time, "DD-MM-YYYYTHH:mm").format(
"DD-MM-YYYYTHH:mm" "DD-MM-YYYYTHH:mm"
); );
@ -103,12 +119,7 @@ const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => {
measure.rainGauge = field.fieldsanswersvalue measure.rainGauge = field.fieldsanswersvalue
? parseFloat(field.fieldsanswersvalue) ? parseFloat(field.fieldsanswersvalue)
: null; : null;
if (verifymeasureDates(data.labels, measureDate, day)) {
// day.values.push(
// field.fieldsanswersvalue
// ? parseFloat(field.fieldsanswersvalue)
// : null
// );
if (verifymeasureDates(data.labels, measureDate, day, data_sort)) {
day.values.push(measure); day.values.push(measure);
datapluv.push(day); datapluv.push(day);
} else { } else {
@ -174,8 +185,8 @@ const AssembleModalObject = async (response, name, userId, formId) => {
(pluvForm) => getCurrentPluviometer(pluvForm, userId, data, datapluv) (pluvForm) => getCurrentPluviometer(pluvForm, userId, data, datapluv)
); );
if (datapluv) { if (datapluv) {
datapluv.sort(function (dataPluv, dataPluvB) {
return dataPluv.label.localeCompare(dataPluvB.label);
datapluv.sort(function (a, b) {
return a.date_format - b.date_format;
}); });
datapluv.forEach((measureDay) => { datapluv.forEach((measureDay) => {
@ -183,12 +194,18 @@ const AssembleModalObject = async (response, name, userId, formId) => {
return a.dateTime.localeCompare(b.dateTime); return a.dateTime.localeCompare(b.dateTime);
}); });
}); });
dtlength = datapluv.length - 1;
val_length = datapluv[dtlength].values.length - 1;
dtlength = datapluv.length > 0 ? datapluv.length - 1 : 0;
if (datapluv[dtlength]?.values) {
val_length =
datapluv[dtlength].values.length > 0
? datapluv[dtlength].values.length - 1
: 0;
comments = datapluv[dtlength].values[val_length].comment; comments = datapluv[dtlength].values[val_length].comment;
} }
} }
console.log(datapluv);
}
} }
} else if (JSON.parse(response).array_to_json) { } else if (JSON.parse(response).array_to_json) {
const r = JSON.parse(response).array_to_json; const r = JSON.parse(response).array_to_json;
@ -203,7 +220,9 @@ const AssembleModalObject = async (response, name, userId, formId) => {
"YYYY-MM-DDTHH:mm:ss" "YYYY-MM-DDTHH:mm:ss"
).format("DD/MM"); ).format("DD/MM");
measure.rainGauge = f.fieldsanswersvalue ? parseFloat(f.fieldsanswersvalue) : null;
measure.rainGauge = f.fieldsanswersvalue
? parseFloat(f.fieldsanswersvalue)
: null;
if (verifymeasureDates(data.labels, measureDate, day)) { if (verifymeasureDates(data.labels, measureDate, day)) {
day.values.push(measure); day.values.push(measure);
@ -212,8 +231,7 @@ const AssembleModalObject = async (response, name, userId, formId) => {
} else { } else {
datapluv.forEach((d) => { datapluv.forEach((d) => {
if (d.label == measureDate) { if (d.label == measureDate) {
d.values.push(
measure);
d.values.push(measure);
} }
}); });
} }
@ -247,7 +265,7 @@ const AssembleModalObject = async (response, name, userId, formId) => {
if (f.fieldname == "eventdate") { if (f.fieldname == "eventdate") {
date = moment(f.fieldsanswersvalue, "DD-MM-YYYY").format( date = moment(f.fieldsanswersvalue, "DD-MM-YYYY").format(
"DD/MM/YYYY" "DD/MM/YYYY"
);;
);
} }
if (f.fieldname == "eventtime") { if (f.fieldname == "eventtime") {
time = f.fieldsanswersvalue; time = f.fieldsanswersvalue;

Loading…
Cancel
Save