|
@ -182,6 +182,13 @@ function reducer(state = initialState, action) { |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function compare(a, b) { |
|
|
|
|
|
if (a == b) return 0; |
|
|
|
|
|
if (parseInt(a[0].slice(3, 5)) < parseInt(b[0].slice(3, 5))) return -1; |
|
|
|
|
|
else if (parseInt(a[0].slice(0, 2)) < parseInt(b[0].slice(0, 2))) return -1; |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function useMarkers(isFocused) { |
|
|
function useMarkers(isFocused) { |
|
|
const [state, dispatch] = useReducer(reducer, initialState); |
|
|
const [state, dispatch] = useReducer(reducer, initialState); |
|
|
|
|
|
|
|
@ -190,39 +197,51 @@ function useMarkers(isFocused) { |
|
|
const addr = context.currentLocation; |
|
|
const addr = context.currentLocation; |
|
|
|
|
|
|
|
|
const parsePluviometer = (db_result) => { |
|
|
const parsePluviometer = (db_result) => { |
|
|
if (db_result.rows.length <= 0) return []; |
|
|
|
|
|
|
|
|
// if (db_result.rows.length <= 0) return [];
|
|
|
|
|
|
const points = []; |
|
|
|
|
|
|
|
|
const values = { |
|
|
|
|
|
pictures: null, |
|
|
|
|
|
data: { |
|
|
|
|
|
labels: [], |
|
|
|
|
|
values: [], |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
const info = { |
|
|
|
|
|
pictures: "[]", |
|
|
description: "", |
|
|
description: "", |
|
|
date: "", |
|
|
date: "", |
|
|
}; |
|
|
}; |
|
|
const start = Math.max(0, db_result.rows.length - 7); |
|
|
|
|
|
for (let i = start; 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); |
|
|
|
|
|
|
|
|
description = row["Description"] ? "\n\n" + row["Description"] : ""; |
|
|
description = row["Description"] ? "\n\n" + row["Description"] : ""; |
|
|
|
|
|
|
|
|
values.image = custom_assets.pluviometer; |
|
|
|
|
|
values.date = row["Date"]; |
|
|
|
|
|
values.description = |
|
|
|
|
|
|
|
|
info.date = row["Date"]; |
|
|
|
|
|
info.description = |
|
|
row["Precipitation"] + "mm" + ", " + row["Date"] + description; |
|
|
row["Precipitation"] + "mm" + ", " + row["Date"] + description; |
|
|
values.pictures = row["Images"]; |
|
|
|
|
|
values.data.labels.push(row["Date"].slice(0, 5)); |
|
|
|
|
|
values.data.values.push(parseInt(row["Precipitation"])); |
|
|
|
|
|
|
|
|
info.pictures = row["Images"]; |
|
|
|
|
|
|
|
|
|
|
|
points.push([row["Date"].slice(0, 5), parseInt(row["Precipitation"])]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
latestPoints = points.sort(compare).slice(-7); |
|
|
|
|
|
if (latestPoints.length == 0) { |
|
|
|
|
|
var labels = []; |
|
|
|
|
|
var values = []; |
|
|
} |
|
|
} |
|
|
|
|
|
var labels = latestPoints.map((i) => { |
|
|
|
|
|
return i[0]; |
|
|
|
|
|
}); |
|
|
|
|
|
var values = latestPoints.map((i) => { |
|
|
|
|
|
return i[1]; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const result = { |
|
|
const result = { |
|
|
|
|
|
image: custom_assets.pluviometer, |
|
|
ID: ++ID, |
|
|
ID: ++ID, |
|
|
name: "pluviometer", |
|
|
name: "pluviometer", |
|
|
title: "Pluviometro 1", |
|
|
title: "Pluviometro 1", |
|
|
coordinate: location, |
|
|
coordinate: location, |
|
|
address: addr, |
|
|
address: addr, |
|
|
...values, |
|
|
|
|
|
|
|
|
data: { |
|
|
|
|
|
labels: labels, |
|
|
|
|
|
values: values, |
|
|
|
|
|
}, |
|
|
|
|
|
...info, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
console.log(result); |
|
|
console.log(result); |
|
|