@@ -3,21 +3,36 @@ import { Table } from "console-table-printer";
33import { parseArgs } from "util" ;
44import { cpus } from "node:os" ;
55import type { ICmd } from "@al/cmd/utils/cmd-runner" ;
6- import { type ITask , type IResult } from "./worker" ;
6+ import type {
7+ ITask ,
8+ IResult ,
9+ IGroupedMsg ,
10+ ISummaryMap ,
11+ ISummaryMapGeneric ,
12+ } from "./worker" ;
713import WorkerPool from "@al/cmd/utils/worker-pool" ;
814import fileHelper from "@al/cmd/utils/file-helper" ;
9- import type {
10- GroupedMsg ,
11- Summary as SummaryData ,
12- SummaryMap ,
13- } from "@al/ui/models/logData" ;
14- import LogData from "@al/ui/models/logData" ;
1515
1616let workerURL = new URL ( "worker.ts" , import . meta. url ) ;
1717
18- interface IStats extends Omit < IResult , "filePath" > {
18+ interface IStats extends Omit < IResult , "filePath" | "dataMap" > {
1919 minTimeFile : string ;
2020 maxTimeFile : string ;
21+ dataMap : IStatsSummaryMap ;
22+ }
23+
24+ interface IStatsGroupedMsg extends IGroupedMsg {
25+ firstFile : string ;
26+ lastFile : string ;
27+ }
28+
29+ type IStatsSummaryMap = ISummaryMapGeneric < IStatsGroupedMsg > ;
30+
31+ interface ISummary {
32+ msgs : IStatsGroupedMsg [ ] ;
33+ httpCodes : IStatsGroupedMsg [ ] ;
34+ jobs : IStatsGroupedMsg [ ] ;
35+ plugins : IStatsGroupedMsg [ ] ;
2136}
2237
2338const stats : IStats = {
@@ -27,10 +42,10 @@ const stats: IStats = {
2742 minTimeFile : "" ,
2843 size : 0 ,
2944 dataMap : {
30- httpCodes : new Map < string , GroupedMsg > ( ) ,
31- jobs : new Map < string , GroupedMsg > ( ) ,
32- msgs : new Map < string , GroupedMsg > ( ) ,
33- plugins : new Map < string , GroupedMsg > ( ) ,
45+ httpCodes : new Map < string , IStatsGroupedMsg > ( ) ,
46+ jobs : new Map < string , IStatsGroupedMsg > ( ) ,
47+ msgs : new Map < string , IStatsGroupedMsg > ( ) ,
48+ plugins : new Map < string , IStatsGroupedMsg > ( ) ,
3449 } ,
3550} ;
3651
@@ -109,7 +124,7 @@ async function processLogs() {
109124 await readFiles ( filePaths ) ;
110125 console . log ( "=========End Read Files=========" ) ;
111126
112- const summary = LogData . initSummary ( stats . dataMap ) ;
127+ const summary = initSummary ( stats . dataMap ) ;
113128
114129 writeContent ( summary ) ;
115130}
@@ -155,37 +170,64 @@ function processFileResponse(fileStats: IResult) {
155170
156171 stats . size += fileStats . size ;
157172
158- initSummaryMap ( fileStats . dataMap ) ;
173+ initSummaryMap ( fileStats . dataMap , fileStats . filePath ) ;
159174}
160175
161- function initSummaryMap ( dataMap : SummaryMap ) {
162- mergeIntoOverallMap ( dataMap . httpCodes , stats . dataMap . httpCodes ) ;
163- mergeIntoOverallMap ( dataMap . jobs , stats . dataMap . jobs ) ;
164- mergeIntoOverallMap ( dataMap . msgs , stats . dataMap . msgs ) ;
165- mergeIntoOverallMap ( dataMap . plugins , stats . dataMap . plugins ) ;
176+ function initSummaryMap ( dataMap : ISummaryMap , filePath : string ) {
177+ mergeIntoOverallMap ( dataMap . httpCodes , stats . dataMap . httpCodes , filePath ) ;
178+ mergeIntoOverallMap ( dataMap . jobs , stats . dataMap . jobs , filePath ) ;
179+ mergeIntoOverallMap ( dataMap . msgs , stats . dataMap . msgs , filePath ) ;
180+ mergeIntoOverallMap ( dataMap . plugins , stats . dataMap . plugins , filePath ) ;
166181}
167182
168183function mergeIntoOverallMap (
169- fileMap : Map < string , GroupedMsg > ,
170- overallMap : Map < string , GroupedMsg >
184+ fileMap : Map < string , IGroupedMsg > ,
185+ overallMap : Map < string , IStatsGroupedMsg > ,
186+ filePath : string
171187) {
172188 for ( const [ k , v ] of fileMap ) {
173189 if ( ! overallMap . has ( k ) ) {
174190 overallMap . set ( k , {
175191 msg : v . msg ,
176192 hasErrors : false ,
177- logs : [ ] ,
178193 logsCount : 0 ,
194+ firstTime : v . firstTime ,
195+ lastTime : v . lastTime ,
196+ firstFile : filePath ,
197+ lastFile : filePath ,
179198 } ) ;
180199 }
181200
182201 const grpOverall = overallMap . get ( k ) ! ;
183- grpOverall . hasErrors = grpOverall . hasErrors || v . hasErrors ;
202+ grpOverall . hasErrors ||= v . hasErrors ;
184203 grpOverall . logsCount += v . logsCount ! ;
204+
205+ if ( v . firstTime < grpOverall . firstTime ) {
206+ grpOverall . firstTime = v . firstTime ;
207+ grpOverall . firstFile = filePath ;
208+ }
209+
210+ if ( v . lastTime > grpOverall . lastTime ) {
211+ grpOverall . lastTime = v . lastTime ;
212+ grpOverall . lastFile = filePath ;
213+ }
185214 }
186215}
187216
188- function writeContent ( summary : SummaryData ) {
217+ function summarySorterFn ( a : IStatsGroupedMsg , b : IStatsGroupedMsg ) {
218+ return b . logsCount - a . logsCount ;
219+ }
220+
221+ function initSummary ( summaryMap : IStatsSummaryMap ) : ISummary {
222+ return {
223+ msgs : [ ...summaryMap . msgs . values ( ) ] . sort ( summarySorterFn ) ,
224+ httpCodes : [ ...summaryMap . httpCodes . values ( ) ] . sort ( summarySorterFn ) ,
225+ jobs : [ ...summaryMap . jobs . values ( ) ] . sort ( summarySorterFn ) ,
226+ plugins : [ ...summaryMap . plugins . values ( ) ] . sort ( summarySorterFn ) ,
227+ } ;
228+ }
229+
230+ function writeContent ( summary : ISummary ) {
189231 console . log ( ) ;
190232
191233 stats . size = prettyBytes ( stats . size ) as any ;
@@ -217,15 +259,15 @@ function writeContent(summary: SummaryData) {
217259 writeGroupedMsgs ( summary . plugins , "Plugins" ) ;
218260}
219261
220- function writeGroupedMsgs ( grpMsgs : GroupedMsg [ ] , title : string ) {
262+ function writeGroupedMsgs ( grpMsgs : IStatsGroupedMsg [ ] , title : string ) {
221263 console . log ( ) ;
222264
223265 const table = new Table ( {
224266 columns : [
225267 { name : "msg" , title : title , alignment : "left" } ,
226268 { name : "logsCount" , title : "Count" } ,
227269 ] ,
228- disabledColumns : [ "hasErrors" , "logs" ] ,
270+ disabledColumns : [ "hasErrors" ] ,
229271 } ) ;
230272
231273 for ( const grp of grpMsgs . slice ( 0 , flags . topLogsCount ) ) {
0 commit comments