Start analysis
This commit is contained in:
parent
f754b90353
commit
6701ec3df0
35
src/main/kotlin/me/msoucy/gbat/Analyze.kt
Normal file
35
src/main/kotlin/me/msoucy/gbat/Analyze.kt
Normal file
@ -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<String>, val knowledge : Double, val orphaned : Double, val atRisk : Double = 0.0) : Comparable<Condensation> {
|
||||||
|
override operator fun compareTo(other : Condensation) : Int {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private class Result(val repoRoot : File,
|
||||||
|
val projectRoot : File,
|
||||||
|
val fname : File,
|
||||||
|
val results : List<Pair<String, List<Condensation>>>)
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
@ -4,7 +4,7 @@ import java.io.File
|
|||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
fun <T> Iterable<T>.copyOf() = mutableListOf<T>().also { it.addAll(this) }
|
fun <T> Iterable<T>.copyOf() : List<T> = mutableListOf<T>().also { it.addAll(this) }
|
||||||
fun <T> Iterable<T>.mutableCopyOf() = mutableListOf<T>().also { it.addAll(this) }
|
fun <T> Iterable<T>.mutableCopyOf() = mutableListOf<T>().also { it.addAll(this) }
|
||||||
|
|
||||||
fun List<String>.runCommand(workingDir: File): Pair<String?,String?> {
|
fun List<String>.runCommand(workingDir: File): Pair<String?,String?> {
|
||||||
|
@ -130,7 +130,7 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
|
|||||||
newAuthors.add(author)
|
newAuthors.add(author)
|
||||||
}
|
}
|
||||||
newAuthors = newAuthors.sorted().mutableCopyOf()
|
newAuthors = newAuthors.sorted().mutableCopyOf()
|
||||||
val newKnowledgeId = if(riskModel.jointBusProbBelowThreshold(*newAuthors.toTypedArray())) {
|
val newKnowledgeId = if(riskModel.jointBusProbBelowThreshold(newAuthors)) {
|
||||||
SAFE_KNOWLEDGE_ACCT_ID
|
SAFE_KNOWLEDGE_ACCT_ID
|
||||||
} else {
|
} else {
|
||||||
lookupOrCreateKnowledgeAcct(newAuthors)
|
lookupOrCreateKnowledgeAcct(newAuthors)
|
||||||
|
@ -25,11 +25,11 @@ class RiskModel(val threshold : Double,
|
|||||||
|
|
||||||
fun isDeparted(author : String) = author.trim() in departed
|
fun isDeparted(author : String) = author.trim() in departed
|
||||||
|
|
||||||
fun jointBusProb(vararg authors : String) =
|
fun jointBusProb(authors : List<String>) =
|
||||||
authors.map { this[it] }.reduce { a, b -> a * b }
|
authors.map { this[it] }.reduce { a, b -> a * b }
|
||||||
|
|
||||||
fun jointBusProbBelowThreshold(vararg authors : String) =
|
fun jointBusProbBelowThreshold(authors : List<String>) =
|
||||||
jointBusProb(*authors) <= threshold
|
jointBusProb(authors) <= threshold
|
||||||
|
|
||||||
private fun parseBusRisks() {
|
private fun parseBusRisks() {
|
||||||
busRiskFile?.forEachLine { line ->
|
busRiskFile?.forEachLine { line ->
|
||||||
|
Loading…
Reference in New Issue
Block a user