Skip to content

Commit db7caee

Browse files
committed
Optimize robot breakdown graph
1 parent 4462aaa commit db7caee

2 files changed

Lines changed: 32 additions & 30 deletions

File tree

OpenFlow/src/public/Controllers.ts

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -356,46 +356,44 @@ module openflow {
356356

357357
dt = new Date(new Date().toISOString());
358358
dt.setMonth(dt.getMonth() - 1);
359+
//dt.setDate(dt.getDate() - 1);
359360
var dt2 = new Date(new Date().toISOString());
360361
dt2.setMinutes(dt.getMinutes() - 1);
361362
//
362363
// { "$limit": 20 }
363364
var rpaheartbeat: any = [];
364365
if (points[0]._index == 0) // Online robots
365366
{
366-
rpaheartbeat = { $match: { "user._rpaheartbeat": { "$gte": dt2 } } };
367+
// rpaheartbeat = { $match: { "user._rpaheartbeat": { "$gte": dt2 } } };
368+
rpaheartbeat = { $match: { "_rpaheartbeat": { "$gte": dt2 } } };
367369
} else {
368370

369-
rpaheartbeat = { $match: { "user._rpaheartbeat": { "$lt": dt2 } } };
371+
// rpaheartbeat = { $match: { "user._rpaheartbeat": { "$lt": dt2 } } };
372+
rpaheartbeat = { $match: { "_rpaheartbeat": { "$lt": dt2 } } };
370373
}
371-
372374
agg = [
373-
{ $match: { _created: { "$gte": dt }, clientagent: "openrpa" } },
375+
{ $match: { _type: 'user' } },
376+
rpaheartbeat,
374377
{
375378
$lookup: {
376-
from: "users",
377-
localField: "userid",
378-
foreignField: "_id",
379-
as: "userarr"
379+
from: "audit",
380+
localField: "_id",
381+
foreignField: "userid",
382+
as: "audit"
380383
}
381-
},
382-
{
383-
"$project": {
384-
"userid": 1,
384+
}
385+
, {
386+
$project: {
387+
"_id": 1,
385388
"name": 1,
386-
"user": { "$arrayElemAt": ["$userarr", 0] }
389+
"count": { "$size": "$audit" }
387390
}
388-
},
389-
rpaheartbeat,
390-
{ "$group": { "_id": { userid: "$userid", name: "$name" }, "count": { "$sum": 1 } } },
391-
{ $sort: { "count": -1 } },
392-
{ "$limit": 20 }
391+
}
392+
, { "$limit": 20 }
393393
];
394394

395-
396-
var data = await this.api.Aggregate("audit", agg);
397-
398-
395+
var data = await this.api.Aggregate("users", agg);
396+
console.log(data);
399397

400398
chart = new chartset();
401399
if (points[0]._index == 0) // Online robots
@@ -404,21 +402,25 @@ module openflow {
404402
} else {
405403
chart.heading = "Logins per offline robot the last month (top 20)";
406404
}
407-
// chart.series = ['name', 'count'];
408-
// chart.labels = ['name', 'count'];
409405
chart.data = [];
410406
chart.ids = [];
411407
for (var x = 0; x < data.length; x++) {
412408
chart.data.push(data[x].count);
413-
chart.ids.push(data[x]._id.userid);
414-
chart.labels.push(data[x]._id.name);
409+
chart.ids.push(data[x]._id);
410+
chart.labels.push(data[x].name);
415411
}
416412
chart.click = this.processData.bind(this);
417413
this.charts.splice(0, 1);
418414
this.charts.unshift(chart);
415+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
419416

420417

421-
418+
if (points[0]._index == 0) // Online robots
419+
{
420+
rpaheartbeat = { $match: { "user._rpaheartbeat": { "$gte": dt2 } } };
421+
} else {
422+
rpaheartbeat = { $match: { "user._rpaheartbeat": { "$lt": dt2 } } };
423+
}
422424

423425
dt = new Date(new Date().toISOString());
424426
dt.setMonth(dt.getMonth() - 1);
@@ -456,7 +458,7 @@ module openflow {
456458
{ "$limit": 20 }
457459
];
458460
var workflowruns = await this.api.Aggregate("openrpa_instances", agg);
459-
461+
console.log(workflowruns);
460462

461463
chart = new chartset();
462464
if (points[0]._index == 0) // Online robots
@@ -519,7 +521,7 @@ module openflow {
519521
{ "$limit": 20 }
520522
];
521523
var workflowruns = await this.api.Aggregate("openrpa_instances", agg);
522-
524+
console.log(workflowruns);
523525

524526
chart = new chartset();
525527
if (workflowruns.length > 0) {

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.532
1+
0.0.533

0 commit comments

Comments
 (0)