diff --git a/src/main/kotlin/me/msoucy/gbat/Analyze.kt b/src/main/kotlin/me/msoucy/gbat/Analyze.kt new file mode 100644 index 0000000..2e9690d --- /dev/null +++ b/src/main/kotlin/me/msoucy/gbat/Analyze.kt @@ -0,0 +1,35 @@ +package me.msoucy.gbat + +import java.io.File + +import me.msoucy.gbat.models.KnowledgeModel +import me.msoucy.gbat.models.LineModel +import me.msoucy.gbat.models.RiskModel + +private data class Condensation(val authors : List, val knowledge : Double, val orphaned : Double, val atRisk : Double = 0.0) : Comparable { + override operator fun compareTo(other : Condensation) : Int { + return -1 + } +} +private class Result(val repoRoot : File, + val projectRoot : File, + val fname : File, + val results : List>>) + +private fun condenseAnalysis(repoRoot : File, + projectRoot : File, + fname : File, + lineModel : LineModel, + knowledgeModel : KnowledgeModel, + riskModel : RiskModel) : Result { + val condensations = lineModel.get().mapIndexed { idx, line -> + val knowledges = knowledgeModel.knowledgeSummary(idx + 1).map { (authors, knowledge) -> + Condensation(authors, + knowledge, + if(authors.all(riskModel::isDeparted)) knowledge else 0.0, + riskModel.jointBusProb(authors) * knowledge) + }.sorted() + Pair(line, knowledges) + } + return Result(repoRoot, projectRoot, fname, condensations) +} \ No newline at end of file diff --git a/src/main/kotlin/me/msoucy/gbat/Util.kt b/src/main/kotlin/me/msoucy/gbat/Util.kt index 8d33acb..abc8b34 100644 --- a/src/main/kotlin/me/msoucy/gbat/Util.kt +++ b/src/main/kotlin/me/msoucy/gbat/Util.kt @@ -4,7 +4,7 @@ import java.io.File import java.io.IOException import java.util.concurrent.TimeUnit -fun Iterable.copyOf() = mutableListOf().also { it.addAll(this) } +fun Iterable.copyOf() : List = mutableListOf().also { it.addAll(this) } fun Iterable.mutableCopyOf() = mutableListOf().also { it.addAll(this) } fun List.runCommand(workingDir: File): Pair { diff --git a/src/main/kotlin/me/msoucy/gbat/models/KnowledgeModel.kt b/src/main/kotlin/me/msoucy/gbat/models/KnowledgeModel.kt index 32a8c92..2b8ec32 100644 --- a/src/main/kotlin/me/msoucy/gbat/models/KnowledgeModel.kt +++ b/src/main/kotlin/me/msoucy/gbat/models/KnowledgeModel.kt @@ -130,7 +130,7 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R newAuthors.add(author) } newAuthors = newAuthors.sorted().mutableCopyOf() - val newKnowledgeId = if(riskModel.jointBusProbBelowThreshold(*newAuthors.toTypedArray())) { + val newKnowledgeId = if(riskModel.jointBusProbBelowThreshold(newAuthors)) { SAFE_KNOWLEDGE_ACCT_ID } else { lookupOrCreateKnowledgeAcct(newAuthors) diff --git a/src/main/kotlin/me/msoucy/gbat/models/RiskModel.kt b/src/main/kotlin/me/msoucy/gbat/models/RiskModel.kt index 55af3f6..679bbe7 100644 --- a/src/main/kotlin/me/msoucy/gbat/models/RiskModel.kt +++ b/src/main/kotlin/me/msoucy/gbat/models/RiskModel.kt @@ -25,11 +25,11 @@ class RiskModel(val threshold : Double, fun isDeparted(author : String) = author.trim() in departed - fun jointBusProb(vararg authors : String) = + fun jointBusProb(authors : List) = authors.map { this[it] }.reduce { a, b -> a * b } - fun jointBusProbBelowThreshold(vararg authors : String) = - jointBusProb(*authors) <= threshold + fun jointBusProbBelowThreshold(authors : List) = + jointBusProb(authors) <= threshold private fun parseBusRisks() { busRiskFile?.forEachLine { line ->