Browse Source

ordering pluviometer data on modal chart

master
analuizaff 3 years ago
parent
commit
214cc272f6
  1. 125
      src/app/components/AssembleModalObject.js
  2. 2
      src/app/components/PluviometerGraphics.js
  3. 4
      src/app/hooks/usePluviometerData.js

125
src/app/components/AssembleModalObject.js

@ -3,7 +3,7 @@ import React from "react";
import { View, Text } from "react-native";
import getFieldsAnswers from "../api/RequestFieldsAnswers/getFieldsAnswers";
import assets from "../config/assets";
//---1/3: melhorar código
//----- 1/3: melhorar código (URGENTE)
const custom_assets = {
pluviometer: assets.PluviometerIcon,
officialPluviometer: assets.OfficialPluviometer,
@ -72,10 +72,10 @@ function verifymeasureDates(labels, measureDate, day) {
}
const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => {
//console.log("\nuserid: "+ userId + "\n\n");
//console.log(pluvForm);
var day = { label: null, values: [] };
var time = null;
var dt = null;
var measure = { rainGauge: null, dateTime: null, comment: null };
var measureDate = null;
if (pluvForm.formsanswersuserinformer == userId) {
pluvForm.array_to_json.find((field) => {
@ -83,28 +83,38 @@ const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => {
measureDate = moment(field.fieldsanswersvalue, "DD-MM-YYYY").format(
"DD/MM"
);
//data.labels.push(moment(f.fieldsanswersdtfilling).format("DD/MM/YYYY"));
dt = moment(field.fieldsanswersvalue, "DD-MM-YYYY").format(
"DD-MM-YYYY"
);
} else if (field.fieldname == "eventtime") {
time = moment(field.fieldsanswersvalue, "HH:mm").format("HH:mm");
} else if (field.fieldname == "comments") {
measure.comment = field.fieldsanswersvalue;
}
});
measure.dateTime = moment(dt + "T" + time, "DD-MM-YYYYTHH:mm").format(
"DD-MM-YYYYTHH:mm"
);
// console.log("dt: " + day.dateTime);
pluvForm.array_to_json.find((field) => {
if (field.fieldname == "rainamount") {
if (verifymeasureDates(data.labels, measureDate, day)) {
day.values.push(
field.fieldsanswersvalue
measure.rainGauge = field.fieldsanswersvalue
? parseFloat(field.fieldsanswersvalue)
: null
);
: null;
if (verifymeasureDates(data.labels, measureDate, day)) {
// day.values.push(
// field.fieldsanswersvalue
// ? parseFloat(field.fieldsanswersvalue)
// : null
// );
day.values.push(measure);
datapluv.push(day);
} else {
datapluv.forEach((d) => {
if (d.label === measureDate) {
d.values.push(
field.fieldsanswersvalue
? parseFloat(field.fieldsanswersvalue)
: null
);
d.values.push(measure);
}
});
}
@ -126,6 +136,7 @@ async function getPluviometerStatio_informations(id) {
}
const AssembleModalObject = async (response, name, userId, formId) => {
// console.log(response);
var situation = null;
var user = null;
var institution = null;
@ -140,33 +151,69 @@ const AssembleModalObject = async (response, name, userId, formId) => {
var datapluv = [];
if (name == "pluviometer") {
situation = "PLUVIÔMETRO";
const pluv_sation = await getPluviometerStatio_informations(formId);
if (pluv_sation) {
pluv_sation.forEach((field) => {
if (field.fieldname == "institutename") {
institution =
field.fieldsanswersvalue != "None"
? field.fieldsanswersvalue
: "Não há vínculo institucional";
} else if (field.fieldname == "eventaddress") {
address = field.fieldsanswersvalue;
}
});
}
if (response) {
if (JSON.parse(response).array_to_json) {
const r = JSON.parse(response).array_to_json;
//(waiting for issue #16) user = r[0].formsanswersuserinformer;
const currentPluv = JSON.parse(response).array_to_json.filter(
(pluvForm) => getCurrentPluviometer(pluvForm, userId, data, datapluv)
);
if (datapluv) {
datapluv.sort(function (dataPluv, dataPluvB) {
return dataPluv.label.localeCompare(dataPluvB.label);
});
datapluv.forEach((measureDay) => {
measureDay.values.sort(function (a, b) {
return a.dateTime.localeCompare(b.dateTime);
});
});
dtlength = datapluv.length - 1;
val_length = datapluv[dtlength].values.length - 1;
comments = datapluv[dtlength].values[val_length].comment;
}
}
}
} else if (JSON.parse(response).array_to_json) {
const r = JSON.parse(response).array_to_json;
if (name == "automaticPluviometer") {
situation = "PLUVIÔMETRO";
r[0].array_to_json.forEach(function (f) {
var day = { label: null, values: [] };
var measure = { rainGauge: null };
if (f.fieldname == "medicao") {
var measureDate = moment(
f.fieldsanswersdtfilling,
"YYYY-MM-DDTHH:mm:ss"
).format("DD/MM");
measure.rainGauge = f.fieldsanswersvalue ? parseFloat(f.fieldsanswersvalue) : null;
if (verifymeasureDates(data.labels, measureDate, day)) {
day.values.push(
f.fieldsanswersvalue ? parseFloat(f.fieldsanswersvalue) : null
);
day.values.push(measure);
day.label = measureDate;
datapluv.push(day);
} else {
datapluv.forEach((d) => {
if (d.label == measureDate) {
d.values.push(
f.fieldsanswersvalue ? parseFloat(f.fieldsanswersvalue) : null
);
measure);
}
});
}
@ -187,36 +234,6 @@ const AssembleModalObject = async (response, name, userId, formId) => {
}
// console.log(datapluv);
} else if (name == "pluviometer") {
situation = "PLUVIÔMETRO";
r[r.length - 1].array_to_json.forEach(function (f) {
if (f.fieldname == "comments") {
comments = f.fieldsanswersvalue;
}
});
const pluv_sation = await getPluviometerStatio_informations(formId);
if (pluv_sation) {
pluv_sation.forEach((field) => {
if (field.fieldname == "institutename") {
institution =
field.fieldsanswersvalue != "None"
? field.fieldsanswersvalue
: "Não há vínculo institucional";
} else if (field.fieldname == "eventaddress") {
address = field.fieldsanswersvalue;
}
});
}
const currentPluv = JSON.parse(response).array_to_json.filter(
(pluvForm) => getCurrentPluviometer(pluvForm, userId, data, datapluv)
);
if (datapluv) {
datapluv.sort(function (dataPluv, dataPluvB) {
return dataPluv.label.localeCompare(dataPluvB.label);
});
}
} else {
if (r[0].array_to_json) {
user = r[0].formsanswersuserinformer;
@ -228,7 +245,9 @@ const AssembleModalObject = async (response, name, userId, formId) => {
address = f.fieldsanswersvalue;
}
if (f.fieldname == "eventdate") {
date = f.fieldsanswersvalue;
date = moment(f.fieldsanswersvalue, "DD-MM-YYYY").format(
"DD/MM/YYYY"
);;
}
if (f.fieldname == "eventtime") {
time = f.fieldsanswersvalue;

2
src/app/components/PluviometerGraphics.js

@ -56,7 +56,7 @@ function PluviometerGraphics({ chartHeight, data }) {
data.forEach((day) => {
labels.push(day.label);
day.values.forEach((value) => {
values.push(value);
values.push(value.rainGauge);
});
});
return (

4
src/app/hooks/usePluviometerData.js

@ -15,11 +15,9 @@ function getPluviometerData(geoLocation, setPluviometerData) {
if (data != undefined) {
const dataObject = JSON.parse(data);
// console.log(dataObject.responseData);
if (dataObject?.success) {
setPluviometerData(dataObject);
}
} else {
setPluviometerData(null);
setPluviometerData(false);
}
socketObject.close();

Loading…
Cancel
Save