@@ -5,15 +5,17 @@ import { Observable, Subscription, debounceTime, map, startWith } from 'rxjs';
55import { CustomUsageReportLine , UsageReportService } from 'src/app/usage-report.service' ;
66import { DialogBillingNavigateComponent } from './dialog-billing-navigate' ;
77import { MatDialog } from '@angular/material/dialog' ;
8+ import { ModelUsageReport } from 'github-usage-report' ;
89
910@Component ( {
10- selector : 'app-usage' ,
11- templateUrl : './usage.component.html' ,
12- styleUrls : [ './usage.component.scss' ] ,
13- standalone : false
11+ selector : 'app-usage' ,
12+ templateUrl : './usage.component.html' ,
13+ styleUrls : [ './usage.component.scss' ] ,
14+ standalone : false
1415} )
1516export class UsageComponent implements OnInit , OnDestroy {
1617 usage ! : UsageReport ;
18+ usageCopilotPremiumRequests ! : ModelUsageReport ;
1719 usageLines = { } as {
1820 sharedStorage : CustomUsageReportLine [ ] ,
1921 codespaces : CustomUsageReportLine [ ] ,
@@ -92,31 +94,38 @@ export class UsageComponent implements OnInit, OnDestroy {
9294 this . subscriptions . forEach ( subscription => subscription . unsubscribe ( ) ) ;
9395 }
9496
95- async onFileText ( fileText : string ) {
97+ async onFileText ( fileText : string , type : 'metered' | 'copilot_premium_requests' ) {
9698 this . status = 'Parsing File...' ;
97- const usage = await this . usageReportService . setUsageReportData ( fileText , async ( _ : any , progress : any ) : Promise < any > => {
98- return await new Promise ( ( resolve ) => {
99- if ( progress === this . progress ) return resolve ( '' ) ;
100- setTimeout ( ( ) => {
101- this . progress = progress ;
102- this . status = `Parsing File... ${ progress } %`
103- resolve ( '' ) ;
104- } , 0 )
105- } ) ;
106- } ) . then ( async ( usage ) => {
107- this . status = 'Loading... Be patient, this may take a while.' ;
108- return new Promise < UsageReport > ( resolve => setTimeout ( ( ) => resolve ( usage ) , 100 ) ) ;
109- } ) ;
110- this . minDate = new Date ( usage . lines [ 0 ] ?. date ) ;
111- this . maxDate = new Date ( usage . lines [ usage . lines . length - 1 ] ?. date ) ;
99+
100+ const progressFunction = async ( _ : any , progress : any ) : Promise < any > => {
101+ return await new Promise ( ( resolve ) => {
102+ if ( progress === this . progress ) return resolve ( '' ) ;
103+ this . progress = progress ;
104+ this . status = `Parsing File... ${ progress } %`
105+ resolve ( '' ) ;
106+ } ) ;
107+ } ;
108+ const usage = await ( type === 'metered' ? this . usageReportService . setUsageReportData ( fileText , progressFunction ) : type === 'copilot_premium_requests' ? this . usageReportService . setUsageReportCopilotPremiumRequests ( fileText , progressFunction ) : null ) ;
109+ if ( ! usage ) {
110+ this . status = 'Error parsing file. Please check the file format.' ;
111+ return ;
112+ }
113+ const firstLine = usage . lines [ 0 ] ;
114+ const lastLine = usage . lines [ usage . lines . length - 1 ] ;
115+ this . minDate = new Date ( firstLine && 'date' in firstLine ? firstLine . date : new Date ( ) ) ;
116+ this . maxDate = new Date ( lastLine && 'date' in lastLine ? lastLine . date : new Date ( ) ) ;
112117 // make the date 00:00:00
113118 this . minDate . setHours ( 0 , 0 , 0 , 0 ) ;
114119 this . maxDate . setHours ( 0 , 0 , 0 , 0 ) ;
115120 this . range . controls . start . setValue ( this . minDate , { emitEvent : false } ) ;
116121 this . range . controls . end . setValue ( this . maxDate , { emitEvent : false } ) ;
122+ if ( type === 'copilot_premium_requests' ) {
123+ this . usageCopilotPremiumRequests = usage as ModelUsageReport ;
124+ } else {
125+ this . usage = usage as UsageReport ;
126+ }
117127 this . status = 'Usage Report' ;
118128 this . progress = null ;
119- this . usage = usage ;
120129 this . cdr . detectChanges ( ) ;
121130 }
122131
0 commit comments