@@ -112,63 +112,47 @@ module openflow {
112112 }
113113 async dographs ( ) {
114114 var chart : chartset = null ;
115- this . charts = [ ] ;
115+ var agg : any = { } ;
116+ var data : any = { } ;
117+
118+ var datatimeframe = new Date ( new Date ( ) . toISOString ( ) ) ;
119+ datatimeframe . setDate ( datatimeframe . getDate ( ) - 5 ) ;
120+ agg = [
121+ { $match : { _created : { "$gte" : datatimeframe } } } ,
122+ {
123+ $group :
124+ {
125+ _id :
126+ {
127+ WorkflowId : "$WorkflowId" ,
128+ name : "$name" ,
129+ day : { $dayOfMonth : "$_created" }
130+ } ,
131+ count : { $sum : 1 }
132+ }
133+ } ,
134+ { $sort : { "_id.day" : 1 } }
135+ // ,{ "$limit": 20 }
136+ ] ;
137+ var workflowruns = await this . api . Aggregate ( "openrpa_instances" , agg ) ;
138+
139+
116140 for ( var i = 0 ; i < this . models . length ; i ++ ) {
117141 var workflow = this . models [ i ] as any ;
118- var d = new Date ( ) ;
119- //d.setMonth(d.getMonth() - 1);
120- d . setDate ( d . getDate ( ) - 7 ) ;
121- console . debug ( "get mapreduce of instances" ) ;
122- var stats = await this . api . MapReduce ( "openrpa_instances" ,
123- function map ( ) {
124- var startDate = new Date ( this . _created ) ;
125- this . count = 1 ;
126- emit ( startDate . toISOString ( ) . split ( 'T' ) [ 0 ] , this ) ;
127- } , function reduce ( key , values ) {
128- var reducedObject = { count : 0 , value : 0 , avg : 0 , minrun : 0 , maxrun : 0 , run : 0 , _acl : [ ] } ;
129- values . forEach ( function ( value ) {
130- var startDate = new Date ( value . _created ) ;
131- var endDate = new Date ( value . _modified ) ;
132- var seconds = ( endDate . getTime ( ) - startDate . getTime ( ) ) / 1000 ;
133- if ( reducedObject . minrun == 0 && seconds > 0 ) reducedObject . minrun = seconds ;
134- if ( reducedObject . minrun > seconds ) reducedObject . minrun = seconds ;
135- if ( reducedObject . maxrun < seconds ) reducedObject . maxrun = seconds ;
136- reducedObject . run += seconds ;
137- reducedObject . count += value . count ;
138- reducedObject . _acl = value . _acl ;
139- } ) ;
140- return reducedObject ;
141- } , function finalize ( key , reducedValue ) {
142- if ( reducedValue . count > 0 ) {
143- reducedValue . avg = reducedValue . value / reducedValue . count ;
144- reducedValue . run = reducedValue . run / reducedValue . count ;
145- }
146- return reducedValue ;
147- } , { _type : "workflowinstance" , WorkflowId : workflow . _id , "_created" : { "$gte" : new Date ( d . toISOString ( ) ) } } , { inline : 1 } , null ) ;
148142
149143 chart = new chartset ( ) ;
150- chart . charttype = "line"
151144 chart . data = [ ] ;
152- var lastdate = "" ;
153- var days = daysBetween ( d , new Date ( ) ) ;
154- for ( var y = 0 ; y < days ; y ++ ) {
155- var startDate = new Date ( d ) ;
156- startDate . setDate ( d . getDate ( ) + y ) ;
157- var datestring = startDate . toISOString ( ) . split ( 'T' ) [ 0 ] ;
158- var exists = stats . filter ( m => m . _id == datestring ) ;
159- if ( exists . length > 0 ) {
160- chart . data . push ( exists [ 0 ] . value . count ) ;
161- } else {
162- chart . data . push ( 0 ) ;
163- }
164- if ( ( y % 2 ) == 0 || ( days == 30 && y == 30 ) ) {
165- chart . labels . push ( startDate . getDate ( ) . toString ( ) ) ;
166- } else {
167- chart . labels . push ( "" ) ;
145+ for ( var x = 0 ; x < workflowruns . length ; x ++ ) {
146+ if ( workflowruns [ x ] . _id . WorkflowId == workflow . _id ) {
147+ chart . data . push ( workflowruns [ x ] . count ) ;
148+ chart . labels . push ( workflowruns [ x ] . _id . day ) ;
168149 }
169150 }
170- workflow . chart = chart ;
171- if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
151+ if ( chart . data . length > 0 ) {
152+ workflow . chart = chart ;
153+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
154+ }
155+
172156 }
173157
174158 }
@@ -1042,55 +1026,6 @@ module openflow {
10421026 this . userdata . data . UsersCtrl . searchstring = this . searchstring ;
10431027 this . userdata . data . UsersCtrl . basequeryas = this . basequeryas ;
10441028 var chart : chartset = null ;
1045- // for (var i = 0; i < this.models.length; i++) {
1046- // var user = this.models[i] as any;
1047- // var d = new Date();
1048- // // d.setMonth(d.getMonth() - 1);
1049- // d.setDate(d.getDate() - 7);
1050- // console.debug("get mapreduce for " + user.name);
1051- // var stats = await this.api.MapReduce("audit",
1052- // function map() {
1053- // var startDate = new Date(this._created);
1054- // this.count = 1;
1055- // emit(startDate.toISOString().split('T')[0], this);
1056- // }, function reduce(key, values) {
1057- // var reducedObject = { count: 0, value: 0, avg: 0, minrun: 0, maxrun: 0, run: 0, _acl: [] };
1058- // values.forEach(function (value) {
1059- // reducedObject.count += value.count;
1060- // reducedObject._acl = value._acl;
1061- // });
1062- // return reducedObject;
1063- // }, function finalize(key, reducedValue) {
1064- // if (reducedValue.count > 0) {
1065- // reducedValue.avg = reducedValue.value / reducedValue.count;
1066- // }
1067- // return reducedValue;
1068- // }, { userid: user._id, "_created": { "$gte": new Date(d.toISOString()) } }, { inline: 1 }, null);
1069-
1070- // chart = new chartset();
1071- // chart.charttype = "line"
1072- // chart.data = [];
1073- // var days = daysBetween(d, new Date());
1074- // for (var y = 0; y < days; y++) {
1075- // var startDate = new Date(d);
1076- // startDate.setDate(d.getDate() + y);
1077- // var datestring = startDate.toISOString().split('T')[0];
1078- // var exists = stats.filter(m => m._id == datestring);
1079- // if (exists.length > 0) {
1080- // chart.data.push(exists[0].value.count);
1081- // } else {
1082- // chart.data.push(0);
1083- // }
1084- // //chart.labels.push(datestring);
1085- // if ((y % 2) == 0 || (days == 30 && y == 30)) {
1086- // chart.labels.push(startDate.getDate().toString());
1087- // } else {
1088- // chart.labels.push("");
1089- // }
1090- // }
1091- // user.chart = chart;
1092-
1093- // }
10941029 this . loading = false ;
10951030 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
10961031 }
0 commit comments