import moment from "moment"; import React from "react"; import { View, Text } from "react-native"; import assets from "../config/assets"; const custom_assets = { pluviometer: assets.pluviometer, officialPluviometer: assets.officialPluviometer, floodZones: assets.floodZones, riverLevel: ["low", "normal", "high", "flooding"].map((key) => { return assets.riverLevel[key]; }), rainLevel: ["rain_0_5", "rain_1_5", "rain_2_5", "rain_3_5"].map((key) => { return assets.rainLevel[key]; }), }; function getLogo(name, situation) { if (name == "automaticPluviometer") { return custom_assets.officialPluviometer; } if (name == "pluviometer") { return custom_assets.pluviometer; } if (name == "rain") { if (situation == "sem chuva") { return custom_assets.rainLevel[0]; } else if (situation == "chuva fraca") { return custom_assets.rainLevel[1]; } else if (situation == "chuva moderada") { return custom_assets.rainLevel[2]; } else if (situation == "chuva forte") { return custom_assets.rainLevel[3]; } else { return custom_assets.rainLevel[3]; } } if (name == "riverFlood") { if (situation == "baixo") { return custom_assets.riverLevel[0]; } else if (situation == "normal") { return custom_assets.riverLevel[1]; } else if (situation == "alto") { return custom_assets.riverLevel[2]; } else if (situation == "inundar") { return custom_assets.riverLevel[3]; } return custom_assets.riverLevel[0]; } if (name == "floodZones") { return custom_assets.floodZones; } } function verifyMeasureDates(labels, measureDate) { if (labels == null || !labels.find((f) => f == measureDate)) { labels.push(measureDate); } } const AssembleModalObject = (response, name) => { var situation = null; var user = null; var address = null; var date = null; var time = null; var comments = null; var pictures = null; var data = { values: [], labels: [], }; if (JSON.parse(response)) { const r = JSON.parse(response); if (name == "automaticPluviometer") { (situation = "PLUVIÔMETRO"), r[0].array_to_json.forEach(function (f) { 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( f.fieldsanswersvalue ? parseFloat(f.fieldsanswersvalue) : null ); } if (f.fieldname == "siglarede") { user = f.fieldsanswersvalue; } if (f.fieldname == "nome") { address = f.fieldsanswersvalue; } }); } else { if (r[0].array_to_json) { r[0].array_to_json.forEach(function (f) { if (f.fieldname == "situation") { situation = f.fieldsanswersvalue; } if (f.fieldname == "eventaddress") { address = f.fieldsanswersvalue; } if (f.fieldname == "eventdate") { date = f.fieldsanswersvalue; } if (f.fieldname == "eventtime") { time = f.fieldsanswersvalue; } if (f.fieldname == "comments") { comments = f.fieldsanswersvalue; } }); } } } return { name: name, title: situation, user: user, address: address, date: date + " | " + time, description: comments, logo: getLogo(name, situation), pictures: pictures, data: data, }; }; export default AssembleModalObject;