|
|
|
@@ -5,35 +5,23 @@ import Datetime from 'react-datetime';
|
|
|
|
|
import 'react-datetime/css/react-datetime.css';
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import moment from 'moment-timezone';
|
|
|
|
|
import RangeSlider from 'react-range-slider-input';
|
|
|
|
|
import './App.css';
|
|
|
|
|
import 'leaflet/dist/leaflet.css';
|
|
|
|
|
import 'react-range-slider-input/dist/style.css';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let tzcache = {};
|
|
|
|
|
|
|
|
|
|
// num: number of steps per duration
|
|
|
|
|
// secs: number of seconds per step
|
|
|
|
|
const durations = [
|
|
|
|
|
{id: 0, len: 'Day', win: '1m', full: '1 min', delta: [1, 'days'], format: 'HH'},
|
|
|
|
|
{id: 1, len: 'Week', win: '3m', full: '3 min', delta: [7, 'days'], format: 'HH'},
|
|
|
|
|
{id: 2, len: 'Week', win: '10m', full: '10 min', delta: [7, 'days'], format: 'HH'},
|
|
|
|
|
{id: 3, len: 'Month', win: '10m', full: '10 min', delta: [1, 'months'], format: 'D'},
|
|
|
|
|
{id: 4, len: 'Month', win: '1h', full: '1 hour', delta: [1, 'months'], format: 'D'},
|
|
|
|
|
{id: 5, len: 'Year', win: '2h', full: '2 hours', delta: [1, 'years'], format: 'M/D'},
|
|
|
|
|
{id: 6, len: 'Year', win: '1d', full: '1 day', delta: [1, 'years'], format: 'M/D'},
|
|
|
|
|
{id: 0, len: 'Day', win: '1m', full: '1 min', delta: [1, 'days'], format: 'HH', num: 1440, secs: 60},
|
|
|
|
|
{id: 1, len: 'Week', win: '3m', full: '3 min', delta: [7, 'days'], format: 'HH', num: 3360, secs: 180},
|
|
|
|
|
{id: 2, len: 'Month', win: '10m', full: '10 min', delta: [1, 'months'], format: 'D', num: 4380, secs: 600},
|
|
|
|
|
{id: 3, len: 'Year', win: '2h', full: '2 hour', delta: [1, 'years'], format: 'M/D', num: 4380, secs: 7200},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const units = {
|
|
|
|
|
'PM10': ' ug/m³',
|
|
|
|
|
'PM2.5': ' ug/m³',
|
|
|
|
|
'VOC': ' / 500',
|
|
|
|
|
'CO2': ' ppm',
|
|
|
|
|
'Energy': ' kWh',
|
|
|
|
|
'Power': ' W',
|
|
|
|
|
'Temperature': ' °C',
|
|
|
|
|
'Humidity': '%',
|
|
|
|
|
'Setpoint': ' °C',
|
|
|
|
|
'State': '',
|
|
|
|
|
'Lux': ' lx',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function useSensor(measurement, name, end, duration) {
|
|
|
|
|
const [data, setData] = useState(false);
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
@@ -63,10 +51,10 @@ function useSensor(measurement, name, end, duration) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Owntracks({end, duration}) {
|
|
|
|
|
function Owntracks({end, duration, range}) {
|
|
|
|
|
const [data, loading] = useSensor('owntracks', 'OwnTracks', end, duration);
|
|
|
|
|
|
|
|
|
|
const coords = data.length ? data.map(({ lat, lon }) => [lat, lon]).filter(([lat, lon]) => lat !== null || lon !== null) : [];
|
|
|
|
|
const coords = data.length ? data.filter(x => !range || (x.time >= range[0] && x.time <= range[1])).map(({ lat, lon }) => [lat, lon]).filter(([lat, lon]) => lat !== null || lon !== null) : [];
|
|
|
|
|
|
|
|
|
|
const handleSubmit = (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
@@ -102,46 +90,74 @@ function Owntracks({end, duration}) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Graphs({end, duration}) {
|
|
|
|
|
function Graphs({end, duration, range}) {
|
|
|
|
|
return (
|
|
|
|
|
<div className='container'>
|
|
|
|
|
<Owntracks end={end} duration={duration} />
|
|
|
|
|
<Owntracks end={end} duration={duration} range={range} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Menu({duration, setDuration, end, setEnd}) {
|
|
|
|
|
function Menu({duration, setDuration, end, setEnd, range, setRange}) {
|
|
|
|
|
const [submenu, setSubmenu] = useState(false);
|
|
|
|
|
const [showRange, setShowRange] = useState(false);
|
|
|
|
|
|
|
|
|
|
const chooseDuration = (x) => {
|
|
|
|
|
setSubmenu(false);
|
|
|
|
|
setRange(false);
|
|
|
|
|
setDuration(x);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const chooseEnd = (x) => {
|
|
|
|
|
setSubmenu(false);
|
|
|
|
|
const newEnd = x.add(...duration.delta);
|
|
|
|
|
setRange(false);
|
|
|
|
|
setEnd(newEnd);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const chooseNow = (x) => {
|
|
|
|
|
setSubmenu(false);
|
|
|
|
|
setRange(false);
|
|
|
|
|
setEnd(moment());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const next = () => {
|
|
|
|
|
setSubmenu(false);
|
|
|
|
|
setRange(false);
|
|
|
|
|
setEnd(prevEnd => moment(prevEnd).add(...duration.delta));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const prev = () => {
|
|
|
|
|
setSubmenu(false);
|
|
|
|
|
setRange(false);
|
|
|
|
|
setEnd(prevEnd => moment(prevEnd).subtract(...duration.delta));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onSlider = (slider) => {
|
|
|
|
|
console.log(slider);
|
|
|
|
|
// good luck remembering how this works
|
|
|
|
|
const lowOffset = slider[0] * duration.secs - duration.num * duration.secs;
|
|
|
|
|
const highOffset = slider[1] * duration.secs - duration.num * duration.secs;
|
|
|
|
|
|
|
|
|
|
const low = moment.unix(end.unix() + lowOffset);
|
|
|
|
|
const high = moment.unix(end.unix() + highOffset);
|
|
|
|
|
|
|
|
|
|
const lowStr = low.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
|
|
|
|
const highStr = high.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
|
|
|
|
|
|
|
|
|
console.log(lowStr, highStr);
|
|
|
|
|
setRange([lowStr, highStr]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='menu'>
|
|
|
|
|
{!!submenu &&<div className='submenu'>
|
|
|
|
|
{showRange && <div className='range'>
|
|
|
|
|
{moment(range[0]).format('lll')} - {moment(range[1]).format('lll')}
|
|
|
|
|
</div>}
|
|
|
|
|
|
|
|
|
|
{submenu ?
|
|
|
|
|
<div className='submenu'>
|
|
|
|
|
{submenu === 'end' &&
|
|
|
|
|
<>
|
|
|
|
|
<div className='submenu-header'>
|
|
|
|
@@ -169,11 +185,26 @@ function Menu({duration, setDuration, end, setEnd}) {
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{durations.map(x =>
|
|
|
|
|
<button key={x.id} onClick={() => chooseDuration(x)}>Last {x.len} / {x.full} data</button>
|
|
|
|
|
<button key={x.id} onClick={() => chooseDuration(x)}>Last {x.len} ({x.full} data)</button>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
</div>}
|
|
|
|
|
</div>
|
|
|
|
|
:
|
|
|
|
|
<div className='time-slider'>
|
|
|
|
|
<RangeSlider
|
|
|
|
|
min={0}
|
|
|
|
|
max={duration.num}
|
|
|
|
|
defaultValue={[0, duration.num]}
|
|
|
|
|
onInput={onSlider}
|
|
|
|
|
onThumbDragStart={() => setShowRange(true)}
|
|
|
|
|
onThumbDragEnd={() => setShowRange(false)}
|
|
|
|
|
onRangeDragStart={() => setShowRange(true)}
|
|
|
|
|
onRangeDragEnd={() => setShowRange(false)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<div className='menu-container'>
|
|
|
|
|
<button onClick={() => prev()}><</button>
|
|
|
|
@@ -201,6 +232,7 @@ function Menu({duration, setDuration, end, setEnd}) {
|
|
|
|
|
function App() {
|
|
|
|
|
const [duration, setDuration] = useState(durations[0]);
|
|
|
|
|
const [end, setEnd] = useState(moment());
|
|
|
|
|
const [range, setRange] = useState(false);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
@@ -209,11 +241,14 @@ function App() {
|
|
|
|
|
setDuration={setDuration}
|
|
|
|
|
end={end}
|
|
|
|
|
setEnd={setEnd}
|
|
|
|
|
range={range}
|
|
|
|
|
setRange={setRange}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Graphs
|
|
|
|
|
end={end}
|
|
|
|
|
duration={duration}
|
|
|
|
|
range={range}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|