Commit b1eeb28d by OuiAtichat

update get interval

parent 96662896
...@@ -74,7 +74,7 @@ const Data = [ ...@@ -74,7 +74,7 @@ const Data = [
{ smtitle: 'Max. Fingerprint', smValue: 0, iconType: 'max' }, { smtitle: 'Max. Fingerprint', smValue: 0, iconType: 'max' },
{ smtitle: 'Min. Fingerprint', smValue: 0, iconType: 'min' }, { smtitle: 'Min. Fingerprint', smValue: 0, iconType: 'min' },
], ],
} },
]; ];
class Home extends Component { class Home extends Component {
...@@ -115,7 +115,7 @@ class Home extends Component { ...@@ -115,7 +115,7 @@ class Home extends Component {
keycardAvg: null, keycardAvg: null,
table: null, table: null,
}; };
looper; looper = null;
componentDidMount = async () => { componentDidMount = async () => {
await this.getConfig(); await this.getConfig();
await this.getCurrentUser(); await this.getCurrentUser();
...@@ -125,7 +125,7 @@ class Home extends Component { ...@@ -125,7 +125,7 @@ class Home extends Component {
componentDidUpdate = async (prevProps, prevState) => { componentDidUpdate = async (prevProps, prevState) => {
if (prevState.allDevicesId !== this.state.allDevicesId) { if (prevState.allDevicesId !== this.state.allDevicesId) {
// await this.getFeedData(); // await this.getFeedData();
await this.loopFeedData(); this.loopFeedData();
} }
}; };
...@@ -164,8 +164,8 @@ class Home extends Component { ...@@ -164,8 +164,8 @@ class Home extends Component {
.doc(allDevicesId[i]) .doc(allDevicesId[i])
.get(); .get();
let devicedata = deviceInfo.data(); let devicedata = deviceInfo.data();
devicedata.deviceid = allDevicesId[i] devicedata.deviceid = allDevicesId[i];
devicedata.position = [devicedata.location._long,devicedata.location._lat] devicedata.position = [devicedata.location._long, devicedata.location._lat];
allDeviceInfo.push(devicedata); allDeviceInfo.push(devicedata);
if (i === allDevicesId.length - 1) { if (i === allDevicesId.length - 1) {
this.setState({ allDeviceInfo }); this.setState({ allDeviceInfo });
...@@ -174,12 +174,12 @@ class Home extends Component { ...@@ -174,12 +174,12 @@ class Home extends Component {
this.setState({ allDevicesId }); this.setState({ allDevicesId });
}; };
loopFeedData = async (deviceId,selectedRange,breakdown) => { loopFeedData = async (deviceId, selectedRange, breakdown) => {
console.log("loopFeedData") console.log('loopFeedData');
clearInterval(this.looper) // clearInterval(this.looper)
await this.getFeedData(deviceId,selectedRange,breakdown); await this.getFeedData(deviceId, selectedRange, breakdown);
this.looper = setInterval(await this.getFeedData(deviceId,selectedRange,breakdown) , 60000) this.looper = setInterval(async () => await this.getFeedData(deviceId, selectedRange, breakdown), 60000);
} };
getFeedData = async ( getFeedData = async (
deviceId, deviceId,
...@@ -223,7 +223,7 @@ class Home extends Component { ...@@ -223,7 +223,7 @@ class Home extends Component {
}; };
try { try {
console.log("getFeedData") console.log('getFeedData');
axios.defaults.headers.common['Authorization'] = `Bearer ${userToken}`; axios.defaults.headers.common['Authorization'] = `Bearer ${userToken}`;
const response = await axios.post(kairosUrl, q_data); const response = await axios.post(kairosUrl, q_data);
this.setState({ this.setState({
...@@ -236,7 +236,7 @@ class Home extends Component { ...@@ -236,7 +236,7 @@ class Home extends Component {
currentLast: currentLast:
Math.round( Math.round(
response.data.queries[0].results[5].values[ response.data.queries[0].results[5].values[
response.data.queries[0].results[5].values.length - 1 response.data.queries[0].results[5].values.length - 1
][1] * 100 ][1] * 100
) / 100, ) / 100,
revenueTotal: Math.round(this.getTotal(response.data.queries[0].results[4].values) * 100) / 100, revenueTotal: Math.round(this.getTotal(response.data.queries[0].results[4].values) * 100) / 100,
...@@ -251,23 +251,29 @@ class Home extends Component { ...@@ -251,23 +251,29 @@ class Home extends Component {
remoteMax: Math.round(this.getMax(response.data.queries[0].results[2].values) * 100) / 100, remoteMax: Math.round(this.getMax(response.data.queries[0].results[2].values) * 100) / 100,
remoteMin: Math.round(this.getMin(response.data.queries[0].results[2].values) * 100) / 100, remoteMin: Math.round(this.getMin(response.data.queries[0].results[2].values) * 100) / 100,
remoteAvg: Math.round(this.getAvg(response.data.queries[0].results[2].values) * 100) / 100, remoteAvg: Math.round(this.getAvg(response.data.queries[0].results[2].values) * 100) / 100,
fingerPrintTotal: Math.round( fingerPrintTotal:
response.data.queries[0].results[0].values[ Math.round(
response.data.queries[0].results[0].values.length - 1 response.data.queries[0].results[0].values[
][1] * 100 response.data.queries[0].results[0].values.length - 1
) / 100, ][1] * 100
) / 100,
fingerPrintMax: Math.round(this.getMax(response.data.queries[0].results[0].values) * 100) / 100, fingerPrintMax: Math.round(this.getMax(response.data.queries[0].results[0].values) * 100) / 100,
fingerPrintMin: Math.round(this.getMin(response.data.queries[0].results[0].values) * 100) / 100, fingerPrintMin: Math.round(this.getMin(response.data.queries[0].results[0].values) * 100) / 100,
fingerPrintAvg: Math.round(this.getAvg(response.data.queries[0].results[0].values) * 100) / 100, fingerPrintAvg: Math.round(this.getAvg(response.data.queries[0].results[0].values) * 100) / 100,
keycardTotal: Math.round( keycardTotal:
response.data.queries[0].results[3].values[ Math.round(
response.data.queries[0].results[3].values.length - 1 response.data.queries[0].results[3].values[
][1] * 100 response.data.queries[0].results[3].values.length - 1
) / 100, ][1] * 100
) / 100,
keycardMax: Math.round(this.getMax(response.data.queries[0].results[3].values) * 100) / 100, keycardMax: Math.round(this.getMax(response.data.queries[0].results[3].values) * 100) / 100,
keycardMin: Math.round(this.getMin(response.data.queries[0].results[3].values) * 100) / 100, keycardMin: Math.round(this.getMin(response.data.queries[0].results[3].values) * 100) / 100,
keycardAvg: Math.round(this.getAvg(response.data.queries[0].results[3].values) * 100) / 100, keycardAvg: Math.round(this.getAvg(response.data.queries[0].results[3].values) * 100) / 100,
table: this.getTable(this.state.allDeviceInfo[this.state.allDevicesId.indexOf(deviceId || this.state.allDevicesId[0])].name,response.data.queries[0].results), table: this.getTable(
this.state.allDeviceInfo[this.state.allDevicesId.indexOf(deviceId || this.state.allDevicesId[0])]
.name,
response.data.queries[0].results
),
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
...@@ -315,19 +321,21 @@ class Home extends Component { ...@@ -315,19 +321,21 @@ class Home extends Component {
return total; return total;
}; };
getTable = (site,data) => { getTable = (site, data) => {
let table = []; let table = [];
for (let i = 0, len = data[1].values.length; i < len; i++) { for (let i = 0, len = data[1].values.length; i < len; i++) {
let v = { let v = {
site:site, site: site,
people: data[1].values[i][1], people: data[1].values[i][1],
revenue: data[4].values[i][1], revenue: data[4].values[i][1],
remote: data[2].values[i][1], remote: data[2].values[i][1],
current: data[5].values[i][1], current: data[5].values[i][1],
timestamp: moment(data[1].values[i][0]).format('D/M/YY H:mm'), timestamp: moment(data[1].values[i][0]).format('D/M/YY H:mm'),
}; };
table[table.length] = v; table[table.length] = v;
} }
return table; return table;
}; };
......
...@@ -6,20 +6,20 @@ const Map = ReactMapboxGl({ ...@@ -6,20 +6,20 @@ const Map = ReactMapboxGl({
accessToken: 'pk.eyJ1IjoicHJhY2hwYXdlZSIsImEiOiJjanlxdndybXcwNDZtM2RxcDlzenRrdzhsIn0.gvfTBIUhhBKvY2ZWBjj3Zw', accessToken: 'pk.eyJ1IjoicHJhY2hwYXdlZSIsImEiOiJjanlxdndybXcwNDZtM2RxcDlzenRrdzhsIn0.gvfTBIUhhBKvY2ZWBjj3Zw',
}); });
const Data = [ // const Data = [
{ id: 1, position: [100.56721, 13.748115], name: 'nexpie' }, // { id: 1, position: [100.56721, 13.748115], name: 'nexpie' },
{ id: 2, position: [100.56987, 13.747821], name: 'avani' }, // { id: 2, position: [100.56987, 13.747821], name: 'avani' },
{ id: 3, position: [100.622749, 13.962597], name: 'zeer' }, // { id: 3, position: [100.622749, 13.962597], name: 'zeer' },
{ id: 4, position: [100.535007, 13.746648], name: 'siam paragon' }, // { id: 4, position: [100.535007, 13.746648], name: 'siam paragon' },
{ id: 5, position: [100.679211, 13.826122], name: 'Fashion Island' }, // { id: 5, position: [100.679211, 13.826122], name: 'Fashion Island' },
]; // ];
export default class Mapbox extends React.PureComponent { export default class Mapbox extends React.PureComponent {
state = { state = {
center: undefined, center: undefined,
active: undefined, active: undefined,
zoom: [10], zoom: [10],
data:[] data: [],
}; };
componentDidUpdate = () => { componentDidUpdate = () => {
...@@ -27,8 +27,8 @@ export default class Mapbox extends React.PureComponent { ...@@ -27,8 +27,8 @@ export default class Mapbox extends React.PureComponent {
let data1 = this.props.allDeviceInfo; let data1 = this.props.allDeviceInfo;
this.setState({ this.setState({
data: data1, data: data1,
center:data1[0].position, center: data1[0].position,
active:data1[0] active: data1[0],
}); });
} }
}; };
......
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import App from './App'; import App from './App';
import * as serviceWorker from './serviceWorker';
import './styles.scss'; import './styles.scss';
ReactDOM.render(<App />, document.getElementById('root')); ReactDOM.render(<App />, document.getElementById('root'));
// serviceWorker.register();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment