@@ -184,8 +184,16 @@ class StatsJob extends job.Job {
184184 utcMoment . subtract ( 1 , 'days' ) ;
185185 }
186186
187+ // always create a dedicated array for last 30 days
188+ const last30Dates = [ ] ;
189+ const last30Moment = moment . utc ( ) ;
190+ for ( let i = 0 ; i < 30 ; i ++ ) {
191+ last30Dates . push ( last30Moment . format ( 'YYYY:M:D' ) ) ;
192+ last30Moment . subtract ( 1 , 'days' ) ;
193+ }
194+
187195 const options = {
188- dailyDates : specificDates ,
196+ dailyDates : last30Dates ,
189197 monthlyBreakdown : true ,
190198 license_hosting : license ?. license_hosting ,
191199 } ;
@@ -205,6 +213,47 @@ class StatsJob extends job.Job {
205213 user . add_event ( { key : "DP" , count : allData . daily [ key ] , timestamp : timestamp , segmentation : allData . dailybreakdown ? allData . dailybreakdown [ key ] : { } } ) ;
206214 }
207215 }
216+ // Get all apps
217+ const apps = await db . collection ( 'apps' ) . find ( { } , { projection : { _id : 1 } } ) . toArray ( ) ;
218+
219+ // For each app, sum DP for last 30 days using allData.dailybreakdown and last30Dates
220+ const appDPs = { } ;
221+ for ( const app of apps ) {
222+ appDPs [ app . _id ] = 0 ;
223+ if ( allData . apps && allData . apps [ app . _id ] ) {
224+ appDPs [ app . _id ] = allData . apps [ app . _id ] ;
225+ }
226+ }
227+
228+ // Count apps in each DP range
229+ dataMonthly . appsLT10KDP = 0 ;
230+ dataMonthly . apps10Kto100KDP = 0 ;
231+ dataMonthly . apps100Kto1MDP = 0 ;
232+ dataMonthly . apps1Mto10MDP = 0 ;
233+ dataMonthly . apps10Mto100MDP = 0 ;
234+ dataMonthly . appsGT100MDP = 0 ;
235+ for ( const appId in appDPs ) {
236+ const dp = appDPs [ appId ] ;
237+ if ( dp < 10000 ) {
238+ dataMonthly . appsLT10KDP ++ ;
239+ }
240+ else if ( dp < 100000 ) {
241+ dataMonthly . apps10Kto100KDP ++ ;
242+ }
243+ else if ( dp < 1000000 ) {
244+ dataMonthly . apps100Kto1MDP ++ ;
245+ }
246+ else if ( dp < 10000000 ) {
247+ dataMonthly . apps1Mto10MDP ++ ;
248+ }
249+ else if ( dp < 100000000 ) {
250+ dataMonthly . apps10Mto100MDP ++ ;
251+ }
252+ else {
253+ dataMonthly . appsGT100MDP ++ ;
254+ }
255+ }
256+
208257 user . user_details ( { 'custom' : dataMonthly } ) ;
209258 server . start ( function ( ) {
210259 server . stop ( ) ;
0 commit comments