Added timeout processing

This commit is contained in:
kunkliricsi 2020-11-21 19:18:29 +01:00
parent 73157520ab
commit 04c27560ea
5 changed files with 126 additions and 82 deletions

View File

@ -42,6 +42,7 @@ class Dashboard extends Component {
this.updateSeries = this.updateSeries.bind(this); this.updateSeries = this.updateSeries.bind(this);
this.updateDynamic = this.updateDynamic.bind(this); this.updateDynamic = this.updateDynamic.bind(this);
this.performTask = this.performTask.bind(this);
} }
static contextType = DevicesContext; static contextType = DevicesContext;
@ -112,7 +113,8 @@ class Dashboard extends Component {
} }
updateDynamic() { updateDynamic() {
const secondAgo = new Date( Date.now() - 1000 * 1 ); const secondAgo = new Date();
secondAgo.setMilliseconds(0);
const minuteAgo = new Date( Date.now() - 1000 * 60 ); const minuteAgo = new Date( Date.now() - 1000 * 60 );
const hourAgo = new Date( Date.now() - 1000 * 60 * 60 ); const hourAgo = new Date( Date.now() - 1000 * 60 * 60 );
@ -127,7 +129,8 @@ class Dashboard extends Component {
barDevicePoints[d.id] = Array(3).fill(0); barDevicePoints[d.id] = Array(3).fill(0);
} }
for (var p of this.context.heatmapPoints) { const processMethod = (items, index) => {
const p = items[index];
if (p.date > minuteAgo) { if (p.date > minuteAgo) {
var seconds = Math.floor((p.date.getTime() - minuteAgo.getTime()) / 1000); var seconds = Math.floor((p.date.getTime() - minuteAgo.getTime()) / 1000);
var oldProb = minuteDevicePoints[p.deviceId][seconds]; var oldProb = minuteDevicePoints[p.deviceId][seconds];
@ -165,6 +168,7 @@ class Dashboard extends Component {
} }
} }
const finishMethod = () => {
const minuteHeatmapSeries = []; const minuteHeatmapSeries = [];
var i = 0; var i = 0;
@ -245,6 +249,34 @@ class Dashboard extends Component {
}); });
} }
const processHeatmapItem = processMethod.bind(this);
const onFinished = finishMethod.bind(this)
this.performTask(this.context.heatmapPoints, 10, 150,
processHeatmapItem, onFinished);
}
performTask(items, numToProcess, wait, processItem, onFinished) {
var pos = 0;
// This is run once for every numToProcess items.
function iteration() {
// Calculate last position.
var j = Math.min(pos + numToProcess, items.length);
// Start at current position and loop to last position.
for (var i = pos; i < j; i++) {
processItem(items, i);
}
// Increment current position.
pos += numToProcess;
// Only continue if there are more items to process.
if (pos < items.length)
setTimeout(iteration, wait); // Wait 10 ms to let the UI update.
else
onFinished();
}
iteration();
}
render() { render() {
const { classes } = this.props; const { classes } = this.props;
return ( return (
@ -265,22 +297,22 @@ class Dashboard extends Component {
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>
<Paper className={classes.paper}> <Paper className={classes.paper}>
<HeatmapChart label="Highest probability per devices by seconds" series={this.state.heatmapSecondsSeries}/> <HeatmapChart label="Highest probability per second by devices" series={this.state.heatmapSecondsSeries}/>
</Paper> </Paper>
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>
<Paper className={classes.paper}> <Paper className={classes.paper}>
<HeatmapChart label="Highest probability per devices by minutes" series={this.state.heatmapMinutesSeries}/> <HeatmapChart label="Highest probability per minute by devices" series={this.state.heatmapMinutesSeries}/>
</Paper> </Paper>
</Grid> </Grid>
<Grid item xs={6}> <Grid item xs={6}>
<Paper className={classes.paper}> <Paper className={classes.paper}>
<BarChart label="# of messages per device" series={this.state.barSeries} categories={this.state.barCategories}/> <BarChart label="# of messages by devices" series={this.state.barSeries} categories={this.state.barCategories}/>
</Paper> </Paper>
</Grid> </Grid>
<Grid item xs={6}> <Grid item xs={6}>
<Paper className={classes.paper}> <Paper className={classes.paper}>
<LineChart label="# of messages by second" series={this.state.lineSeries}/> <LineChart label="# of messages per second" series={this.state.lineSeries}/>
</Paper> </Paper>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -16,6 +16,18 @@ export class BarChart extends Component {
this.setState({options: { this.setState({options: {
chart: { chart: {
stacked: true, stacked: true,
animations: {
enabled: true,
easing: 'linear',
speed: 250,
animateGradually: {
enabled: false,
},
dynamicAnimation: {
enabled: true,
speed: 250
}
},
}, },
plotOptions: { plotOptions: {
bar: { bar: {

View File

@ -12,13 +12,13 @@ export class LineChart extends Component {
animations: { animations: {
enabled: true, enabled: true,
easing: 'linear', easing: 'linear',
speed: 1000, speed: 250,
animateGradually: { animateGradually: {
enabled: false, enabled: false,
}, },
dynamicAnimation: { dynamicAnimation: {
enabled: false, enabled: true,
speed: 1000 speed: 250
} }
}, },
zoom: { zoom: {

View File

@ -1,4 +1,4 @@
import { Box, Grid, IconButton, Paper, Typography } from '@material-ui/core'; import { Grid, IconButton, Paper, Typography } from '@material-ui/core';
import { blueGrey } from '@material-ui/core/colors'; import { blueGrey } from '@material-ui/core/colors';
import { AddBox, Refresh } from '@material-ui/icons/'; import { AddBox, Refresh } from '@material-ui/icons/';
import { withStyles } from '@material-ui/styles'; import { withStyles } from '@material-ui/styles';

View File

@ -16,9 +16,9 @@ class DeviceMarker extends Component {
getColor() { getColor() {
const { device } = this.props; const { device } = this.props;
if (device.status == "Online") { if (device.status === "Online") {
return { color: blue[800] }; return { color: blue[800] };
} else if (device.status == "Offline") { } else if (device.status === "Offline") {
return { color: yellow[800] }; return { color: yellow[800] };
} else /* if (device.status == "unknown") */ { } else /* if (device.status == "unknown") */ {
return { color: red[800] }; return { color: red[800] };