From b99a01f5aa93c1131b479348caae9907d5f8a00e Mon Sep 17 00:00:00 2001 From: GabrielTrettel Date: Wed, 11 Aug 2021 22:34:23 -0300 Subject: [PATCH] Queries and JSONS for API communication --- db/create_config_tables.sql | 280 ++++++++++++++++++++++++++++++ db/floodzones-river-rain-api.json | 46 +++++ db/forms-fields-answers.json | 21 +++ db/pluviometer-api.json | 18 ++ db/pluviometer-modal-api.json | 27 +++ db/pluviometer-register-api.json | 20 +++ 6 files changed, 412 insertions(+) create mode 100644 db/create_config_tables.sql create mode 100644 db/floodzones-river-rain-api.json create mode 100644 db/forms-fields-answers.json create mode 100644 db/pluviometer-api.json create mode 100644 db/pluviometer-modal-api.json create mode 100644 db/pluviometer-register-api.json diff --git a/db/create_config_tables.sql b/db/create_config_tables.sql new file mode 100644 index 0000000..10cb2f3 --- /dev/null +++ b/db/create_config_tables.sql @@ -0,0 +1,280 @@ +DO $$ +DECLARE +--id fields +idfieldsituationcode bigint; +idfieldslatitude bigint; +idfieldslongitude bigint; +idfieldsaddress bigint; +idfieldsdate bigint; +idfieldstime bigint; +idfieldscomment bigint; +idfieldsimages bigint; +idfieldsinsname bigint; +idfieldsinstype bigint; +idfieldsvalue bigint; + +--id forms +idfloodzonesform bigint; +idrainform bigint; +idriverform bigint; +idpluvform bigint; +idpluvregsform bigint; + +BEGIN +---------------------------------- Fields -------------------------------------------------- + --situação do evento + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Situation', 'situation of the event', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'text' + RETURNING id INTO idfieldsituationcode; + + --Latitude + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Latitude', 'Event location latitude', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'real' + RETURNING id INTO idfieldslatitude; + + --Longitude + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Longitude', 'Event location longitude', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'real' + RETURNING id INTO idfieldslongitude; + + --Endereço + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Address', 'Event adress', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'text' + RETURNING id INTO idfieldsaddress; + + --Data + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Date_event', 'Event date', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'text' + RETURNING id INTO idfieldsdate; + + --Hora + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Time_event', 'Event time', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'text' + RETURNING id INTO idfieldstime; + + --Comentário + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Comment', 'Additional comment about the event', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'text' + RETURNING id INTO idfieldscomment; + + --Imagens + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Images', 'Event Images', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'text' + RETURNING id INTO idfieldsimages; + + --Qtd de agua no pluviometro + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Rain_amount', 'amount of rain recorded in the pluviometer', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'real' + RETURNING id INTO idfieldsvalue; + + --Tipo da instituição + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Institute_type', 'Kind of an institute', '', 1 + FROM fieldsdatatypes fdt WHERE fdt.name = 'text' + RETURNING id INTO idfieldsinstype; + + --Nome da Instituição + INSERT INTO fields(idfieldsdatatypes, name, description, fillingclue, active) + SELECT fdt.id, 'Institute_name', 'Name of an institute', '', 1 + FROM fieldsdatatypes fdt + WHERE fdt.name = 'text' + RETURNING id INTO idfieldsinsname; + +---------------------------------- Formulários --------------------------------------- +--Begin FloodZones Form + INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) + SELECT fo.id, 'FLOODZONES_FORM', 'Flood Zones Form', 'Flood Zones Form', current_timestamp, 1 + FROM formsorigins fo + WHERE fo.name = 'WP6.MobileApp' + RETURNING id INTO idfloodzonesform; + + --situação + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idfloodzonesform, idfieldsituationcode, 1); + + --local (lat, log e endereço) + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idfloodzonesform, idfieldslatitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idfloodzonesform, idfieldslongitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idfloodzonesform, idfieldsaddress, 1); + + --data e hora + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idfloodzonesform, idfieldsdate, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idfloodzonesform, idfieldstime, 1); + + --comentário + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idfloodzonesform, idfieldscomment, 1); + + --imagens + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idfloodzonesform, idfieldsimages, 1); +--End FloodZones Form + +--Begin Rain Form + INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) + SELECT fo.id, 'RAIN_FORM', 'Rain', 'Rain zones Form', current_timestamp, 1 + FROM formsorigins fo + WHERE fo.name = 'WP6.MobileApp' + RETURNING id INTO idrainform; + + --situação + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idrainform, idfieldsituationcode, 1); + + --local (lat, log e endereço) + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idrainform, idfieldslatitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idrainform, idfieldslongitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idrainform, idfieldsaddress, 1); + + --data e hora + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idrainform, idfieldsdate, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idrainform, idfieldstime, 1); + + --comentário + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idrainform, idfieldscomment, 1); + + --imagens + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idrainform, idfieldsimages, 1); +--End Rain Form + +--Begin Pluviometer Form + INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) + SELECT fo.id, 'PLUVIOMETERS_FORM', 'Pluviometers', 'Pluviometers Form', current_timestamp, 1 + FROM formsorigins fo + WHERE fo.name = 'WP6.MobileApp' + RETURNING id INTO idpluvform; + + --situação + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvform, idfieldsituationcode, 1); + + --local (lat, log e endereço) + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvform, idfieldslatitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvform, idfieldslongitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvform, idfieldsaddress, 1); + + --data e hora + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvform, idfieldsdate, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvform, idfieldstime, 1); + + --comentário + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvform, idfieldscomment, 1); + + --imagens + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvform, idfieldsimages, 1); +--End Pluviometer Form +--Begin River Form + INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) + SELECT fo.id, 'RIVERFLOOD_FORM', 'River Flood', 'River Flood Form', current_timestamp, 1 + FROM formsorigins fo + WHERE fo.name = 'WP6.MobileApp' + RETURNING id INTO idriverform; + + --situação + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idriverform, idfieldsituationcode, 1); + + --local (lat, log e endereço) + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idriverform, idfieldslatitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idriverform, idfieldslongitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idriverform, idfieldsaddress, 1); + + --data e hora + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idriverform, idfieldsdate, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idriverform, idfieldstime, 1); + + --comentário + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idriverform, idfieldscomment, 1); + + --imagens + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idriverform, idfieldsimages, 1); +--End River Form + +--Pluviometer Registration Form + INSERT INTO forms(idformsorigins, code, name, description, dtcreation, active) + SELECT fo.id, 'PLUVIOMETERS_REGISTRATION', 'Pluviometer registration', 'Pluviometer registration', current_timestamp, 1 + FROM formsorigins fo + WHERE fo.name = 'WP6.MobileApp' + RETURNING id INTO idpluvregsform; + + --local (lat, log e endereço) + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvregsform, idfieldslatitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvregsform, idfieldslongitude, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvregsform, idfieldsaddress, 1); + + --data e hora + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvregsform, idfieldsdate, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvregsform, idfieldstime, 1); + + --Instituição (tipo e nome) + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvregsform, idfieldsinstype, 1); + + INSERT INTO formsfields(id, idforms, idfields, active) + VALUES (DEFAULT, idpluvregsform, idfieldsinsname, 1); +--End Pluviometer Registration Form +END $$' diff --git a/db/floodzones-river-rain-api.json b/db/floodzones-river-rain-api.json new file mode 100644 index 0000000..6411857 --- /dev/null +++ b/db/floodzones-river-rain-api.json @@ -0,0 +1,46 @@ +JSON intended to get all forms + + +{ + "responseTimestamp": "2021-08-05T19:23:50.126Z", + "responseData": { + "array_to_json": [ + { + "code": "vegetation_sp_wsg84", + "name": "Vegetation_SP_WSG84 sh file", + "description": "Vegetation_SP_WSG84 shape file" + }, + { + "code": "FLOODZONES_FORM", + "name": "Flood Zones Form", + "description": "FloodZones Form" + }, + { + "code": "susceptibilidade_inundacao", + "name": "Áreas com Suscetibilidade a Inundação", + "description": "CPRM areas with classes of susceptibility to flooding" + }, + { + "code": "PLUVIOMETERS_FORM", + "name": "Pluviometers", + "description": "Pluviometers Form" + }, + { + "code": "RAIN_FORM", + "name": "Rain", + "description": "Rain zones Form" + }, + { + "code": "RIVERFLOOD_FORM", + "name": "River Flood", + "description": "River Flood Form" + }, + { + "code": "PLUVIOMETERS_REGISTRATION", + "name": "Pluviometer registration", + "description": "Pluviometer registration" + } + ] + }, + "success": true +} diff --git a/db/forms-fields-answers.json b/db/forms-fields-answers.json new file mode 100644 index 0000000..d6adf88 --- /dev/null +++ b/db/forms-fields-answers.json @@ -0,0 +1,21 @@ +This example for floodzones also applies for river and rain. All fields are equal. + + +{ +"responseData": { + "array_to_json": [{ + "formcode": "FLOODZONES_FORM", + "formsanswersuserinformer": "admin@wpd.com", + "filds": [{ + "fieldsanswerssituation": "intransitavel", + "fieldsanswerslatitude": 4.750550953715424, + "fieldsanswerslongitude": -74.1179903701844, + "fieldsanswerseventaddress": "Rua dos bobos, 81", + "fieldsanswerseventdate": "11-08-2021", + "fieldsanswerseventtime": "21:52", + "fielsanswercomment": "users description about the current event", + "fieldsanswerimages": "base64" + }] + }] + } +} diff --git a/db/pluviometer-api.json b/db/pluviometer-api.json new file mode 100644 index 0000000..98c6a5a --- /dev/null +++ b/db/pluviometer-api.json @@ -0,0 +1,18 @@ +JSON intended to display pluviometer icons on map + + +{ + "responseData": { + "array_to_json": [{ + "formcode": "PLUVIOMETERS_FORM", + "formsanswersuserinformer": "admin@wpd.com", + "fieldsanswerslatitude": 4.750550953715424, + "fieldsanswerslongitude": -74.1179903701844 + }, + "formcode": "PLUVIOMETERS_FORM", + "formsanswersuserinformer": "admin222@wpd.com", + "fieldsanswerslatitude": 4.23876482872188, + "fieldsanswerslongitude": -79.1179903701844 + }] + } +} diff --git a/db/pluviometer-modal-api.json b/db/pluviometer-modal-api.json new file mode 100644 index 0000000..46e7a1a --- /dev/null +++ b/db/pluviometer-modal-api.json @@ -0,0 +1,27 @@ +JSON intended to display pluviometer data on modal + + +{ + "responseData": { + "array_to_json": [{ + "formcode": "PLUVIOMETERS_FORM", + "formsanswersuserinformer": "admin@wpd.com", + "fias": [{ + "username" : "Fulano", + "userrole" : "Professor", + "institutionname": "E.E. Vicente Leporace", + "address" : "Rua Nassau", + "images" : "base64", + "pluviometerformsanswers" : [ + {"fieldsanswersdate": "11/02", "fieldsanswersrainamount": 5}, + {"fieldsanswersdate": "10/02", "fieldsanswersrainamount": 5}, + {"fieldsanswersdate": "9/02", "fieldsanswersrainamount": 5}, + {"fieldsanswersdate": "8/02", "fieldsanswersrainamount": 5}, + {"fieldsanswersdate": "7/02", "fieldsanswersrainamount": 5}, + {"fieldsanswersdate": "6/02", "fieldsanswersrainamount": 5}, + {"fieldsanswersdate": "2/02", "fieldsanswersrainamount": 5} + ] + }] + }] + } +} diff --git a/db/pluviometer-register-api.json b/db/pluviometer-register-api.json new file mode 100644 index 0000000..fad8071 --- /dev/null +++ b/db/pluviometer-register-api.json @@ -0,0 +1,20 @@ +This JSON is used to insert Pluviometer data into datalake + + +{ +"responseData": { + "array_to_json": [{ + "formcode": "PLUVIOMETERS_REGISTRATION", + "formsanswersuserinformer": "admin@wpd.com", + "filds": [{ + "fieldsanswerslatitude": 4.750550953715424, + "fieldsanswerslongitude": -74.1179903701844, + "fieldsanswerseventaddress": "Rua dos bobos, 81", + "fieldsanswerseventdate": "11-08-2021", + "fieldsanswerseventtime": "21:52", + "fieldsanswersinstitutename": "E. E. Vagner", + "fieldsanswerrinstitutetype": "Escola" + }] + }] + } +}