Commit 611370c9 authored by alain's avatar alain 🐙
Browse files

initial commit

parents
.DS_Store
[submodule "frontend/data-on-a-map-app"]
path = frontend/data-on-a-map-app
url = https://git.waag.org/alain/data-on-a-map-app.git
# gammasense-data-app
Repository for gammasense instance of the data-on-map-app (as git submodule)
- backend folder contains data handling server
- frontend folder contains submodule and configuration files
\ No newline at end of file
# gammasense-data-app backend
## to install:
## to start:
# gammasense-data-app frontend
## to install
`cd data-on-a-map-app`
`npm install`
## to start
`npm start`
Starts the local server on localhost:3000
## to build
`npm run build`
Builds the app for production to the `build` folder.
import gammasense from "./sources/gammasense"
const colors = [
"#f1aa2a",
"#db246b",
"#552a80"
]
export const initialLayers = ["pm25"]
export const dataGroups = [
{
title: "data",
parameters: {
"pm25": {
id: "pm25",
label: "gamma radiation",
unit: " μg/m3",
range: [0, 150],
legend: {
0: { label: "Good", color: colors[0] },
70: { label: "Bad", color: colors[1] },
150: { label: "Very bad", color: colors[2] },
},
tooltip: "",
type: "StationLayer",
sources: [ gammasense ]
}
}
}
]
This diff is collapsed.
import { addMissingHours, calculateHourlyData } from "../../data-on-a-map-app/src/util/data"
import { roundBy } from "../../data-on-a-map-app/src/util/math"
export default {
name: "gammasense",
sides: 5,
angle: 0,
factor: 0.5,
all: async function getAll(parameter) {
try {
const allResponse = await fetch(`http://localhost:8080/api/v1/get_stations`)
const all = await allResponse.json()
const latestResponse = await fetch(`http://localhost:8080/api/v1/get_latest_value?sensor_id=all`)
const latest = await latestResponse.json()
let offlineSensors = []
let unregisteredSensors = []
let places = {}
var prefix
if (parameter === "pm25") prefix = "p25"
const data = all.map(sensor => {
let sensorData = latest.find(o => o.ms === sensor.ms)
const place = (sensor.city_id ? sensor.city_id.city_name : null)
if(sensorData) {
if(sensor.city_id) {
if(!places[place]) places[place] = {
all: [],
}
places[place].all.push(sensorData[`${prefix}`])
}
return {
id: sensor.ms.toString(),
name: sensor.ms.toString() + " " + place,
type: null,
source: "muv",
coordinates: [sensor.latitude, sensor.longitude].reverse(),
place: place,
mean: sensorData[`${prefix}`]
//max: sensorData[`${parameter}_max`]
}
} else {
offlineSensors.push(sensor.ms)
return {
id: sensor.ms.toString(),
name: sensor.ms.toString() + " " + (sensor.city_id ? sensor.city_id.city_name : null) + " (offline)",
type: null,
source: "muv",
coordinates: [sensor.latitude, sensor.longitude].reverse(),
mean: null,
max: null
}
}
})
latest.forEach(sensor => {
if(!all.find(o => +o.ms === +sensor.ms)) {
unregisteredSensors.push(sensor.ms)
}
})
console.log(`Offline Sensors (${offlineSensors.length}):`, offlineSensors.sort((a, b) => a - b).join(', '))
console.log(`Unregistered Sensors (${unregisteredSensors.length}):`, unregisteredSensors.sort((a, b) => a - b).join(', '))
Object.keys(places).forEach(function(place) {
console.log(place)
places[place].amount = places[place].all.length
places[place].average = roundBy(places[place].all.reduce((a, b) => a + b, 0) / places[place].all.length, 1)
places[place].highest = Math.max(...places[place].all)
})
console.log(places)
return data
} catch (error) {
console.log(error)
}
},
detail: async function getDetail(station, parameter, start, end) {
try {
const stationInfo = {
type: station.id,
name: station.name,
description: ""
}
const response = await fetch(`http://localhost:8080/api/v1/get_sensor_value?sensor_id=${station.id}&start=${start}&end=${end}`)
const responseData = await response.json()
var prefix
if (parameter === "pm25") prefix = "p25"
const hourlyData = calculateHourlyData(responseData, prefix).reverse()
const conformedData = hourlyData.map(m => { return { ...m, timestamp: new Date(m.timestamp).getTime() }})
const data = addMissingHours(conformedData) //.reverse()
return { stationInfo, data }
} catch (error) {
console.log(error)
}
}
}
\ No newline at end of file
data-on-a-map-app @ 96f16bf2
Subproject commit 96f16bf26d3d979a319bc5caab394aed04842bad
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment