|
@ -1,4 +1,5 @@ |
|
|
import { useEffect, useReducer } from "react"; |
|
|
import { useEffect, useReducer } from "react"; |
|
|
|
|
|
|
|
|
import "../config/globals"; |
|
|
import "../config/globals"; |
|
|
|
|
|
|
|
|
const assets = { |
|
|
const assets = { |
|
@ -26,7 +27,27 @@ var displacement = 0; |
|
|
|
|
|
|
|
|
var ID = 0; |
|
|
var ID = 0; |
|
|
|
|
|
|
|
|
|
|
|
var fetched_data = new Map([ |
|
|
|
|
|
["pluv", new Set()], |
|
|
|
|
|
["flood", new Set()], |
|
|
|
|
|
["rain", new Set()], |
|
|
|
|
|
["river", new Set()], |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
function is_valid(id, category) { |
|
|
|
|
|
if (fetched_data.get(category).has(id)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} else { |
|
|
|
|
|
fetched_data.get(category).add(id); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function partsePluviometer(row) { |
|
|
function partsePluviometer(row) { |
|
|
|
|
|
if (!is_valid(row["Id"], "pluv")) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
displacement += offset; |
|
|
displacement += offset; |
|
|
return { |
|
|
return { |
|
|
ID: ++ID, |
|
|
ID: ++ID, |
|
@ -41,6 +62,10 @@ function partsePluviometer(row) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function parseFloodZones(row) { |
|
|
function parseFloodZones(row) { |
|
|
|
|
|
if (!is_valid(row["Id"], "flood")) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
displacement += offset; |
|
|
displacement += offset; |
|
|
return { |
|
|
return { |
|
|
ID: ++ID, |
|
|
ID: ++ID, |
|
@ -55,6 +80,10 @@ function parseFloodZones(row) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function parseRiverLevel(row) { |
|
|
function parseRiverLevel(row) { |
|
|
|
|
|
if (!is_valid(row["Id"], "river")) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
displacement += offset; |
|
|
displacement += offset; |
|
|
const riverLevel = ["Baixo", "Rio normal", "Alto", "Transfordando"]; |
|
|
const riverLevel = ["Baixo", "Rio normal", "Alto", "Transfordando"]; |
|
|
const riverIdx = row["RiverIdx"]; |
|
|
const riverIdx = row["RiverIdx"]; |
|
@ -71,6 +100,10 @@ function parseRiverLevel(row) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function parseRainLevel(row) { |
|
|
function parseRainLevel(row) { |
|
|
|
|
|
if (!is_valid(row["Id"], "rain")) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
displacement += offset; |
|
|
displacement += offset; |
|
|
const rainLevel = [ |
|
|
const rainLevel = [ |
|
|
"Sem chuva", |
|
|
"Sem chuva", |
|
@ -98,20 +131,26 @@ function parseResult(db_result, parseRow) { |
|
|
|
|
|
|
|
|
for (let i = 0; i < db_result.rows.length; ++i) { |
|
|
for (let i = 0; i < db_result.rows.length; ++i) { |
|
|
var row = db_result.rows.item(i); |
|
|
var row = db_result.rows.item(i); |
|
|
warnings.push(parseRow(row)); |
|
|
|
|
|
|
|
|
const data = parseRow(row); |
|
|
|
|
|
if (data !== null) { |
|
|
|
|
|
warnings.push(data); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return warnings; |
|
|
return warnings; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function genericSelect(dispatch, query, parseFunction) { |
|
|
|
|
|
|
|
|
function genericSelect(queriesToParsersMapper, dispatch, isFocused) { |
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
|
|
|
console.log("requesting data"); |
|
|
|
|
|
queriesToParsersMapper.forEach(([query, parser]) => { |
|
|
global.userDataBase.transaction((tx) => { |
|
|
global.userDataBase.transaction((tx) => { |
|
|
tx.executeSql(query, [], (tx, results) => { |
|
|
tx.executeSql(query, [], (tx, results) => { |
|
|
dispatch({ increment: parseResult(results, parseFunction) }); |
|
|
|
|
|
|
|
|
dispatch({ increment: parseResult(results, parser) }); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}, []); |
|
|
|
|
|
|
|
|
}, [isFocused]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const initialState = { markers: new Set() }; |
|
|
const initialState = { markers: new Set() }; |
|
@ -126,7 +165,7 @@ function reducer(state = initialState, action) { |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function useMarkers() { |
|
|
|
|
|
|
|
|
function useMarkers(isFocused) { |
|
|
const [state, dispatch] = useReducer(reducer, initialState); |
|
|
const [state, dispatch] = useReducer(reducer, initialState); |
|
|
|
|
|
|
|
|
const queriesToParsersMapper = [ |
|
|
const queriesToParsersMapper = [ |
|
@ -136,10 +175,7 @@ function useMarkers() { |
|
|
["SELECT * FROM RainLevel;", parseRainLevel], |
|
|
["SELECT * FROM RainLevel;", parseRainLevel], |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
queriesToParsersMapper.forEach(([query, parser]) => { |
|
|
|
|
|
console.log(query); |
|
|
|
|
|
genericSelect(dispatch, query, parser); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
genericSelect(queriesToParsersMapper, dispatch, isFocused); |
|
|
|
|
|
|
|
|
return state; |
|
|
return state; |
|
|
} |
|
|
} |
|
|