|
|
@ -1,8 +1,9 @@ |
|
|
|
import moment from "moment"; |
|
|
|
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
|
|
|
|
const custom_assets = { |
|
|
|
pluviometer: assets.PluviometerIcon, |
|
|
|
officialPluviometer: assets.OfficialPluviometer, |
|
|
@ -59,14 +60,72 @@ function getLogo(name, situation) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function verifyMeasureDates(labels, measureDate) { |
|
|
|
function verifymeasureDates(labels, measureDate, day) { |
|
|
|
// console.log(measureDate);
|
|
|
|
if (labels == null || !labels.find((f) => f == measureDate)) { |
|
|
|
labels.push(measureDate); |
|
|
|
day.label = measureDate; |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
const getCurrentPluviometer = (pluvForm, userId, data, datapluv) => { |
|
|
|
//console.log("\nuserid: "+ userId + "\n\n");
|
|
|
|
//console.log(pluvForm);
|
|
|
|
var day = { label: null, values: [] }; |
|
|
|
|
|
|
|
var measureDate = null; |
|
|
|
if (pluvForm.formsanswersuserinformer == userId) { |
|
|
|
pluvForm.array_to_json.find((field) => { |
|
|
|
if (field.fieldname == "date") { |
|
|
|
measureDate = moment(field.fieldsanswersvalue, "DD-MM-YYYY").format( |
|
|
|
"DD/MM" |
|
|
|
); |
|
|
|
//data.labels.push(moment(f.fieldsanswersdtfilling).format("DD/MM/YYYY"));
|
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
pluvForm.array_to_json.find((field) => { |
|
|
|
if (field.fieldname == "rainamount") { |
|
|
|
if (verifymeasureDates(data.labels, measureDate, day)) { |
|
|
|
day.values.push( |
|
|
|
field.fieldsanswersvalue |
|
|
|
? parseFloat(field.fieldsanswersvalue) |
|
|
|
: null |
|
|
|
); |
|
|
|
|
|
|
|
datapluv.push(day); |
|
|
|
} else { |
|
|
|
datapluv.forEach((d) => { |
|
|
|
if (d.label === measureDate) { |
|
|
|
d.values.push( |
|
|
|
field.fieldsanswersvalue |
|
|
|
? parseFloat(field.fieldsanswersvalue) |
|
|
|
: null |
|
|
|
); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return pluvForm; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
async function getPluviometerStatio_informations(id) { |
|
|
|
const result = await getFieldsAnswers.fieldsAnswers(null, id); |
|
|
|
|
|
|
|
if (result.data) { |
|
|
|
return result.data.responseData.array_to_json[0].array_to_json; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
const AssembleModalObject = (response, name) => { |
|
|
|
//console.log(response);
|
|
|
|
const AssembleModalObject = async (response, name, userId, formId) => { |
|
|
|
var situation = null; |
|
|
|
var user = null; |
|
|
|
var institution = null; |
|
|
@ -76,10 +135,11 @@ const AssembleModalObject = (response, name) => { |
|
|
|
var comments = null; |
|
|
|
var pictures = null; |
|
|
|
var data = { |
|
|
|
values: [], |
|
|
|
labels: [], |
|
|
|
}; |
|
|
|
|
|
|
|
var datapluv = []; |
|
|
|
|
|
|
|
if (JSON.parse(response).array_to_json) { |
|
|
|
const r = JSON.parse(response).array_to_json; |
|
|
|
|
|
|
@ -88,15 +148,32 @@ const AssembleModalObject = (response, name) => { |
|
|
|
if (name == "automaticPluviometer") { |
|
|
|
(situation = "PLUVIÔMETRO"), |
|
|
|
r[0].array_to_json.forEach(function (f) { |
|
|
|
var day = { label: null, values: [] }; |
|
|
|
if (f.fieldname == "medicao") { |
|
|
|
verifyMeasureDates( |
|
|
|
data.labels, |
|
|
|
moment(f.fieldsanswersdtfilling).format("DD/MM") |
|
|
|
); //data.labels.push(moment(f.fieldsanswersdtfilling).format("DD/MM/YYYY"));
|
|
|
|
data.values.push( |
|
|
|
var measureDate = moment( |
|
|
|
f.fieldsanswersdtfilling, |
|
|
|
"YYYY-MM-DDTHH:mm:ss" |
|
|
|
).format("DD/MM"); |
|
|
|
|
|
|
|
if (verifymeasureDates(data.labels, measureDate, day)) { |
|
|
|
day.values.push( |
|
|
|
f.fieldsanswersvalue ? parseFloat(f.fieldsanswersvalue) : null |
|
|
|
); |
|
|
|
day.label = measureDate; |
|
|
|
datapluv.push(day); |
|
|
|
} else { |
|
|
|
datapluv.forEach((d) => { |
|
|
|
if (d.label == measureDate) { |
|
|
|
d.values.push( |
|
|
|
f.fieldsanswersvalue |
|
|
|
? parseFloat(f.fieldsanswersvalue) |
|
|
|
: null |
|
|
|
); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (f.fieldname == "siglarede") { |
|
|
|
institution = f.fieldsanswersvalue; |
|
|
|
} |
|
|
@ -104,9 +181,44 @@ const AssembleModalObject = (response, name) => { |
|
|
|
address = f.fieldsanswersvalue; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
if (datapluv) { |
|
|
|
datapluv.sort(function (dataPluv, dataPluvB) { |
|
|
|
return dataPluv.label.localeCompare(dataPluvB.label); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// console.log(datapluv);
|
|
|
|
} else if (name == "pluviometer") { |
|
|
|
situation = "PLUVIÔMETRO"; |
|
|
|
//buscar todos os PLUVIOMETERS_FORMS REPORTADOS PELO USUÁRIO DOS ULTIMOS 5 DIAS
|
|
|
|
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; |
|
|
@ -141,7 +253,7 @@ const AssembleModalObject = (response, name) => { |
|
|
|
description: comments, |
|
|
|
logo: getLogo(name, situation), |
|
|
|
pictures: pictures, |
|
|
|
data: data, |
|
|
|
data: datapluv, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|