Try without timer.

This commit is contained in:
Andrés Uribe Stengel 2020-07-16 15:07:54 +02:00
parent 40c5dc2cb0
commit 76eb9012fa
2 changed files with 94 additions and 90 deletions

View File

@ -29,7 +29,5 @@ Meteor.startup(() => {
Meteor.subscribe('activeDeviceCollection'); Meteor.subscribe('activeDeviceCollection');
} }
Meteor.setTimeout(function() {
ReactDOM.render(<App />, document.getElementById('root')); ReactDOM.render(<App />, document.getElementById('root'));
}, 1250);
}); });

View File

@ -10,7 +10,7 @@ export default function Home() {
const uniqueEspNames = _.uniq(SensorDataCollection.find({}, { const uniqueEspNames = _.uniq(SensorDataCollection.find({}, {
sort: {device_id: 1}, fields: {device_id: true} sort: {device_id: 1}, fields: {device_id: true}
}).fetch().map(function(x) { }).fetch().map(function (x) {
return x.device_id; return x.device_id;
}), true); }), true);
@ -19,18 +19,23 @@ export default function Home() {
}); });
const sensorData = useTracker(() => { const sensorData = useTracker(() => {
return SensorDataCollection.find({ device_id: deviceName.deviceName }, { sort: { timestamp: -1 }, limit: 61 }).fetch().reverse(); return SensorDataCollection.find({device_id: deviceName.deviceName}, {
sort: {timestamp: -1},
limit: 61
}).fetch().reverse();
}); });
const handleChange = (e) => { const handleChange = (e) => {
if (e.target.value === "") {console.log("No device selected!");} else { if (e.target.value === "") {
var doc = ActiveDeviceCollection.findOne({ deviceName: deviceName.deviceName }); console.log("No device selected!");
ActiveDeviceCollection.update({ _id: doc._id }, {$set:{deviceName: e.target.value}}); } else {
var doc = ActiveDeviceCollection.findOne({deviceName: deviceName.deviceName});
ActiveDeviceCollection.update({_id: doc._id}, {$set: {deviceName: e.target.value}});
} }
} }
/*if (sensorData.length <= 0) { if ((sensorData.length <= 0) || (deviceName.length <= 0) || (uniqueEspNames.length <= 0)) {
return ( return (
<CardDeck> <CardDeck>
<Card> <Card>
@ -41,7 +46,7 @@ export default function Home() {
</Card> </Card>
</CardDeck> </CardDeck>
) )
} else {}*/ } else {
return ( return (
<> <>
<Row> <Row>
@ -55,7 +60,7 @@ export default function Home() {
<Form.Group> <Form.Group>
<Form.Control as="select" type="text" onChange={handleChange}> <Form.Control as="select" type="text" onChange={handleChange}>
<option></option> <option></option>
{uniqueEspNames.map((espName, index) =>{ {uniqueEspNames.map((espName, index) => {
return <option key={index} value={espName}>{espName}</option> return <option key={index} value={espName}>{espName}</option>
})} })}
</Form.Control> </Form.Control>
@ -71,25 +76,25 @@ export default function Home() {
<Row> <Row>
<Col> <Col>
<ResponsiveContainer width='100%' height={350}> <ResponsiveContainer width='100%' height={350}>
<LineChart data={sensorData} margin={{ top: 50, right: 50, bottom: 25, left: 5 }}> <LineChart data={sensorData} margin={{top: 50, right: 50, bottom: 25, left: 5}}>
<Line type="monotone" dataKey="temperature" stroke="#10b5de" /> <Line type="monotone" dataKey="temperature" stroke="#10b5de"/>
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/> <CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
<XAxis dataKey="timeAsString" /> <XAxis dataKey="timeAsString"/>
<YAxis /> <YAxis/>
<Tooltip /> <Tooltip/>
<Legend /> <Legend/>
</LineChart> </LineChart>
</ResponsiveContainer> </ResponsiveContainer>
</Col> </Col>
<Col> <Col>
<ResponsiveContainer width='100%' height={350}> <ResponsiveContainer width='100%' height={350}>
<LineChart data={sensorData} margin={{ top: 50, right: 50, bottom: 25, left: 5 }}> <LineChart data={sensorData} margin={{top: 50, right: 50, bottom: 25, left: 5}}>
<Line type="monotone" dataKey="humidity" stroke="#ff6f00" /> <Line type="monotone" dataKey="humidity" stroke="#ff6f00"/>
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/> <CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
<XAxis dataKey="timeAsString" /> <XAxis dataKey="timeAsString"/>
<YAxis /> <YAxis/>
<Tooltip /> <Tooltip/>
<Legend /> <Legend/>
</LineChart> </LineChart>
</ResponsiveContainer> </ResponsiveContainer>
</Col> </Col>
@ -97,29 +102,30 @@ export default function Home() {
<Row> <Row>
<Col> <Col>
<ResponsiveContainer width='100%' height={350}> <ResponsiveContainer width='100%' height={350}>
<LineChart data={sensorData} margin={{ top: 50, right: 50, bottom: 25, left: 5 }}> <LineChart data={sensorData} margin={{top: 50, right: 50, bottom: 25, left: 5}}>
<Line type="monotone" dataKey="brightness" stroke="#ffd500" /> <Line type="monotone" dataKey="brightness" stroke="#ffd500"/>
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/> <CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
<XAxis dataKey="timeAsString" /> <XAxis dataKey="timeAsString"/>
<YAxis /> <YAxis/>
<Tooltip /> <Tooltip/>
<Legend /> <Legend/>
</LineChart> </LineChart>
</ResponsiveContainer> </ResponsiveContainer>
</Col> </Col>
<Col> <Col>
<ResponsiveContainer width='100%' height={350}> <ResponsiveContainer width='100%' height={350}>
<LineChart data={sensorData} margin={{ top: 50, right: 50, bottom: 25, left: 5 }}> <LineChart data={sensorData} margin={{top: 50, right: 50, bottom: 25, left: 5}}>
<Line type="monotone" dataKey="moisture" stroke="#1c4399" /> <Line type="monotone" dataKey="moisture" stroke="#1c4399"/>
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/> <CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
<XAxis dataKey="timeAsString" /> <XAxis dataKey="timeAsString"/>
<YAxis /> <YAxis/>
<Tooltip /> <Tooltip/>
<Legend /> <Legend/>
</LineChart> </LineChart>
</ResponsiveContainer> </ResponsiveContainer>
</Col> </Col>
</Row> </Row>
</> </>
) )
}
} }