@@ -13,61 +13,59 @@ export interface MetricsQueryParams {
1313
1414class MetricsService {
1515 async getMetrics ( params : MetricsQueryParams ) {
16- const { org, type , since, until, editor, language, model } = params ;
17-
16+ const { org, since, until, editor, language, model } = params ; // type
17+
1818 const dateFilter = {
1919 ...( since && { $gte : new Date ( since ) } ) ,
2020 ...( until && { $lte : new Date ( until ) } )
2121 } ;
2222
23- const query : any = {
23+ const query : mongoose . FilterQuery < MetricDailyResponseType > = {
2424 ...( org && { org } ) ,
2525 ...( Object . keys ( dateFilter ) . length && { date : dateFilter } )
2626 } ;
2727
28- const types = type ? type . split ( / [ , ] + / ) : [ ] ;
29-
30- const metrics = await mongoose . model ( 'Metrics' ) . find ( query ) . sort ( { date :1 } ) . lean ( ) ;
28+ const metrics = await mongoose . model < MetricDailyResponseType > ( 'Metrics' ) . find ( query ) . sort ( { date : 1 } ) . lean ( ) ;
3129
3230 if ( editor || language || model ) {
3331 metrics . forEach ( metric => {
34- if ( metric . copilot_ide_code_completions ) {
35- metric . copilot_ide_code_completions . editors = metric . copilot_ide_code_completions . editors . filter ( ( editorItem : any ) => {
32+ if ( metric . copilot_ide_code_completions ?. editors ) {
33+ metric . copilot_ide_code_completions . editors = metric . copilot_ide_code_completions . editors . filter ( ( editorItem ) => {
3634 if ( editor && editorItem . name !== editor ) return false ;
37- if ( model ) {
38- editorItem . models = editorItem . models . filter ( ( modelItem : any ) => {
35+ if ( editorItem . models ) {
36+ editorItem . models = editorItem . models . filter ( ( modelItem ) => {
3937 if ( modelItem . name !== model ) return false ;
40- if ( language ) {
41- modelItem . languages = modelItem . languages . filter ( ( languageItem : any ) => languageItem . name === language ) ;
38+ if ( modelItem . languages ) {
39+ modelItem . languages = modelItem . languages . filter ( ( languageItem ) => languageItem . name === language ) ;
4240 }
4341 return true ;
4442 } ) ;
4543 }
4644 return true ;
4745 } ) ;
4846 }
49- if ( metric . copilot_ide_chat ) {
50- metric . copilot_ide_chat . editors = metric . copilot_ide_chat . editors . filter ( ( editorItem : any ) => {
47+ if ( metric . copilot_ide_chat ?. editors ) {
48+ metric . copilot_ide_chat . editors = metric . copilot_ide_chat . editors . filter ( ( editorItem ) => {
5149 if ( editor && editorItem . name !== editor ) return false ;
52- if ( model ) {
53- editorItem . models = editorItem . models . filter ( ( modelItem : any ) => {
50+ if ( editorItem . models ) {
51+ editorItem . models = editorItem . models . filter ( ( modelItem ) => {
5452 if ( modelItem . name !== model ) return false ;
5553 return true ;
5654 } ) ;
5755 }
5856 return true ;
5957 } ) ;
6058 }
61- if ( metric . copilot_dotcom_chat ) {
62- metric . copilot_dotcom_chat . models = metric . copilot_dotcom_chat . models . filter ( ( modelItem : any ) => {
59+ if ( metric . copilot_dotcom_chat ?. models ) {
60+ metric . copilot_dotcom_chat . models = metric . copilot_dotcom_chat . models . filter ( ( modelItem ) => {
6361 if ( modelItem . name !== model ) return false ;
6462 return true ;
6563 } ) ;
6664 }
67- if ( metric . copilot_dotcom_pull_requests ) {
68- metric . copilot_dotcom_pull_requests . repositories = metric . copilot_dotcom_pull_requests . repositories . filter ( ( repositoryItem : any ) => {
69- if ( model ) {
70- repositoryItem . models = repositoryItem . models . filter ( ( modelItem : any ) => {
65+ if ( metric . copilot_dotcom_pull_requests ?. repositories ) {
66+ metric . copilot_dotcom_pull_requests . repositories = metric . copilot_dotcom_pull_requests . repositories . filter ( ( repositoryItem ) => {
67+ if ( repositoryItem . models ) {
68+ repositoryItem . models = repositoryItem . models . filter ( ( modelItem ) => {
7169 if ( modelItem . name !== model ) return false ;
7270 return true ;
7371 } ) ;
@@ -152,13 +150,13 @@ class MetricsService {
152150 }
153151 } ;
154152
155- metrics . forEach ( ( daily : any ) => {
153+ metrics . forEach ( ( daily ) => {
156154 if ( daily . copilot_ide_code_completions ) {
157155 periodMetrics . copilot_ide_code_completions . total_code_acceptances += daily . copilot_ide_code_completions . total_code_acceptances || 0 ;
158156 periodMetrics . copilot_ide_code_completions . total_code_suggestions += daily . copilot_ide_code_completions . total_code_suggestions || 0 ;
159157 periodMetrics . copilot_ide_code_completions . total_code_lines_accepted += daily . copilot_ide_code_completions . total_code_lines_accepted || 0 ;
160158 periodMetrics . copilot_ide_code_completions . total_code_lines_suggested += daily . copilot_ide_code_completions . total_code_lines_suggested || 0 ;
161- daily . copilot_ide_code_completions . editors ?. forEach ( ( editor : any ) => {
159+ daily . copilot_ide_code_completions . editors ?. forEach ( ( editor ) => {
162160 let editorTotals = periodMetrics . copilot_ide_code_completions . editors . find ( e => e . name === editor . name ) ;
163161 if ( editorTotals ) {
164162 editorTotals . total_code_acceptances += editor . total_code_acceptances || 0 ;
@@ -176,7 +174,7 @@ class MetricsService {
176174 }
177175 periodMetrics . copilot_ide_code_completions . editors . push ( editorTotals ) ;
178176 }
179- editor . models ?. forEach ( ( model : any ) => {
177+ editor . models ?. forEach ( ( model ) => {
180178 let editorModelTotals = editorTotals ?. models . find ( m => m . name === model . name ) ;
181179 if ( editorModelTotals ) {
182180 editorModelTotals . total_code_acceptances += model . total_code_acceptances || 0 ;
@@ -194,7 +192,7 @@ class MetricsService {
194192 }
195193 editorTotals ?. models . push ( editorModelTotals ) ;
196194 }
197- model . languages ?. forEach ( ( language : any ) => {
195+ model . languages ?. forEach ( ( language ) => {
198196 let modelLanguageTotals = editorModelTotals ?. languages . find ( l => l . name === language . name ) ;
199197 if ( modelLanguageTotals ) {
200198 modelLanguageTotals . total_code_acceptances += language . total_code_acceptances || 0 ;
@@ -220,7 +218,7 @@ class MetricsService {
220218 periodMetrics . copilot_ide_chat . total_chats += daily . copilot_ide_chat . total_chats || 0 ;
221219 periodMetrics . copilot_ide_chat . total_chat_copy_events += daily . copilot_ide_chat . total_chat_copy_events || 0 ;
222220 periodMetrics . copilot_ide_chat . total_chat_insertion_events += daily . copilot_ide_chat . total_chat_insertion_events || 0 ;
223- daily . copilot_ide_chat . editors ?. forEach ( ( editor : any ) => {
221+ daily . copilot_ide_chat . editors ?. forEach ( ( editor ) => {
224222 let editorTotals = periodMetrics . copilot_ide_chat . editors . find ( e => e . name === editor . name ) ;
225223 if ( editorTotals ) {
226224 editorTotals . total_chats += editor . total_chats || 0 ;
@@ -236,7 +234,7 @@ class MetricsService {
236234 }
237235 periodMetrics . copilot_ide_chat . editors . push ( editorTotals ) ;
238236 }
239- editor . models ?. forEach ( ( model : any ) => {
237+ editor . models ?. forEach ( ( model ) => {
240238 let editorModelTotals = editorTotals ?. models . find ( m => m . name === model . name ) ;
241239 if ( editorModelTotals ) {
242240 editorModelTotals . total_chats += model . total_chats || 0 ;
@@ -257,7 +255,7 @@ class MetricsService {
257255
258256 if ( daily . copilot_dotcom_chat ) {
259257 periodMetrics . copilot_dotcom_chat . total_chats += daily . copilot_dotcom_chat . total_chats || 0 ;
260- daily . copilot_dotcom_chat . models ?. forEach ( ( model : any ) => {
258+ daily . copilot_dotcom_chat . models ?. forEach ( ( model ) => {
261259 let modelTotals = periodMetrics . copilot_dotcom_chat . models . find ( m => m . name === model . name ) ;
262260 if ( modelTotals ) {
263261 modelTotals . total_chats += model . total_chats || 0 ;
@@ -273,7 +271,7 @@ class MetricsService {
273271
274272 if ( daily . copilot_dotcom_pull_requests ) {
275273 periodMetrics . copilot_dotcom_pull_requests . total_pr_summaries_created += daily . copilot_dotcom_pull_requests . total_pr_summaries_created || 0 ;
276- daily . copilot_dotcom_pull_requests . repositories ?. forEach ( ( repository : any ) => {
274+ daily . copilot_dotcom_pull_requests . repositories ?. forEach ( ( repository ) => {
277275 let repositoryTotals = periodMetrics . copilot_dotcom_pull_requests . repositories . find ( r => r . name === repository . name ) ;
278276 if ( repositoryTotals ) {
279277 repositoryTotals . total_pr_summaries_created += repository . total_pr_summaries_created || 0 ;
@@ -285,7 +283,7 @@ class MetricsService {
285283 }
286284 periodMetrics . copilot_dotcom_pull_requests . repositories . push ( repositoryTotals ) ;
287285 }
288- repository . models ?. forEach ( ( model : any ) => {
286+ repository . models ?. forEach ( ( model ) => {
289287 const repositoryModelTotals = repositoryTotals ?. models . find ( m => m . name === model . name ) ;
290288 if ( repositoryModelTotals ) {
291289 repositoryModelTotals . total_pr_summaries_created += model . total_pr_summaries_created || 0 ;
0 commit comments