Commit b1eeb28d by OuiAtichat

update get interval

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