diff --git a/src/app/api/Ingestion/appIngestion.js b/src/app/api/Ingestion/appIngestion.js new file mode 100644 index 0000000..5c15235 --- /dev/null +++ b/src/app/api/Ingestion/appIngestion.js @@ -0,0 +1,7 @@ +import { create } from "apisauce"; + +const appIngestion = create({ + baseURL: "https://wpdappingestion.azurewebsites.net", +}); + +export default appIngestion; diff --git a/src/app/api/Ingestion/sendFormAnswer.js b/src/app/api/Ingestion/sendFormAnswer.js new file mode 100644 index 0000000..bd71052 --- /dev/null +++ b/src/app/api/Ingestion/sendFormAnswer.js @@ -0,0 +1,16 @@ +import appIngestion from "./appIngestion"; + +const endpoint = "/api/wpdAppIngestion?"; + +async function sendFormAnswer(ingestionObject) { + console.log(JSON.stringify(ingestionObject)); + + const response = await appIngestion.post( + endpoint, + JSON.stringify(ingestionObject) + ); + + return response; +} + +export default sendFormAnswer; diff --git a/src/app/components/forms/AssembleIngestionObject.js b/src/app/components/forms/AssembleIngestionObject.js new file mode 100644 index 0000000..dbc6a54 --- /dev/null +++ b/src/app/components/forms/AssembleIngestionObject.js @@ -0,0 +1,96 @@ +import moment from "moment"; +import React from "react"; +import sendFormAnswer from "../../api/Ingestion/sendFormAnswer"; + +const AssembleIngestionObject = ({ + images, + description, + situation, + code, + location, + date, + time, + address, +}) => { + const ingestionObject = { + responseData: { + array_to_json: [ + { + formcode: code, + formsanswersuserinformer: "admin@wpd.com", + fieldsanswerslongitude: location["longitude"], + fieldsanswerslatitude: location["latitude"], + fields: [ + { + fieldsanswerssituation: situation ? situation : "CHUVA FRACA", + fieldsanswerseventaddress: address, + fieldsanswerseventdate: moment(date).format("DD-MM-YYYY"), + fieldsanswerseventtime: moment(time).format("HH:mm"), + fieldsanswercomment: description + ? description + : "descrição do evento", + }, + ], + }, + ], + }, + }; + + const a = sendFormAnswer(ingestionObject); +}; +const AssembleIngestionPluviometer = ({ + pluviometer, + description, + images, + date, + time, +}) => { + const pluviometerObject = { + responseData: { + array_to_json: [ + { + formcode: "PLUVIOMETERS_FORM", + formsanswersuserinformer: "admin@wpd.com", + fias: [ + { + fieldsanswersdate: moment(date).format("DD-MM-YYYY"), + fieldsanswersrainamount: pluviometer, + fieldsanswerseventtime: moment(time).format("HH:mm"), + fielsanswercomment: description, + }, + ], + }, + ], + }, + }; +}; + +const AssembleIngestionPluvRegistration = ({date, time, user}) => { + const pluvResgistrationObject = { + responseData: { + array_to_json: [ + { + formcode: "PLUVIOMETER_REGISTRATION", + formsanswersuserinformer: "admin@wpd.com", //user + fieldsanswerslongitude: -46.5637, //location["longitude"], + fieldsanswerslatitude: -23.6230,//location["latitude"], + fields: [ + { + fieldsanswerseventaddress: "Rua Rio de Janeiros, 81",//address + fieldsanswerseventdate: moment(date).format("DD-MM-YYYY"), + fieldsanswerseventtime: moment(time).format("HH:mm"), + fieldsanswersinstitutename: "E. E. Vagner", + fieldsanswerrinstitutetype: "Escola", + }, + ], + }, + ], + }, + }; + const a = sendFormAnswer(ingestionObject); +}; +export { + AssembleIngestionObject, + AssembleIngestionPluviometer, + AssembleIngestionPluvRegistration, +}; diff --git a/src/app/components/forms/FormsCode.js b/src/app/components/forms/FormsCode.js new file mode 100644 index 0000000..2d19093 --- /dev/null +++ b/src/app/components/forms/FormsCode.js @@ -0,0 +1,7 @@ +export const formcode = { + rain: "RAIN_FORM", + river: "RIVERFLOOD_FORM", + floodzones: "FLOODZONES_FORM", + pluviometer: "PLUVIOMETER_FORM", + pluviometerRegistration: "PLUVIOMETER_REGISTRATION", +}; diff --git a/src/app/hooks/useFiltering.js b/src/app/hooks/useFiltering.js index fadf1d9..fb6b780 100644 --- a/src/app/hooks/useFiltering.js +++ b/src/app/hooks/useFiltering.js @@ -4,42 +4,42 @@ function useFiltering(location) { name: "floodZones", socketUrl: new WebSocket( "wss://waterproofing.geog.uni-heidelberg.de/wss/hot/data?" + - `type=FLOODZONES_FORM&lat=-9.9740&lon=-67.8098&buffer=5000&limit=5` + `type=FLOODZONES_FORM&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=5` ), }, { name: "rain", socketUrl: new WebSocket( "wss://waterproofing.geog.uni-heidelberg.de/wss/hot/data?" + - `type=RAIN_FORM&lat=-9.9740&lon=-67.8098&buffer=5000&limit=5` + `type=RAIN_FORM&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=30` ), }, { name: "riverFlood", socketUrl: new WebSocket( "wss://waterproofing.geog.uni-heidelberg.de/wss/hot/data?" + - `type=RIVERFLOOD_FORM&-9.9740&lon=-67.8098&buffer=5000&limit=5` + `type=RIVERFLOOD_FORM&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=5` ), }, { name: "pluviometer", socketUrl: new WebSocket( "wss://waterproofing.geog.uni-heidelberg.de/wss/hot/data?" + - `type=PLUVIOMETER_REGISTRATION&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=5` + `type=PLUVIOMETER_REGISTRATION&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=5` ), }, { name: "susceptibilityAreas", socketUrl: new WebSocket( "wss://waterproofing.geog.uni-heidelberg.de/wss/hot/data?" + - `type=FLOODZONES_OFFICIAL&lat=-9.9740&lon=-67.8098&buffer=5000&limit=3` + `type=FLOODZONES_OFFICIAL&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=3` ), }, { name: "automaticPluviometer", socketUrl: new WebSocket( "wss://waterproofing.geog.uni-heidelberg.de/wss/hot/data?" + - `type=PLUVIOMETERS_OFFICIAL&lat=-9.9740&lon=-67.8098&buffer=5000&limit=5` + `type=PLUVIOMETERS_OFFICIAL&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=5` ), }, ]; diff --git a/src/app/hooks/useSocketMarkers.js b/src/app/hooks/useSocketMarkers.js index a5a84eb..d02bc91 100644 --- a/src/app/hooks/useSocketMarkers.js +++ b/src/app/hooks/useSocketMarkers.js @@ -49,32 +49,32 @@ function getImage(name, situation) { } if (name == "rain") { - if (situation == "sem chuva") { + if (situation == "SEM CHUVA") { return custom_assets_pin.rainLevel[0]; - } else if (situation == "chuva fraca") { + } else if (situation == "CHUVA FRACA") { return custom_assets_pin.rainLevel[1]; - } else if (situation == "chuva moderada") { + } else if (situation == "CHUVA MODERADA") { return custom_assets_pin.rainLevel[2]; - } else if (situation == "chuva forte") { + } else if (situation == "CHUVA FORTE") { return custom_assets_pin.rainLevel[3]; } return custom_assets_pin.rainLevel[3]; } if (name == "riverFlood") { - if (situation == "baixo") { + if (situation == "BAIXO") { return custom_assets_pin.riverLevel[0]; - } else if (situation == "normal") { + } else if (situation == "NORMAL") { return custom_assets_pin.riverLevel[1]; - } else if (situation == "alto") { + } else if (situation == "ALTO") { return custom_assets_pin.riverLevel[2]; - } else if (situation == "inundar") { + } else if (situation == "INUNDAR") { return custom_assets_pin.riverLevel[3]; } return custom_assets_pin.riverLevel[0]; } if (name == "floodZones") { - if (situation == "transitavel") { + if (situation == "TRANSITAVEL") { return custom_assets_pin.floodZones.passable; } else { return custom_assets_pin.floodZones.not_passable; @@ -126,28 +126,41 @@ function buildPolygonsObject(response, name) { var r = JSON.parse(response); var coordinate = []; var formsanswersgeom = r.formsanswersgeom; - const arrayCoordinates = JSON.parse(formsanswersgeom)["coordinates"][0]; - var n = Object.keys(arrayCoordinates).length; + if (JSON.parse(formsanswersgeom).type == "Polygon") { + const arrayCoordinates = JSON.parse(formsanswersgeom)["coordinates"][0]; + var n = Object.keys(arrayCoordinates).length; - for (let i = 0; i < n; i++) { - var lat = arrayCoordinates[i][1]; - var lon = arrayCoordinates[i][0]; - coordinate.push([lat, lon]); + for (let i = 0; i < n; i++) { + var lat = arrayCoordinates[i][1]; + var lon = arrayCoordinates[i][0]; + coordinate.push([lat, lon]); + } + return { + ID: r.formsanswersid, + name: name, + title: "Titulo", //response.fieldsanswerssituation + address: "Endereço", //response.fieldsanswerseventaddress, + coordinate: coordinate, + date: "data" + " | " + "hora", //response.fieldsanswerseventdate + " | " + response.fieldsanswerseventtime, + description: "comentário", //response.fielsanswercomment, + logo: custom_assets.pluviometer, + pictures: null, + image: "", //getMarkerImage(answer.name), + }; + } else { + return { + ID: r.formsanswersid, + name: name, + title: "Titulo", //response.fieldsanswerssituation + address: "Endereço", //response.fieldsanswerseventaddress, + coordinate: [null, null], + date: "data" + " | " + "hora", //response.fieldsanswerseventdate + " | " + response.fieldsanswerseventtime, + description: "comentário", //response.fielsanswercomment, + logo: custom_assets.pluviometer, + pictures: null, + image: "", //getMarkerImage(answer.name), + };; } - var polygonObject = { - ID: r.formsanswersid, - name: name, - title: "Titulo", //response.fieldsanswerssituation - address: "Endereço", //response.fieldsanswerseventaddress, - coordinate: coordinate, - date: "data" + " | " + "hora", //response.fieldsanswerseventdate + " | " + response.fieldsanswerseventtime, - description: "comentário", //response.fielsanswercomment, - logo: custom_assets.pluviometer, - pictures: null, - image: "", //getMarkerImage(answer.name), - }; - - return polygonObject; } function buildMarkerObject(response, name) { @@ -195,7 +208,7 @@ function buildMarkerObject(response, name) { description: comments, logo: getLogo(), pictures: pictures, - image: getImage(name, situation), + image: getImage(name, situation), }; } diff --git a/src/app/screens/PluviometerRegisterScreen.js b/src/app/screens/PluviometerRegisterScreen.js index 4b725de..6e8f33a 100644 --- a/src/app/screens/PluviometerRegisterScreen.js +++ b/src/app/screens/PluviometerRegisterScreen.js @@ -11,6 +11,7 @@ import { TouchableOpacity } from "react-native-gesture-handler"; import { FontAwesome5 } from "@expo/vector-icons"; import { AuthContext } from "../auth/context"; import { Shadow } from "react-native-shadow-2"; +import { AssembleIngestionPluvRegistration } from "../components/forms/AssembleIngestionObject"; const dims = scaleDimsFromWidth(85, 85, 25); @@ -101,7 +102,7 @@ function PluviometerRegisterScreen(props) { duration: 1950, icon: "warning", type: "warning", - onPress: () => {}, + onPress: () => {AssembleIngestionPluvRegistration(date, time, user)}, }); }} > diff --git a/src/app/screens/PluviometerSharingDataScreen.js b/src/app/screens/PluviometerSharingDataScreen.js index 0ff6374..fb85ddb 100644 --- a/src/app/screens/PluviometerSharingDataScreen.js +++ b/src/app/screens/PluviometerSharingDataScreen.js @@ -11,6 +11,8 @@ import colors from "../config/colors/"; import moment from "moment"; import PickEventDateLocation from "../components/PickEventDateLocation"; import { EventLocationContext } from "../context/EventLocationContext"; +import { formcode } from "../components/forms/FormsCode"; +import { AssembleIngestionPluviometer } from "../components/forms/AssembleIngestionObject"; const dims = scaleDimsFromWidth(85, 85, 25); @@ -30,6 +32,8 @@ function PluviometerSharingDataScreen(props) { const [date, setDate] = useState(moment()); const [time, setTime] = useState(moment()); + const code = formcode.pluviometer; + useEffect(() => { context.defaultLocation(); }, []); @@ -44,7 +48,8 @@ function PluviometerSharingDataScreen(props) { images: [], }} onSubmit={(values) => { - insertPluviometerData({ ...values, dateTime, time }); + // insertPluviometerData({ ...values, dateTime, time }); + AssembleIngestionPluviometer({ ...values, date, time}) showMessage({ message: "Informação enviada!", duration: 3000, diff --git a/src/app/screens/RainSharingDataScreen.js b/src/app/screens/RainSharingDataScreen.js index b841b06..ba39bbc 100644 --- a/src/app/screens/RainSharingDataScreen.js +++ b/src/app/screens/RainSharingDataScreen.js @@ -16,6 +16,8 @@ import moment from "moment"; import { EventLocationContext } from "../context/EventLocationContext"; import PickEventDateLocation from "../components/PickEventDateLocation"; import SvgLabeledButton from "../components/SvgLabeledButton"; +import { AssembleIngestionObject } from "../components/forms/AssembleIngestionObject"; +import { formcode } from "../components/forms/FormsCode"; const validationSchema = Yup.object().shape({ images: Yup.array(), @@ -24,6 +26,7 @@ const validationSchema = Yup.object().shape({ function RainSharingDataScreen(props) { const [rain, setRain] = useState(-1); + const [rainSituation, setRainSituation] = useState(null); const [error, setError] = useState(false); const dims = scaleDimsFromWidth(85, 85, 27); @@ -31,6 +34,8 @@ function RainSharingDataScreen(props) { const [date, setDate] = useState(moment()); const [time, setTime] = useState(moment()); + const code = formcode.rain; + const context = useContext(EventLocationContext); useEffect(() => { @@ -52,7 +57,16 @@ function RainSharingDataScreen(props) { setError(true); return; } - insertRainData({ ...values, rain, location, date, time, address }); + AssembleIngestionObject({ + ...values, + rainSituation, + code, + location, + date, + time, + address, + }); + // insertRainData({ ...values, rain, location, date, time, address }); showMessage({ message: "Informação enviada!", duration: 1950, @@ -77,13 +91,13 @@ function RainSharingDataScreen(props) { > setRain(0)} + onPress={() => {setRain(0); setRainSituation("SEM CHUVA")}} SvgImage={assets.rainLevel.Rain_0_5} label={"SEM CHUVA"} isToggle={rain == 0} /> setRain(1)} + onPress={() => {setRain(1); setRainSituation("CHUVA FRACA")}} SvgImage={assets.rainLevel.Rain_1_5} label={"CHUVA FRACA"} isToggle={rain == 1} @@ -93,14 +107,14 @@ function RainSharingDataScreen(props) { setRain(2)} + onPress={() => {setRain(2); setRainSituation("CHUVA MODERADA")}} SvgImage={assets.rainLevel.Rain_2_5} label={"CHUVA MODERADA"} isToggle={rain == 2} /> setRain(3)} + onPress={() => {setRain(3), setRainSituation("CHUVA FORTE")}} SvgImage={assets.rainLevel.Rain_3_5} label={"CHUVA FORTE"} isToggle={rain == 3} diff --git a/src/app/screens/RiverFloodSharingDataScreen.js b/src/app/screens/RiverFloodSharingDataScreen.js index 2e4cf68..602eba3 100644 --- a/src/app/screens/RiverFloodSharingDataScreen.js +++ b/src/app/screens/RiverFloodSharingDataScreen.js @@ -16,6 +16,8 @@ import moment from "moment"; import { EventLocationContext } from "../context/EventLocationContext"; import PickEventDateLocation from "../components/PickEventDateLocation"; import SvgLabeledButton from "../components/SvgLabeledButton"; +import { formcode } from "../components/forms/FormsCode"; +import { AssembleIngestionObject } from "../components/forms/AssembleIngestionObject"; const validationSchema = Yup.object().shape({ images: Yup.array(), @@ -24,6 +26,9 @@ const validationSchema = Yup.object().shape({ function RiverFloodSharingDataScreen(props) { const [riverScale, setRiverScale] = useState(-1); + const [riverSituation, setRiverSituation] = useState(null); + + const code = formcode.river; const context = useContext(EventLocationContext); @@ -54,9 +59,11 @@ function RiverFloodSharingDataScreen(props) { setError(true); return; } - insertRiverData({ + // insertRiverData({ ...values, riverScale, location, date, time, address,}); + AssembleIngestionObject({ ...values, - riverScale, + riverSituation, + code, location, date, time, @@ -87,14 +94,20 @@ function RiverFloodSharingDataScreen(props) { setRiverScale(0)} + onPress={() => { + setRiverScale(0); + setRiverSituation("BAIXO"); + }} SvgImage={assets.riverLevel.Low} label={"BAIXO"} isToggle={riverScale == 0} /> setRiverScale(1)} + onPress={() => { + setRiverScale(1); + setRiverSituation("NORMAL"); + }} SvgImage={assets.riverLevel.Normal} label={"NORMAL"} isToggle={riverScale == 1} @@ -105,14 +118,19 @@ function RiverFloodSharingDataScreen(props) { setRiverScale(2)} + onPress={() => { + setRiverSituation("ALTO"); + }} SvgImage={assets.riverLevel.High} label={"ALTO"} isToggle={riverScale == 2} /> setRiverScale(3)} + onPress={() => { + setRiverScale(3); + setRiverSituation("INUNDAR"); + }} SvgImage={assets.riverLevel.Flooding} label={"INUNDAR"} isToggle={riverScale == 3} diff --git a/src/app/screens/SharingFloodZonesScreen.js b/src/app/screens/SharingFloodZonesScreen.js index 2d12681..4351679 100644 --- a/src/app/screens/SharingFloodZonesScreen.js +++ b/src/app/screens/SharingFloodZonesScreen.js @@ -15,6 +15,8 @@ import moment from "moment"; import { EventLocationContext } from "../context/EventLocationContext"; import PickEventDateLocation from "../components/PickEventDateLocation"; import SvgLabeledButton from "../components/SvgLabeledButton"; +import { formcode } from "../components/forms/FormsCode"; +import { AssembleIngestionObject } from "../components/forms/AssembleIngestionObject"; const validationSchema = Yup.object().shape({ images: Yup.array(), @@ -23,6 +25,10 @@ const validationSchema = Yup.object().shape({ function SharingFloodZonesScreen(props) { const [passable, setPassable] = useState(-1); + const [floodSituation, setFloodSituation] = useState(null); + + const code = formcode.floodzones; + const [error, setError] = useState(false); const [date, setDate] = useState(moment()); const [time, setTime] = useState(moment()); @@ -51,9 +57,11 @@ function SharingFloodZonesScreen(props) { setError(true); return; } - insertFloodZone({ + //insertFloodZone({ ...values, passable, location, date, time, address, }); + AssembleIngestionObject({ ...values, - passable, + floodSituation, + code, location, date, time, @@ -71,15 +79,21 @@ function SharingFloodZonesScreen(props) { > setPassable(1)} + onPress={() => { + setPassable(1); + setFloodSituation("TRANSITAVEL"); + }} /> setPassable(0)} + onPress={() => { + setPassable(0); + setFloodSituation("INTRANSITAVEL"); + }} label={"INTRANSITÁVEL"} isToggle={passable == 0} SvgImage={assets.floodZones.notPassable}