@@ -675,50 +675,61 @@ export class Workunit extends StateObject<UWorkunitState, IWorkunitState> implem
675675 Measure : "label"
676676 }
677677 } ;
678- const data : IScope [ ] = [ ] ;
679- for ( const scope of scopes ) {
680- const props = { } ;
681- const formattedProps = { } ;
682- if ( scope && scope . Id && scope . Properties && scope . Properties . Property ) {
683- for ( const key in scope . Properties . Property ) {
684- const scopeProperty = scope . Properties . Property [ key ] ;
685- if ( scopeProperty . Measure === "ns" ) {
678+ const activityMap = new Map < number , string > ( ) ;
679+ for ( const activity of meta . Activities ?. Activity ?? [ ] ) {
680+ activityMap . set ( activity . Kind , activity . Name ) ;
681+ }
682+ const data : IScope [ ] = new Array ( scopes . length ) ;
683+ for ( let i = 0 ; i < scopes . length ; i ++ ) {
684+ const scope = scopes [ i ] ;
685+ const props : { [ key : string ] : any } = { } ;
686+ const formattedProps : { [ key : string ] : any } = { } ;
687+ if ( scope ?. Id && scope . Properties ?. Property ) {
688+ for ( const scopeProperty of scope . Properties . Property ) {
689+ const measure = scopeProperty . Measure ;
690+ const name = scopeProperty . Name ;
691+ const rawValue = scopeProperty . RawValue ;
692+ if ( measure === "ns" ) {
686693 scopeProperty . Measure = "s" ;
687694 }
688- if ( scopeProperty . Name === "Kind" ) {
689- const rawValue = parseInt ( scopeProperty . RawValue , 10 ) ;
690- scopeProperty . Formatted = meta . Activities . Activity . filter ( a => a . Kind === rawValue ) [ 0 ] . Name ?? scopeProperty . RawValue ;
695+ if ( name === "Kind" ) {
696+ const rawValueInt = parseInt ( rawValue , 10 ) ;
697+ scopeProperty . Formatted = activityMap . get ( rawValueInt ) ?? rawValue ;
691698 }
692- columns [ scopeProperty . Name ] = { ...scopeProperty } ;
693- safeDelete ( columns , scopeProperty . Name , "RawValue" ) ;
694- safeDelete ( columns , scopeProperty . Name , "Formatted" ) ;
699+ columns [ name ] = {
700+ Name : scopeProperty . Name ,
701+ Measure : scopeProperty . Measure ,
702+ Creator : scopeProperty . Creator ,
703+ CreatorType : scopeProperty . CreatorType
704+ } ;
705+ const numericRawValue = + rawValue ;
695706 switch ( scopeProperty . Measure ) {
696707 case "bool" :
697- props [ scopeProperty . Name ] = ! ! + scopeProperty . RawValue ;
708+ props [ name ] = ! ! numericRawValue ;
698709 break ;
699710 case "sz" :
700- props [ scopeProperty . Name ] = + scopeProperty . RawValue ;
711+ props [ name ] = numericRawValue ;
701712 break ;
702713 case "s" :
703- props [ scopeProperty . Name ] = + scopeProperty . RawValue / 1000000000 ;
714+ props [ scopeProperty . Name ] = numericRawValue / 1000000000 ;
704715 break ;
705716 case "ns" :
706- props [ scopeProperty . Name ] = + scopeProperty . RawValue ;
717+ props [ name ] = numericRawValue ;
707718 break ;
708719 case "ts" :
709- props [ scopeProperty . Name ] = new Date ( + scopeProperty . RawValue / 1000 ) . toISOString ( ) ;
720+ props [ scopeProperty . Name ] = new Date ( numericRawValue / 1000 ) . toISOString ( ) ;
710721 break ;
711722 case "cnt" :
712- props [ scopeProperty . Name ] = + scopeProperty . RawValue ;
723+ props [ name ] = numericRawValue ;
713724 break ;
714725 case "cost" :
715- props [ scopeProperty . Name ] = + scopeProperty . RawValue / 1000000 ;
726+ props [ scopeProperty . Name ] = numericRawValue / 1000000 ;
716727 break ;
717728 case "node" :
718- props [ scopeProperty . Name ] = + scopeProperty . RawValue ;
729+ props [ name ] = numericRawValue ;
719730 break ;
720731 case "skw" :
721- props [ scopeProperty . Name ] = + scopeProperty . RawValue ;
732+ props [ name ] = numericRawValue ;
722733 break ;
723734 case "cpu" :
724735 case "ppm" :
@@ -729,11 +740,10 @@ export class Workunit extends StateObject<UWorkunitState, IWorkunitState> implem
729740 case "id" :
730741 case "fname" :
731742 default :
732- props [ scopeProperty . Name ] = scopeProperty . RawValue ;
743+ props [ name ] = rawValue ;
733744 }
734- formattedProps [ scopeProperty . Name ] = formatNum ( scopeProperty . Formatted ?? props [ scopeProperty . Name ] ) ;
745+ formattedProps [ name ] = formatNum ( scopeProperty . Formatted ?? props [ name ] ) ;
735746 }
736- // Other properties ---
737747 }
738748 const normalizedScope : IScope = {
739749 id : scope . Id ,
@@ -748,37 +758,47 @@ export class Workunit extends StateObject<UWorkunitState, IWorkunitState> implem
748758 __StdDevsSource : "" ,
749759 ...props
750760 } ;
751- if ( normalizedScope [ DEFINITION_LIST ] ) {
761+ const definitionList = normalizedScope [ DEFINITION_LIST ] ;
762+ if ( definitionList ) {
752763 try {
753- const definitionList = JSON . parse ( normalizedScope [ DEFINITION_LIST ] . split ( "\\" ) . join ( "\\\\" ) ) ;
754- normalizedScope [ DEFINITION_LIST ] = [ ] ;
755- definitionList . forEach ( ( definition , idx ) => {
756- const matches = definition . match ( definitionRegex ) ;
764+ const parsedList = JSON . parse ( definitionList . split ( "\\" ) . join ( "\\\\" ) ) ;
765+ const processedDefinitions : Array < { filePath : string , line : number , col : number } > = [ ] ;
766+
767+ for ( let k = 0 ; k < parsedList . length ; k ++ ) {
768+ const matches = parsedList [ k ] . match ( definitionRegex ) ;
757769 if ( matches ) {
758- const filePath = ( matches [ 1 ] ?? "" ) + matches [ 2 ] + matches [ 3 ] ;
759- const line = parseInt ( matches [ 5 ] ) ;
760- const col = parseInt ( matches [ 6 ] ) ;
761- normalizedScope [ DEFINITION_LIST ] . push ( { filePath, line, col } ) ;
770+ processedDefinitions . push ( {
771+ filePath : ( matches [ 1 ] ?? "" ) + matches [ 2 ] + matches [ 3 ] ,
772+ line : parseInt ( matches [ 5 ] , 10 ) ,
773+ col : parseInt ( matches [ 6 ] , 10 )
774+ } ) ;
762775 }
763- } ) ;
776+ }
777+ normalizedScope [ DEFINITION_LIST ] = processedDefinitions ;
764778 } catch ( e ) {
765- logger . error ( `Unexpected "DefinitionList": ${ normalizedScope [ DEFINITION_LIST ] } ` ) ;
779+ logger . error ( `Unexpected "DefinitionList": ${ definitionList } ` ) ;
766780 }
767781 }
782+
768783 const dedup : DedupProperties = { } ;
784+ let maxStdDevs = 0 ;
785+ let maxStdDevsSource = "" ;
769786 for ( const key in normalizedScope ) {
770- if ( key . indexOf ( "__" ) !== 0 ) {
787+ if ( ! key . startsWith ( "__" ) ) {
771788 const row = formatValues ( normalizedScope , key , dedup ) ;
772789 if ( row ) {
773790 normalizedScope . __groupedProps [ row . Key ] = row ;
774- if ( ! isNaN ( row . StdDevs ) && normalizedScope . __StdDevs < row . StdDevs ) {
775- normalizedScope . __StdDevs = row . StdDevs ;
776- normalizedScope . __StdDevsSource = row . Key ;
791+ if ( ! isNaN ( row . StdDevs ) && row . StdDevs > maxStdDevs ) {
792+ maxStdDevs = row . StdDevs ;
793+ maxStdDevsSource = row . Key ;
777794 }
778795 }
779796 }
780797 }
781- data . push ( normalizedScope ) ;
798+ normalizedScope . __StdDevs = maxStdDevs ;
799+ normalizedScope . __StdDevsSource = maxStdDevsSource ;
800+
801+ data [ i ] = normalizedScope ;
782802 }
783803 return {
784804 meta,
0 commit comments