Browse Source

Merge branch 'main' of github.com:IGSD-UoW/WPD-MobileApp

master
GabrielTrettel 3 years ago
parent
commit
6d56152b6a
  1. 7
      src/app/api/Ingestion/appIngestion.js
  2. 16
      src/app/api/Ingestion/sendFormAnswer.js
  3. 96
      src/app/components/forms/AssembleIngestionObject.js
  4. 7
      src/app/components/forms/FormsCode.js
  5. 12
      src/app/hooks/useFiltering.js
  6. 37
      src/app/hooks/useSocketMarkers.js
  7. 3
      src/app/screens/PluviometerRegisterScreen.js
  8. 7
      src/app/screens/PluviometerSharingDataScreen.js
  9. 24
      src/app/screens/RainSharingDataScreen.js
  10. 30
      src/app/screens/RiverFloodSharingDataScreen.js
  11. 22
      src/app/screens/SharingFloodZonesScreen.js

7
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;

16
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;

96
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,
};

7
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",
};

12
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`
),
},
];

37
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,6 +126,7 @@ function buildPolygonsObject(response, name) {
var r = JSON.parse(response);
var coordinate = [];
var formsanswersgeom = r.formsanswersgeom;
if (JSON.parse(formsanswersgeom).type == "Polygon") {
const arrayCoordinates = JSON.parse(formsanswersgeom)["coordinates"][0];
var n = Object.keys(arrayCoordinates).length;
@ -134,7 +135,7 @@ function buildPolygonsObject(response, name) {
var lon = arrayCoordinates[i][0];
coordinate.push([lat, lon]);
}
var polygonObject = {
return {
ID: r.formsanswersid,
name: name,
title: "Titulo", //response.fieldsanswerssituation
@ -146,8 +147,20 @@ function buildPolygonsObject(response, name) {
pictures: null,
image: "", //getMarkerImage(answer.name),
};
return polygonObject;
} 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),
};;
}
}
function buildMarkerObject(response, name) {

3
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)},
});
}}
>

7
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,

24
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) {
>
<SvgLabeledButton
style={{ marginRight: 17 }}
onPress={() => setRain(0)}
onPress={() => {setRain(0); setRainSituation("SEM CHUVA")}}
SvgImage={assets.rainLevel.Rain_0_5}
label={"SEM CHUVA"}
isToggle={rain == 0}
/>
<SvgLabeledButton
onPress={() => 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) {
<View flexDirection="row" justifyContent="center">
<SvgLabeledButton
style={{ marginRight: 17 }}
onPress={() => setRain(2)}
onPress={() => {setRain(2); setRainSituation("CHUVA MODERADA")}}
SvgImage={assets.rainLevel.Rain_2_5}
label={"CHUVA MODERADA"}
isToggle={rain == 2}
/>
<SvgLabeledButton
onPress={() => setRain(3)}
onPress={() => {setRain(3), setRainSituation("CHUVA FORTE")}}
SvgImage={assets.rainLevel.Rain_3_5}
label={"CHUVA FORTE"}
isToggle={rain == 3}

30
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) {
<View style={styles.imgs_row}>
<SvgLabeledButton
style={{ marginRight: 17 }}
onPress={() => setRiverScale(0)}
onPress={() => {
setRiverScale(0);
setRiverSituation("BAIXO");
}}
SvgImage={assets.riverLevel.Low}
label={"BAIXO"}
isToggle={riverScale == 0}
/>
<SvgLabeledButton
onPress={() => setRiverScale(1)}
onPress={() => {
setRiverScale(1);
setRiverSituation("NORMAL");
}}
SvgImage={assets.riverLevel.Normal}
label={"NORMAL"}
isToggle={riverScale == 1}
@ -105,14 +118,19 @@ function RiverFloodSharingDataScreen(props) {
<View flexDirection="row" justifyContent="center">
<SvgLabeledButton
style={{ marginRight: 17 }}
onPress={() => setRiverScale(2)}
onPress={() => {
setRiverSituation("ALTO");
}}
SvgImage={assets.riverLevel.High}
label={"ALTO"}
isToggle={riverScale == 2}
/>
<SvgLabeledButton
onPress={() => setRiverScale(3)}
onPress={() => {
setRiverScale(3);
setRiverSituation("INUNDAR");
}}
SvgImage={assets.riverLevel.Flooding}
label={"INUNDAR"}
isToggle={riverScale == 3}

22
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,
@ -75,11 +83,17 @@ function SharingFloodZonesScreen(props) {
label={"TRANSITÁVEL"}
isToggle={passable == 1}
SvgImage={assets.floodZones.passable}
onPress={() => setPassable(1)}
onPress={() => {
setPassable(1);
setFloodSituation("TRANSITAVEL");
}}
/>
<SvgLabeledButton
onPress={() => setPassable(0)}
onPress={() => {
setPassable(0);
setFloodSituation("INTRANSITAVEL");
}}
label={"INTRANSITÁVEL"}
isToggle={passable == 0}
SvgImage={assets.floodZones.notPassable}

Loading…
Cancel
Save