1+ import { CoveredEndpoint , FoundFault } from "@/types/GeneratedTypes.tsx" ;
2+
13export const getColor = ( code : string | number , isBackground : boolean , isFault : boolean ) => {
24 if ( isFault ) {
35 return isBackground ? "bg-red-500" : "text-red-500" ;
@@ -57,4 +59,68 @@ export const extractCodeLines = (
5759 }
5860
5961 return lines . slice ( startIndex , endIndex + 2 ) . join ( '\n' ) ;
60- } ;
62+ } ;
63+
64+ export const calculateAllStatusCounts = ( covered_http_status : CoveredEndpoint [ ] , endpoint_ids :string [ ] ) => {
65+ const allStatusCounts = {
66+ "2XX" : 0 ,
67+ "3XX" : 0 ,
68+ "4XX" : 0 ,
69+ "5XX" : 0
70+ }
71+
72+ endpoint_ids . map (
73+ ( endpoint ) => {
74+ const allStatusCodes = covered_http_status . filter ( status => status . endpoint_id === endpoint )
75+ . map (
76+ ( status ) => status . http_status
77+ ) . flat ( )
78+ const uniqueStatusCodes = [ ...new Set ( allStatusCodes ) ] ;
79+
80+ const isContainStatusCode = {
81+ "2XX" : false ,
82+ "3XX" : false ,
83+ "4XX" : false ,
84+ "5XX" : false
85+ }
86+
87+ uniqueStatusCodes . map (
88+ ( status ) => {
89+ if ( status >= 200 && status < 300 ) {
90+ isContainStatusCode [ "2XX" ] = true ;
91+ } else if ( status >= 300 && status < 400 ) {
92+ isContainStatusCode [ "3XX" ] = true ;
93+ } else if ( status >= 400 && status < 500 ) {
94+ isContainStatusCode [ "4XX" ] = true ;
95+ } else if ( status >= 500 && status < 600 ) {
96+ isContainStatusCode [ "5XX" ] = true ;
97+ }
98+ }
99+ )
100+
101+ if ( isContainStatusCode [ "2XX" ] ) {
102+ allStatusCounts [ "2XX" ] ++ ;
103+ }
104+ if ( isContainStatusCode [ "3XX" ] ) {
105+ allStatusCounts [ "3XX" ] ++ ;
106+ }
107+ if ( isContainStatusCode [ "4XX" ] ) {
108+ allStatusCounts [ "4XX" ] ++ ;
109+ }
110+ if ( isContainStatusCode [ "5XX" ] ) {
111+ allStatusCounts [ "5XX" ] ++ ;
112+ }
113+ }
114+ )
115+ return allStatusCounts ;
116+ }
117+
118+ export const getFaultCounts = ( found_faults : FoundFault [ ] ) => {
119+ const faultCounts = new Map ( ) ;
120+ found_faults . forEach ( fault => {
121+ fault . fault_categories . forEach ( category => {
122+ faultCounts . set ( category . code , ( faultCounts . get ( category . code ) || 0 ) + 1 ) ;
123+ } ) ;
124+ } ) ;
125+ return faultCounts ;
126+ }
0 commit comments