From 22c8c0e4f90343bbc1853a3f9989724727436ade Mon Sep 17 00:00:00 2001 From: GabrielTrettel Date: Wed, 16 Dec 2020 17:34:33 -0300 Subject: [PATCH] Forms data integrated with maps --- src/app/database/databaseLoader.js | 45 +++- src/app/database/db.js | 14 ++ src/app/hooks/selectFromDB.js | 72 +++++- src/app/screens/MapFeedScreen.js | 2 + src/app/screens/RainSharingDataScreen.js | 47 ++-- .../screens/RiverFloodSharingDataScreen.js | 225 +++++++++--------- 6 files changed, 263 insertions(+), 142 deletions(-) diff --git a/src/app/database/databaseLoader.js b/src/app/database/databaseLoader.js index 638ca16..42baac9 100644 --- a/src/app/database/databaseLoader.js +++ b/src/app/database/databaseLoader.js @@ -49,9 +49,52 @@ function insertPluviometerData({ pluviometer, images, date, location }) { parseFloat(pluviometer), ]; + transaction(global.userDataBase, query, values); +} + +function insertRainData({ images, rain, location }) { + const query = `INSERT INTO RainLevel(RainIdx, Images, Latitude, Longitude) VALUES(?, ?, ?, ?);`; + + if (location === undefined) { + console.debug("undefined location"); + return; + } + + const values = [ + parseInt(rain), + JSON.stringify(images), + parseFloat(location["latitude"]), + parseFloat(location["longitude"]), + ]; + + console.log(values); + + transaction(global.userDataBase, query, values); +} + +function insertRiverData({ images, riverScale, location }) { + const query = `INSERT INTO RiverLevel(RiverIdx, Images, Latitude, Longitude) VALUES(?, ?, ?, ?);`; + + if (location === undefined) { + console.debug("undefined location"); + return; + } + + const values = [ + parseInt(riverScale), + JSON.stringify(images), + parseFloat(location["latitude"]), + parseFloat(location["longitude"]), + ]; + console.log(values); transaction(global.userDataBase, query, values); } -export { insertFloodZone, insertPluviometerData }; +export { + insertFloodZone, + insertPluviometerData, + insertRainData, + insertRiverData, +}; diff --git a/src/app/database/db.js b/src/app/database/db.js index fbea196..d7a07e9 100644 --- a/src/app/database/db.js +++ b/src/app/database/db.js @@ -17,6 +17,20 @@ const init_queries = [ Longitude real NOT NULL, Precipitation real NOT NULL );`, + `CREATE TABLE IF NOT EXISTS RainLevel ( + Id integer PRIMARY KEY autoincrement, + RainIdx INTEGER NOT NULL, + Images text NOT NULL, + Latitude real NOT NULL, + Longitude real NOT NULL + );`, + `CREATE TABLE IF NOT EXISTS RiverLevel ( + Id integer PRIMARY KEY autoincrement, + RiverIdx INTEGER NOT NULL, + Images text NOT NULL, + Latitude real NOT NULL, + Longitude real NOT NULL + );`, ]; // `CREATE TABLE IF NOT EXISTS Users ( diff --git a/src/app/hooks/selectFromDB.js b/src/app/hooks/selectFromDB.js index 1e83b5c..cb15e4d 100644 --- a/src/app/hooks/selectFromDB.js +++ b/src/app/hooks/selectFromDB.js @@ -1,22 +1,41 @@ import { useEffect, useReducer } from "react"; import "../config/globals"; -const floodZoneAsset = require("../assets/pontos_alagamento_peq.png"); +const assets = { + floodZones: require("../assets/pontos_alagamento_peq.png"), + riverLevel: [ + require("../assets/rio_baixo.png"), + require("../assets/rio_normal.png"), + require("../assets/rio_alto.png"), + require("../assets/rio_transbordando.png"), + ], + rainLevel: [ + require("../assets/sem_chuva.png"), + require("../assets/chuva_peq.png"), + require("../assets/chuva_peq.png"), + require("../assets/chuva_forte.png"), + require("../assets/chuva_muito_forte.png"), + require("../assets/chuva_pancadas.png"), + ], + pluviometer: require("../assets/diario_pluviometrico.png"), +}; // NOTE: For debug pourposes var offset = 0.001; var displacement = 0; +var ID = 0; + function partsePluviometer(row) { displacement += offset; return { - key: 999, - title: "pluviometro", + key: ++ID, + title: "Pluviometro", coordinate: { latitude: row["Latitude"] + displacement, longitude: row["Longitude"], }, - image: floodZoneAsset, + image: assets.pluviometer, description: row["Pluviometer"], }; } @@ -24,17 +43,56 @@ function partsePluviometer(row) { function parseFloodZones(row) { displacement += offset; return { - key: row["Id"], + key: ++ID, title: row["Passable"] == 0 ? "Transponível" : "Intransponível", coordinate: { latitude: row["Latitude"], longitude: row["Longitude"] + displacement, }, - image: floodZoneAsset, + image: assets.floodZones, description: row["Description"], }; } +function parseRiverLevel(row) { + displacement += offset; + const riverLevel = ["Baixo", "Rio normal", "Alto", "Transfordando"]; + const riverIdx = row["RiverIdx"]; + return { + key: ++ID, + title: "Nível do rio", + coordinate: { + latitude: row["Latitude"], + longitude: row["Longitude"] + displacement, + }, + image: assets.riverLevel[riverIdx], + description: riverLevel[riverIdx], + }; +} + +function parseRainLevel(row) { + displacement += offset; + const rainLevel = [ + "Sem chuva", + "Chuva fraca", + "Chuva moderada", + "Chuva forte", + "Chuva muito forte", + "Pancada de chuva", + ]; + const rainIdx = row["RainIdx"]; + return { + key: ++ID, + title: "Nível da chuva", + coordinate: { + latitude: row["Latitude"], + longitude: row["Longitude"] + displacement, + }, + image: assets.rainLevel[rainIdx], + description: rainLevel[rainIdx], + }; +} + function parseResult(db_result, parseRow) { var warnings = []; @@ -70,6 +128,8 @@ function useMarkers() { const queriesToParsersMapper = [ ["SELECT * FROM FloodZones;", parseFloodZones], ["SELECT * FROM Pluviometer;", partsePluviometer], + ["SELECT * FROM RiverLevel;", parseRiverLevel], + ["SELECT * FROM RainLevel;", parseRainLevel], ]; queriesToParsersMapper.forEach(([query, parser]) => { diff --git a/src/app/screens/MapFeedScreen.js b/src/app/screens/MapFeedScreen.js index fcbf593..f54ccea 100644 --- a/src/app/screens/MapFeedScreen.js +++ b/src/app/screens/MapFeedScreen.js @@ -11,6 +11,8 @@ function MapFeedScreen(props) { const location = useLocation(); const markers = useMarkers(); + console.log(markers.markers); + return ( - + Chuva
submitForm({ ...values, passable, location })} + onSubmit={(values) => insertRainData({ ...values, rain, location })} validationSchema={validationSchema} > - setPassable(0)}> + setRain(0)}> - setPassable(1)}> + setRain(1)}> - setPassable(2)}> + setRain(2)}> - setPassable(3)}> + setRain(3)}> - setPassable(4)}> + setRain(4)}> - setPassable(5)}> + setRain(5)}> - - Nível da água do rio - - submitForm({ ...values, passable, location })} - validationSchema={validationSchema} - > - - - setPassable(0)}> - - - Baixo - - + return ( + + + Nível da água do rio + + + insertRiverData({ ...values, riverScale, location }) + } + validationSchema={validationSchema} + > + + + setRiverScale(0)}> + + + Baixo + + - setPassable(1)}> - - - Rio normal - - - + setRiverScale(1)}> + + + Rio normal + + + - - setPassable(2)}> - - - Alto - - + + setRiverScale(2)}> + + + Alto + + - setPassable(3)}> - - - Transbordando - - - - - + setRiverScale(3)}> + + + Transbordando + + + + + - - - - ); + + + + ); } const styles = StyleSheet.create({ - container: { - padding: 10, - }, - img_block: { - borderRadius: 5, - padding: 10, - borderStyle: "dotted", - borderColor: colors.primary, - alignItems: "center", - width:130, - }, - floodingLogo: { - width: 85, - height: 85, - }, - text: { - fontSize: 14, - textAlign: "center", - marginTop: 10, - }, + container: { + padding: 10, + }, + img_block: { + borderRadius: 5, + padding: 10, + borderStyle: "dotted", + borderColor: colors.primary, + alignItems: "center", + width: 130, + }, + floodingLogo: { + width: 85, + height: 85, + }, + text: { + fontSize: 14, + textAlign: "center", + marginTop: 10, + }, }); export default RiverFloodSharingDataScreen;