mirror of
https://github.com/ysoftdevs/odc-analyzer.git
synced 2026-03-21 00:29:38 +01:00
Refactored LibDepStatistics to include FailedProjects
This commit is contained in:
23
app/com/ysoft/odc/statistics/FailedProjects.scala
Normal file
23
app/com/ysoft/odc/statistics/FailedProjects.scala
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.ysoft.odc.statistics
|
||||
|
||||
import controllers.ReportInfo
|
||||
|
||||
final class FailedProjects(val failedProjectsSet: Set[String]){
|
||||
def isFailed(projectFullId: String): Boolean = {
|
||||
val projectBareId = projectFullId.takeWhile(_ != '/')
|
||||
failedProjectsSet contains projectBareId
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object FailedProjects {
|
||||
private[statistics] def combineFails(failedReportDownloads: Map[String, Throwable], parsingFailures: Map[ReportInfo, Throwable]): FailedProjects = {
|
||||
/*
|
||||
Fail can happen at multiple places:
|
||||
1. Build cannot be downloaded (auth error, connection error, …) or is failed (failedReportDownloads)
|
||||
2. Build is successful and can be downloaded, but it cannot be parsed (parsingFailures)
|
||||
*/
|
||||
val failedProjectsSet = failedReportDownloads.keySet ++ parsingFailures.keySet.map(_.projectId)
|
||||
new FailedProjects(failedProjectsSet)
|
||||
}
|
||||
}
|
||||
34
app/com/ysoft/odc/statistics/LibDepStatistics.scala
Normal file
34
app/com/ysoft/odc/statistics/LibDepStatistics.scala
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.ysoft.odc.statistics
|
||||
|
||||
import controllers.DependencyCheckReportsParser.Result
|
||||
import controllers._
|
||||
import models.Library
|
||||
|
||||
case class LibDepStatistics(libraries: Set[(Int, Library)], dependencies: Set[GroupedDependency], failedProjects: FailedProjects){
|
||||
def vulnerableRatio = vulnerableDependencies.size.toDouble / dependencies.size.toDouble
|
||||
lazy val vulnerabilities: Set[Vulnerability] = dependencies.flatMap(_.vulnerabilities)
|
||||
lazy val vulnerabilitiesByName = vulnerabilities.map(v => v.name -> v).toMap
|
||||
lazy val vulnerabilityNames = vulnerabilities.map(_.name)
|
||||
lazy val vulnerabilitiesToDependencies: Map[Vulnerability, Set[GroupedDependency]] = vulnerableDependencies.flatMap(dep =>
|
||||
dep.vulnerabilities.map(vuln => (vuln, dep))
|
||||
).groupBy(_._1).mapValues(_.map(_._2)).map(identity)
|
||||
vulnerableDependencies.flatMap(dep => dep.vulnerabilities.map(_ -> dep)).groupBy(_._1).mapValues(_.map(_._2)).map(identity)
|
||||
vulnerableDependencies.flatMap(dep => dep.vulnerabilities.map(_ -> dep)).groupBy(_._1).mapValues(_.map(_._2)).map(identity)
|
||||
lazy val vulnerableDependencies = dependencies.filter(_.isVulnerable)
|
||||
lazy val (dependenciesWithCpe, dependenciesWithoutCpe) = dependencies.partition(_.hasCpe)
|
||||
lazy val cpeRatio = dependenciesWithCpe.size.toDouble / dependencies.size.toDouble
|
||||
lazy val weaknesses = vulnerabilities.flatMap(_.cweOption)
|
||||
lazy val weaknessesFrequency = LibDepStatistics.computeWeaknessesFrequency(vulnerabilities)
|
||||
}
|
||||
|
||||
object LibDepStatistics{
|
||||
private def computeWeaknessesFrequency(vulnerabilities: Set[Vulnerability]) = vulnerabilities.toSeq.map(_.cweOption).groupBy(identity).mapValues(_.size).map(identity).withDefaultValue(0)
|
||||
def apply(libraries: Set[(Int, Library)], dependencies: Set[GroupedDependency], failedReportDownloads: Map[String, Throwable], parsedReports: Result): LibDepStatistics = LibDepStatistics(
|
||||
libraries = libraries,
|
||||
dependencies = dependencies,
|
||||
failedProjects = FailedProjects.combineFails(
|
||||
failedReportDownloads = failedReportDownloads,
|
||||
parsingFailures = parsedReports.failedAnalysises
|
||||
)
|
||||
)
|
||||
}
|
||||
8
app/com/ysoft/odc/statistics/TagStatistics.scala
Normal file
8
app/com/ysoft/odc/statistics/TagStatistics.scala
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.ysoft.odc.statistics
|
||||
|
||||
import models.LibraryTag
|
||||
|
||||
case class TagStatistics(tagRecord: (Int, LibraryTag), stats: LibDepStatistics){
|
||||
def tag: LibraryTag = tagRecord._2
|
||||
def tagId: Int = tagRecord._1
|
||||
}
|
||||
Reference in New Issue
Block a user