Skip to content

Commit e508ba6

Browse files
committed
add range to reports
1 parent db7caee commit e508ba6

3 files changed

Lines changed: 112 additions & 54 deletions

File tree

OpenFlow/src/public/Controllers.ts

Lines changed: 104 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ module openflow {
249249
export class ReportsCtrl extends entitiesCtrl<openflow.Base> {
250250
public message: string = "";
251251
public charts: chartset[] = [];
252+
public datatimeframe: Date;
253+
public onlinetimeframe: Date;
254+
public timeframedesc: string = "";
252255
constructor(
253256
public $scope: ng.IScope,
254257
public $location: ng.ILocationService,
@@ -261,61 +264,87 @@ module openflow {
261264
super($scope, $location, $routeParams, $interval, WebSocketClient, api, userdata);
262265
console.debug("ReportsCtrl");
263266
WebSocketClient.onSignedin((user: TokenUser) => {
264-
this.processData();
267+
if (this.userdata.data.ReportsCtrl) {
268+
this.datatimeframe = this.userdata.data.ReportsCtrl.datatimeframe;
269+
this.onlinetimeframe = this.userdata.data.ReportsCtrl.onlinetimeframe;
270+
this.processData();
271+
} else {
272+
this.settimeframe(30, 0, "30 days");
273+
}
274+
265275
});
266276
}
277+
settimeframe(days, hours, desc) {
278+
this.datatimeframe = new Date(new Date().toISOString());
279+
console.log(this.datatimeframe);
280+
if (days > 0) this.datatimeframe.setDate(this.datatimeframe.getDate() - days);
281+
if (hours > 0) this.datatimeframe.setHours(this.datatimeframe.getHours() - hours);
282+
this.timeframedesc = desc;
283+
console.log(this.datatimeframe);
284+
285+
this.onlinetimeframe = new Date(new Date().toISOString());
286+
this.onlinetimeframe.setMinutes(this.onlinetimeframe.getMinutes() - 1);
287+
// this.datatimeframe = new Date(new Date().toISOString());
288+
// this.datatimeframe.setMonth(this.datatimeframe.getMonth() - 1);
289+
290+
// dt = new Date(new Date().toISOString());
291+
// dt.setMonth(dt.getMonth() - 1);
292+
// //dt.setDate(dt.getDate() - 1);
293+
// dt = new Date(new Date().toISOString());
294+
// dt.setMonth(dt.getMonth() - 1);
295+
// var dt2 = new Date(new Date().toISOString());
296+
// dt2.setMinutes(dt.getMinutes() - 1);
297+
298+
if (!this.userdata.data.ReportsCtrl) this.userdata.data.ReportsCtrl = { run: this.processData.bind(this) };
299+
this.userdata.data.ReportsCtrl.datatimeframe = this.datatimeframe;
300+
this.userdata.data.ReportsCtrl.onlinetimeframe = this.onlinetimeframe;
301+
this.userdata.data.ReportsCtrl.run(this.userdata.data.ReportsCtrl.points);
302+
}
267303
async processData(): Promise<void> {
304+
this.userdata.data.ReportsCtrl.run = this.processData.bind(this);
305+
this.userdata.data.ReportsCtrl.points = null;
268306
this.loading = true;
269307
this.charts = [];
270308
var chart: chartset = null;
271309
var agg: any = {};
272310
var data: any = {};
273-
var dt: Date;
274311

275-
// var agg = [{ "$group": { "_id": "$_type", "count": { "$sum": 1 } } }];
276-
277-
// fuck it, lets kust focus on robots who have been online the last month
312+
// fuck it, lets just focus on robots who have been online the last month
313+
// agg = [
314+
// { $match: { _rpaheartbeat: { "$exists": true } } },
315+
// { "$count": "_rpaheartbeat" }
316+
// ];
278317
agg = [
279-
{ $match: { _rpaheartbeat: { "$exists": true } } },
280-
{ "$count": "_rpaheartbeat" }
281-
];
282-
dt = new Date(new Date().toISOString());
283-
dt.setMonth(dt.getMonth() - 1);
284-
agg = [
285-
{ $match: { _rpaheartbeat: { "$gte": dt } } },
318+
{ $match: { _rpaheartbeat: { "$gte": this.datatimeframe } } },
286319
{ "$count": "_rpaheartbeat" }
287320
];
288321
data = await this.api.Aggregate("users", agg);
289322
var totalrobots = 0;
290323
if (data.length > 0) totalrobots = data[0]._rpaheartbeat;
291324

292-
dt = new Date(new Date().toISOString());
293-
dt.setMinutes(dt.getMinutes() - 1);
294325
agg = [
295-
{ $match: { _rpaheartbeat: { "$gte": dt } } },
326+
{ $match: { _rpaheartbeat: { "$gte": this.onlinetimeframe } } },
296327
{ "$count": "_rpaheartbeat" }
297328
];
298329
data = await this.api.Aggregate("users", agg);
299330
var onlinerobots = 0;
300331
if (data.length > 0) onlinerobots = data[0]._rpaheartbeat;
301332

302333
chart = new chartset();
303-
chart.heading = "Robots seen the last month";
334+
chart.heading = "Robots seen the last " + this.timeframedesc;
304335
chart.labels = ['online', 'offline'];
305336
chart.data = [onlinerobots, (totalrobots - onlinerobots)];
306337
chart.charttype = "doughnut";
307338
// chart.click = this.robotsclick.bind(this);
308339
chart.click = this.robotsclick.bind(this);
309340
this.charts.push(chart);
310-
341+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
311342

312343

313344
// var agg = [{ "$group": { "_id": "$_type", "count": { "$sum": 1 } } }];
314345

315-
dt = new Date(new Date().toISOString());
316-
dt.setMonth(dt.getMonth() - 1);
317346
agg = [
318-
{ $match: { _created: { "$gte": dt }, _type: "workflowinstance" } },
347+
{ $match: { _created: { "$gte": this.datatimeframe }, _type: "workflowinstance" } },
319348
{ "$group": { "_id": { "WorkflowId": "$WorkflowId", "name": "$name" }, "count": { "$sum": 1 } } },
320349
{ $sort: { "count": -1 } },
321350
{ "$limit": 20 }
@@ -347,30 +376,26 @@ module openflow {
347376
if (!this.$scope.$$phase) { this.$scope.$apply(); }
348377
}
349378
async robotsclick(points, evt): Promise<void> {
379+
this.userdata.data.ReportsCtrl.run = this.robotsclick.bind(this);
380+
this.userdata.data.ReportsCtrl.points = points;
350381
if (points.length > 0) {
351382
} else { return; }
352383
var chart: chartset = null;
353384
var agg: any = {};
354385
var data: any = {};
355-
var dt: Date;
356-
357-
dt = new Date(new Date().toISOString());
358-
dt.setMonth(dt.getMonth() - 1);
359-
//dt.setDate(dt.getDate() - 1);
360-
var dt2 = new Date(new Date().toISOString());
361-
dt2.setMinutes(dt.getMinutes() - 1);
362386
//
363387
// { "$limit": 20 }
364388
var rpaheartbeat: any = [];
365389
if (points[0]._index == 0) // Online robots
366390
{
367-
// rpaheartbeat = { $match: { "user._rpaheartbeat": { "$gte": dt2 } } };
368-
rpaheartbeat = { $match: { "_rpaheartbeat": { "$gte": dt2 } } };
391+
// rpaheartbeat = { $match: { "user._rpaheartbeat": { "$gte": this.onlinetimeframe } } };
392+
rpaheartbeat = { $match: { "_rpaheartbeat": { "$gte": this.onlinetimeframe } } };
369393
} else {
370394

371-
// rpaheartbeat = { $match: { "user._rpaheartbeat": { "$lt": dt2 } } };
372-
rpaheartbeat = { $match: { "_rpaheartbeat": { "$lt": dt2 } } };
395+
// rpaheartbeat = { $match: { "user._rpaheartbeat": { "$lt": this.onlinetimeframe } } };
396+
rpaheartbeat = { $match: { "_rpaheartbeat": { "$lt": this.onlinetimeframe } } };
373397
}
398+
this.charts = [];
374399
agg = [
375400
{ $match: { _type: 'user' } },
376401
rpaheartbeat,
@@ -398,9 +423,9 @@ module openflow {
398423
chart = new chartset();
399424
if (points[0]._index == 0) // Online robots
400425
{
401-
chart.heading = "Logins per online robot the last month (top 20)";
426+
chart.heading = "Logins per online robot the last " + this.timeframedesc + " (top 20)";
402427
} else {
403-
chart.heading = "Logins per offline robot the last month (top 20)";
428+
chart.heading = "Logins per offline robot the last " + this.timeframedesc + " (top 20)";
404429
}
405430
chart.data = [];
406431
chart.ids = [];
@@ -409,23 +434,20 @@ module openflow {
409434
chart.ids.push(data[x]._id);
410435
chart.labels.push(data[x].name);
411436
}
412-
chart.click = this.processData.bind(this);
413-
this.charts.splice(0, 1);
414-
this.charts.unshift(chart);
437+
chart.click = this.robotclick.bind(this);
438+
this.charts.push(chart);
415439
if (!this.$scope.$$phase) { this.$scope.$apply(); }
416440

417441

418442
if (points[0]._index == 0) // Online robots
419443
{
420-
rpaheartbeat = { $match: { "user._rpaheartbeat": { "$gte": dt2 } } };
444+
rpaheartbeat = { $match: { "user._rpaheartbeat": { "$gte": this.onlinetimeframe } } };
421445
} else {
422-
rpaheartbeat = { $match: { "user._rpaheartbeat": { "$lt": dt2 } } };
446+
rpaheartbeat = { $match: { "user._rpaheartbeat": { "$lt": this.onlinetimeframe } } };
423447
}
424448

425-
dt = new Date(new Date().toISOString());
426-
dt.setMonth(dt.getMonth() - 1);
427449
agg = [
428-
{ $match: { _created: { "$gte": dt }, _type: "workflowinstance" } },
450+
{ $match: { _created: { "$gte": this.datatimeframe }, _type: "workflowinstance" } },
429451
{
430452
$lookup: {
431453
from: "users",
@@ -475,6 +497,46 @@ module openflow {
475497
chart.labels.push(workflowruns[x]._id.name);
476498
}
477499
chart.click = this.workflowclick.bind(this);
500+
this.charts.push(chart);
501+
502+
503+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
504+
505+
}
506+
async robotclick(points, evt): Promise<void> {
507+
if (points.length > 0) {
508+
} else { return; }
509+
var userid = this.charts[0].ids[points[0]._index];
510+
console.log(userid);
511+
var chart: chartset = null;
512+
var agg: any = {};
513+
var data: any = {};
514+
515+
516+
agg = [
517+
{ $match: { _created: { "$gte": this.datatimeframe }, _type: "workflowinstance", ownerid: userid } },
518+
{ "$group": { "_id": { "WorkflowId": "$WorkflowId", "name": "$name", "owner": "$owner" }, "count": { "$sum": 1 } } },
519+
{ $sort: { "count": -1 } },
520+
{ "$limit": 20 }
521+
];
522+
var workflowruns = await this.api.Aggregate("openrpa_instances", agg);
523+
console.log(workflowruns);
524+
525+
chart = new chartset();
526+
if (workflowruns.length > 0) // Online robots
527+
{
528+
chart.heading = "Workflow runs for " + workflowruns[0].owner + " (top 20)";
529+
} else {
530+
chart.heading = "No data (or permissions) for robot";
531+
}
532+
chart.data = [];
533+
chart.ids = [];
534+
for (var x = 0; x < workflowruns.length; x++) {
535+
chart.data.push(workflowruns[x].count);
536+
chart.ids.push(workflowruns[x]._id.WorkflowId);
537+
chart.labels.push(workflowruns[x]._id.name);
538+
}
539+
chart.click = this.workflowclick.bind(this);
478540
this.charts.splice(1, 1);
479541
this.charts.push(chart);
480542

@@ -491,18 +553,9 @@ module openflow {
491553
var chart: chartset = null;
492554
var agg: any = {};
493555
var data: any = {};
494-
var dt: Date;
495-
496-
dt = new Date(new Date().toISOString());
497-
dt.setMonth(dt.getMonth() - 1);
498-
var dt2 = new Date(new Date().toISOString());
499-
dt2.setMinutes(dt.getMinutes() - 1);
500-
501556

502-
dt = new Date(new Date().toISOString());
503-
dt.setMonth(dt.getMonth() - 1);
504557
agg = [
505-
{ $match: { _created: { "$gte": dt }, WorkflowId: WorkflowId } },
558+
{ $match: { _created: { "$gte": this.datatimeframe }, WorkflowId: WorkflowId } },
506559
{
507560
$group:
508561
{

OpenFlow/src/public/Reports.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ <h1>OpenRPA</h1>
44
</div>
55

66
<pre>{{ ctrl.message }}</pre>
7+
<a href ng-click="ctrl.settimeframe(0, 1, '1 hour')">1 hour</a>
8+
<a href ng-click="ctrl.settimeframe(0, 6, '6 hour')">6 hour</a>
9+
<a href ng-click="ctrl.settimeframe(1, 0, '1 day')">1 day</a>
10+
<a href ng-click="ctrl.settimeframe(7, 0, '7 days')">7 days</a>
11+
<a href ng-click="ctrl.settimeframe(30, 0, '30 days')">30 days</a><br />
712

8-
<div ng-repeat="chart in ctrl.charts" style="display: inline-block;">
13+
<div ng-repeat="chart in ctrl.charts">
914
<div>{{chart.heading}}</div>
1015
<div style="width: 500px">
1116
<canvas id="bar" class="chart-base" chart-type="chart.charttype" chart-data="chart.data"
1217
chart-labels="chart.labels" chart-series="chart.series" chart-click="chart.click">
1318
</canvas>
14-
</div>
19+
</div><br>
1520
</div>

VERSION

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

0 commit comments

Comments
 (0)