private Double fetchBuildDurationWithinThresholdRatio ( Iterable < Build > builds , long thresholdInMillis ) { int totalBuilds = 0 , totalBelowThreshold = 0 ; for ( Build build : builds ) { if ( ! Constants . SUCCESS_STATUS . contains ( build . getBuildStatus ( ) ) ) { continue ; } totalBuilds ++ ; if ( build . getDuration ( ) < thresholdInMillis ) { totalBelowThreshold ++ ; } } if ( totalBuilds == 0 ) { return 0.0d ; } return ( ( totalBelowThreshold * 100 ) / ( double ) totalBuilds ) ; }
Calculate builds that completed successfully within threshold time Only builds with status as Success Unstable is included for calculation