use host time to calculate the real event time

This commit is contained in:
lukas 2020-12-12 15:58:05 +01:00
parent 747e7bbbf8
commit 0817fcf492
3 changed files with 77 additions and 68 deletions

View File

@ -13,7 +13,10 @@ before_script:
build: build:
stage: build stage: build
script: "platformio run -e esp12e" script:
- "platformio run -e esp12e"
- vers=$(grep -Po '[0-9]*\.[0-9]*\.[0-9]*(?=\")' ./src/Pins.h)
- mv .pio/'build/esp12e/*.bin Pumpensteuerung-${vers}.bin
artifacts: artifacts:
paths: paths:
- .pio/build/esp12e/*.bin - ./*.bin

View File

@ -1,12 +1,6 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {Box, List, ListItem, ListItemText} from '@material-ui/core'; import {Box, List, ListItem, ListItemText} from '@material-ui/core';
import { import {FormButton, restController, RestControllerProps, RestFormLoader, SectionContent} from '../components';
FormButton,
restController,
RestControllerProps,
RestFormLoader,
SectionContent
} from '../components';
import {ENDPOINT_ROOT} from "../api"; import {ENDPOINT_ROOT} from "../api";
import {GeneralInformaitonState} from "./types"; import {GeneralInformaitonState} from "./types";
import RefreshIcon from "@material-ui/icons/Refresh"; import RefreshIcon from "@material-ui/icons/Refresh";
@ -21,12 +15,6 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
componentDidMount() { componentDidMount() {
this.props.loadData(); this.props.loadData();
// this.intervalhandler = window.setInterval(() => {
// this.props.loadData();
// console.log("refreshing data");
// console.log(this.props.data)
// }, 10000);
} }
componentWillUnmount() { componentWillUnmount() {
@ -44,19 +32,23 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
<ListItem> <ListItem>
<ListItemText <ListItemText
primary="Chip läuft seit:" primary="Chip läuft seit:"
secondary={this.stringifyTime(props.data.runtime)} secondary={this.stringifyTime(props.data.runtime) + ' / ' + this.getRealTimeString(props.data.runtime)}
/> />
</ListItem> </ListItem>
<ListItem> <ListItem>
<ListItemText <ListItemText
primary="Zuletzt zu wenig Wasser:" primary="Zuletzt zu wenig Wasser:"
secondary={props.data.lastWaterOutage !== 0 ? "vor " + this.stringifyTime(props.data.lastWaterOutage) : "noch nie!"} secondary={props.data.lastWaterOutage !== 0 ? "vor " +
this.stringifyTime(props.data.lastWaterOutage) + ' / ' +
this.getRealTimeString(props.data.lastWaterOutage) : "noch nie!"}
/> />
</ListItem> </ListItem>
<ListItem> <ListItem>
<ListItemText <ListItemText
primary="Letzer Pumpenzyklus" primary="Letzer Pumpenzyklus"
secondary={props.data.lastpumptime !== 0 ? "vor " + this.stringifyTime(props.data.lastpumptime) : "noch nie!"} secondary={props.data.lastpumptime !== 0 ? "vor " +
this.stringifyTime(props.data.lastpumptime) + ' / ' +
this.getRealTimeString(props.data.lastpumptime) : "noch nie!"}
/> />
</ListItem> </ListItem>
<ListItem> <ListItem>
@ -100,7 +92,7 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
* stringify seconds to a pretty format * stringify seconds to a pretty format
* @param sec number of seconds * @param sec number of seconds
*/ */
stringifyTime(sec: number): string { private stringifyTime(sec: number): string {
if (sec >= 86400) { if (sec >= 86400) {
// display days // display days
return (Math.trunc(sec / 86400) + "d " + Math.trunc((sec % 86400) / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec"); return (Math.trunc(sec / 86400) + "d " + Math.trunc((sec % 86400) / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec");
@ -115,6 +107,20 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
return (sec + "sec"); return (sec + "sec");
} }
} }
private getRealTimeString(runtime: number): string {
const timestamp = Date.now();
const a = new Date(timestamp - (runtime * 1000));
const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
const year = a.getFullYear();
const month = months[a.getMonth()];
const date = a.getDate();
const hour = a.getHours();
const min = "0" + a.getMinutes();
const sec = "0" + a.getSeconds();
return '[' + date + ' ' + month + ' ' + year + ' ' + hour + ':' + min.substr(-2) + ':' + sec.substr(-2) + ']';
}
} }
export default restController(GENERALINFORMATION_SETTINGS_ENDPOINT, GeneralInformation); export default restController(GENERALINFORMATION_SETTINGS_ENDPOINT, GeneralInformation);

View File

@ -16,6 +16,6 @@
#define TempSensorPin D4 #define TempSensorPin D4
// version info // version info
#define VERSION "v1.2.1" #define VERSION "v1.2.2"
#endif //PUMPENSTEUERUNG_PINS_H #endif //PUMPENSTEUERUNG_PINS_H