Commit eda3bc4b by OuiAtichat

update feed

parent 4f49b647
......@@ -195,11 +195,10 @@ class Home extends Component {
const { startDate, endDate } = selectedRange;
const now = moment().valueOf();
// console.log('now', moment(now).format('D/M/YY HH:mm'));
// console.log('end', moment(endDate).format('D/M/YY HH:mm'));
// console.log('start', moment(startDate).format('D/M/YY HH:mm'));
// console.log(label);
let q_data = {
// tags = ['Current Cash']
// ["Revenue", "Reset" ,"Remote" ,"People" ,"Fingerprint"]
const q_data = {
start_absolute: startDate || now,
end_absolute: endDate || now,
metrics: [
......@@ -212,11 +211,32 @@ class Home extends Component {
},
],
tags: {
// attr: ['a12'],
attr: ["['Current Cash']"],
},
aggregators: [
{
name: 'avg',
name: 'last',
sampling: {
value: 1,
unit: breakdown,
},
},
],
},
{
name: deviceId || this.state.allDevicesId[0],
group_by: [
{
name: 'tag',
tags: ['attr'],
},
],
tags: {
attr: ['Revenue', 'Reset', 'Remote', 'People', 'Fingerprint'],
},
aggregators: [
{
name: 'sum',
sampling: {
value: 1,
unit: breakdown,
......@@ -231,53 +251,47 @@ class Home extends Component {
console.log('getFeedData');
axios.defaults.headers.common['Authorization'] = `Bearer ${userToken}`;
const response = await axios.post(kairosUrl, q_data);
const [currentFeed, fingerPrintFeed, peopleFeed, remoteFeed, keycardFeed, revenueFeed] = [
response.data.queries[0].results[0].values,
response.data.queries[1].results[0].values,
response.data.queries[1].results[1].values,
response.data.queries[1].results[2].values,
response.data.queries[1].results[3].values,
response.data.queries[1].results[4].values,
];
this.setState({
currentFeed: response.data.queries[0].results[5].values,
revenueFeed: response.data.queries[0].results[4].values,
peopleFeed: response.data.queries[0].results[1].values,
remoteFeed: response.data.queries[0].results[2].values,
keycardFeed: response.data.queries[0].results[3].values,
fingerPrintFeed: response.data.queries[0].results[0].values,
currentLast:
Math.round(
response.data.queries[0].results[5].values[
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,
revenueMax: Math.round(this.getMax(response.data.queries[0].results[4].values) * 100) / 100,
revenueMin: Math.round(this.getMin(response.data.queries[0].results[4].values) * 100) / 100,
revenueAvg: Math.round(this.getAvg(response.data.queries[0].results[4].values) * 100) / 100,
peopleTotal: Math.round(this.getTotal(response.data.queries[0].results[1].values) * 100) / 100,
peopleMax: Math.round(this.getMax(response.data.queries[0].results[1].values) * 100) / 100,
peopleMin: Math.round(this.getMin(response.data.queries[0].results[1].values) * 100) / 100,
peopleAvg: Math.round(this.getAvg(response.data.queries[0].results[1].values) * 100) / 100,
remoteTotal: Math.round(this.getTotal(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,
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,
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,
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,
currentFeed,
fingerPrintFeed,
peopleFeed,
remoteFeed,
keycardFeed,
revenueFeed,
currentLast: Math.round(currentFeed[currentFeed.length - 1][1] * 100) / 100,
revenueTotal: Math.round(this.getTotal(revenueFeed) * 100) / 100,
revenueMax: Math.round(this.getMax(revenueFeed) * 100) / 100,
revenueMin: Math.round(this.getMin(revenueFeed) * 100) / 100,
revenueAvg: Math.round(this.getAvg(revenueFeed) * 100) / 100,
peopleTotal: Math.round(this.getTotal(peopleFeed) * 100) / 100,
peopleMax: Math.round(this.getMax(peopleFeed) * 100) / 100,
peopleMin: Math.round(this.getMin(peopleFeed) * 100) / 100,
peopleAvg: Math.round(this.getAvg(peopleFeed) * 100) / 100,
remoteTotal: Math.round(this.getTotal(remoteFeed) * 100) / 100,
remoteMax: Math.round(this.getMax(remoteFeed) * 100) / 100,
remoteMin: Math.round(this.getMin(remoteFeed) * 100) / 100,
remoteAvg: Math.round(this.getAvg(remoteFeed) * 100) / 100,
fingerPrintTotal: Math.round(fingerPrintFeed[fingerPrintFeed.length - 1][1] * 100) / 100,
fingerPrintMax: Math.round(this.getMax(fingerPrintFeed) * 100) / 100,
fingerPrintMin: Math.round(this.getMin(fingerPrintFeed) * 100) / 100,
fingerPrintAvg: Math.round(this.getAvg(fingerPrintFeed) * 100) / 100,
keycardTotal: Math.round(keycardFeed[keycardFeed.length - 1][1] * 100) / 100,
keycardMax: Math.round(this.getMax(keycardFeed) * 100) / 100,
keycardMin: Math.round(this.getMin(keycardFeed) * 100) / 100,
keycardAvg: Math.round(this.getAvg(keycardFeed) * 100) / 100,
table: this.getTable(
this.state.allDeviceInfo[this.state.allDevicesId.indexOf(deviceId || this.state.allDevicesId[0])]
.name,
response.data.queries[0].results
[peopleFeed, revenueFeed, remoteFeed, currentFeed]
),
});
} catch (error) {
......@@ -329,14 +343,14 @@ class Home extends Component {
getTable = (site, data) => {
let table = [];
for (let i = 0, len = data[1].values.length; i < len; i++) {
for (let i = 0, len = data[1].length; i < len; i++) {
let v = {
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 HH:mm'),
people: data[0][i][1],
revenue: data[1][i][1],
remote: data[2][i][1],
current: data[3][i][1],
timestamp: moment(data[1][i][0]).format('D/M/YY HH:mm'),
};
table.unshift(v);
......
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