@@ -107,6 +107,19 @@ var plugins = require('../../pluginManager.js'),
107
107
) ;
108
108
}
109
109
110
+ /**
111
+ * Update data-point object with new events and sessions counts
112
+ * @param {object } object - object which will be updated
113
+ * @param {object } data - passed data object which contains events and sessions count
114
+ * @returns {object } Returns manipulated object
115
+ **/
116
+ function increaseDataPoints ( object , data ) {
117
+ object . events += data . e ;
118
+ object . sessions += data . s ;
119
+ object [ "data-points" ] += data . e + data . s ;
120
+ return object ;
121
+ }
122
+
110
123
/**
111
124
* Returns last three month session, event and data point count
112
125
* for all and individual apps
@@ -123,7 +136,7 @@ var plugins = require('../../pluginManager.js'),
123
136
var periodsToFetch = [ ] ,
124
137
utcMoment = common . moment . utc ( ) ;
125
138
126
- var monthBack = parseInt ( params . qstring . months ) || 3 ;
139
+ var monthBack = parseInt ( params . qstring . months ) || 12 ;
127
140
128
141
for ( let i = monthBack - 1 ; i > 0 ; i -- ) {
129
142
utcMoment . subtract ( i , "months" ) ;
@@ -143,15 +156,25 @@ var plugins = require('../../pluginManager.js'),
143
156
144
157
common . db . collection ( "server_stats_data_points" ) . find ( filter , { } ) . toArray ( function ( err , dataPerApp ) {
145
158
var toReturn = {
146
- "all-apps" : { }
159
+ "all-apps" : { } ,
160
+ } ;
161
+
162
+ toReturn [ "all-apps" ] [ "12_months" ] = {
163
+ "events" : 0 ,
164
+ "sessions" : 0 ,
165
+ "data-points" : 0
166
+ } ;
167
+ toReturn [ "all-apps" ] [ "6_months" ] = {
168
+ "events" : 0 ,
169
+ "sessions" : 0 ,
170
+ "data-points" : 0
147
171
} ;
148
172
149
173
for ( let i = 0 ; i < periodsToFetch . length ; i ++ ) {
150
174
let formattedDate = periodsToFetch [ i ] . replace ( ":" , "-" ) ;
151
-
152
175
toReturn [ "all-apps" ] [ formattedDate ] = {
153
- "sessions" : 0 ,
154
176
"events" : 0 ,
177
+ "sessions" : 0 ,
155
178
"data-points" : 0
156
179
} ;
157
180
}
@@ -166,26 +189,40 @@ var plugins = require('../../pluginManager.js'),
166
189
167
190
if ( ! toReturn [ dataPerApp [ i ] . a ] [ formattedDate ] ) {
168
191
toReturn [ dataPerApp [ i ] . a ] [ formattedDate ] = {
192
+ "events" : 0 ,
169
193
"sessions" : 0 ,
194
+ "data-points" : 0
195
+ } ;
196
+ }
197
+ if ( ! toReturn [ dataPerApp [ i ] . a ] [ "12_months" ] ) {
198
+ toReturn [ dataPerApp [ i ] . a ] [ "12_months" ] = {
170
199
"events" : 0 ,
200
+ "sessions" : 0 ,
171
201
"data-points" : 0
172
202
} ;
173
203
}
174
-
175
- if ( dataPerApp [ i ] . m === periodsToFetch [ j ] ) {
176
- toReturn [ dataPerApp [ i ] . a ] [ formattedDate ] = {
177
- "sessions" : dataPerApp [ i ] . s ,
178
- "events" : dataPerApp [ i ] . e ,
179
- "data-points" : dataPerApp [ i ] . s + dataPerApp [ i ] . e
204
+ if ( ! toReturn [ dataPerApp [ i ] . a ] [ "6_months" ] ) {
205
+ toReturn [ dataPerApp [ i ] . a ] [ "6_months" ] = {
206
+ "events" : 0 ,
207
+ "sessions" : 0 ,
208
+ "data-points" : 0
180
209
} ;
210
+ }
181
211
182
- toReturn [ "all-apps" ] [ formattedDate ] . sessions += dataPerApp [ i ] . s ;
183
- toReturn [ "all-apps" ] [ formattedDate ] . events += dataPerApp [ i ] . e ;
184
- toReturn [ "all-apps" ] [ formattedDate ] [ "data-points" ] += dataPerApp [ i ] . s + dataPerApp [ i ] . e ;
212
+ if ( dataPerApp [ i ] . m === periodsToFetch [ j ] ) {
213
+ toReturn [ dataPerApp [ i ] . a ] [ formattedDate ] = increaseDataPoints ( toReturn [ dataPerApp [ i ] . a ] [ formattedDate ] , dataPerApp [ i ] ) ;
214
+ toReturn [ "all-apps" ] [ formattedDate ] = increaseDataPoints ( toReturn [ "all-apps" ] [ formattedDate ] , dataPerApp [ i ] ) ;
215
+ // only last 6 months
216
+ if ( j > 5 ) {
217
+ toReturn [ "all-apps" ] [ "6_months" ] = increaseDataPoints ( toReturn [ "all-apps" ] [ "6_months" ] , dataPerApp [ i ] ) ;
218
+ toReturn [ dataPerApp [ i ] . a ] [ "6_months" ] = increaseDataPoints ( toReturn [ dataPerApp [ i ] . a ] [ "6_months" ] , dataPerApp [ i ] ) ;
219
+ }
220
+ toReturn [ dataPerApp [ i ] . a ] [ "12_months" ] = increaseDataPoints ( toReturn [ dataPerApp [ i ] . a ] [ "12_months" ] , dataPerApp [ i ] ) ;
221
+ toReturn [ "all-apps" ] [ "12_months" ] = increaseDataPoints ( toReturn [ "all-apps" ] [ "12_months" ] , dataPerApp [ i ] ) ;
185
222
}
186
223
}
187
- }
188
224
225
+ }
189
226
common . returnOutput ( params , toReturn ) ;
190
227
} ) ;
191
228
} , params ) ;
0 commit comments