Make timestamp type date again and add attribute timestampToString.

This commit is contained in:
Andrés Uribe Stengel 2020-07-15 12:16:04 +02:00
parent 7bb02a8508
commit 16a5521093
4 changed files with 19 additions and 8 deletions

View File

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

View File

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import { Button, Form, Container, Row, Col, Table } from 'react-bootstrap'; import { Button, Form } from 'react-bootstrap';
class AddPlant extends React.Component{ class AddPlant extends React.Component{
@ -69,5 +69,4 @@ class AddPlant extends React.Component{
} }
} }
export default AddPlant; export default AddPlant;

View File

@ -20,7 +20,7 @@ export default function Home() {
<LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, left: 5 }}> <LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, 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="timestamp" /> <XAxis dataKey="timestampToString" />
<YAxis /> <YAxis />
<Tooltip /> <Tooltip />
<Legend /> <Legend />
@ -32,7 +32,7 @@ export default function Home() {
<LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, left: 5 }}> <LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, 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="timestamp" /> <XAxis dataKey="timestampToString" />
<YAxis /> <YAxis />
<Tooltip /> <Tooltip />
<Legend /> <Legend />
@ -46,7 +46,7 @@ export default function Home() {
<LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, left: 5 }}> <LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, 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="timestamp" /> <XAxis dataKey="timestampToString" />
<YAxis /> <YAxis />
<Tooltip /> <Tooltip />
<Legend /> <Legend />
@ -58,7 +58,7 @@ export default function Home() {
<LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, left: 5 }}> <LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, 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="timestamp" /> <XAxis dataKey="timestampToString" />
<YAxis /> <YAxis />
<Tooltip /> <Tooltip />
<Legend /> <Legend />

View File

@ -28,10 +28,22 @@ function messageCallback(collection) {
const id = topicElements.pop(); const id = topicElements.pop();
var date = new Date; var date = new Date;
var time;
if (date.getHours() <= 9) {time = "0" + date.getHours();} else {
time = date.getHours();
}
if (date.getMinutes() <= 9) {time = time + ":0" + date.getMinutes();} else {
time = time + ":" + date.getMinutes();
}
if (date.getSeconds() <= 9) {time = time + ":0" + date.getSeconds();} else {
time = time + ":" + date.getSeconds();
}
let doc = { let doc = {
device_id: id, device_id: id,
timestamp: date, timestamp: date,
timestampToString: time,
} }
try { try {
doc = _.merge(doc, JSON.parse(message)); doc = _.merge(doc, JSON.parse(message));