Tweaks so it runs
This commit is contained in:
		@@ -17,7 +17,8 @@ fun analyze(
 | 
			
		||||
    verbose : Boolean = false
 | 
			
		||||
) : CondensedAnalysis {
 | 
			
		||||
    val lineModel = LineModel()
 | 
			
		||||
    val db = Database.connect("jdbc:sqlite:memory:", "org.sqlite.JDBC")
 | 
			
		||||
    val db = Database.connect("jdbc:sqlite::memory:", "org.sqlite.JDBC")
 | 
			
		||||
    return transaction(db) {
 | 
			
		||||
        val knowledgeModel = KnowledgeModel(db, createdConstant, riskModel)
 | 
			
		||||
        var changesProcessed = 0
 | 
			
		||||
 | 
			
		||||
@@ -32,19 +33,20 @@ fun analyze(
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    return condenseAnalysis(
 | 
			
		||||
        historyItem.repoRoot.path,
 | 
			
		||||
        historyItem.projectRoot.path,
 | 
			
		||||
        historyItem.fname.path,
 | 
			
		||||
        condenseAnalysis(
 | 
			
		||||
            historyItem.repoRoot,
 | 
			
		||||
            historyItem.projectRoot,
 | 
			
		||||
            historyItem.fname,
 | 
			
		||||
            lineModel,
 | 
			
		||||
            knowledgeModel,
 | 
			
		||||
            riskModel)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
private fun condenseAnalysis(
 | 
			
		||||
    repoRoot : String,
 | 
			
		||||
    projectRoot : String,
 | 
			
		||||
    fname : String,
 | 
			
		||||
    repoRoot : File,
 | 
			
		||||
    projectRoot : File,
 | 
			
		||||
    fname : File,
 | 
			
		||||
    lineModel : LineModel,
 | 
			
		||||
    knowledgeModel : KnowledgeModel,
 | 
			
		||||
    riskModel : RiskModel
 | 
			
		||||
 
 | 
			
		||||
@@ -136,7 +136,7 @@ fun main(args: Array<String>) = mainBody {
 | 
			
		||||
        val riskModel = RiskModel(riskThresh, default_bus_risk, risk_file, departed)
 | 
			
		||||
 | 
			
		||||
        val dbFname = File(outDir, "summary.db")
 | 
			
		||||
        val summaryDb = Database.connect(dbFname.absolutePath, "org.sqlite.JDBC")
 | 
			
		||||
        val summaryDb = Database.connect("jdbc:sqlite:${dbFname.absolutePath}", driver="org.sqlite.JDBC")
 | 
			
		||||
        transaction(summaryDb) {
 | 
			
		||||
            exec("PRAGMA journal_mode = OFF")
 | 
			
		||||
            exec("PRAGMA synchronous = OFF")
 | 
			
		||||
 
 | 
			
		||||
@@ -27,12 +27,13 @@ class GitRepo(val projectRoot : File, val git_exe : String) {
 | 
			
		||||
            "--show-toplevel"
 | 
			
		||||
        )
 | 
			
		||||
        val (out, _) = cmd.runCommand(projectRoot)
 | 
			
		||||
        return File(out)
 | 
			
		||||
        return File((out ?: "").trim())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun log(fname : File) : List<Pair<String, Diff>> {
 | 
			
		||||
        val cmd = listOf(
 | 
			
		||||
            git_exe,
 | 
			
		||||
            "--no-pager",
 | 
			
		||||
            "log",
 | 
			
		||||
            "-z", // Null byte separate log entries
 | 
			
		||||
            "-w", // Ignore all whitespace
 | 
			
		||||
@@ -58,7 +59,7 @@ class GitRepo(val projectRoot : File, val git_exe : String) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun parseAuthor(header : List<String>) : String {
 | 
			
		||||
        val segs = header.getOrNull(1)?.trim()?.split("\\s+")?: listOf()
 | 
			
		||||
        val segs = header.getOrNull(1)?.trim()?.split("\\s+".toRegex())?: listOf()
 | 
			
		||||
        return segs.subList(1, segs.size - 2).joinToString(" ")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ fun List<String>.runCommand(workingDir: File): Pair<String?,String?> {
 | 
			
		||||
                .redirectError(ProcessBuilder.Redirect.PIPE)
 | 
			
		||||
                .start()
 | 
			
		||||
 | 
			
		||||
        proc.waitFor(60, TimeUnit.MINUTES)
 | 
			
		||||
        proc.waitFor(5, TimeUnit.SECONDS)
 | 
			
		||||
        return Pair(proc.inputStream.bufferedReader().readText(),
 | 
			
		||||
                    proc.errorStream.bufferedReader().readText())
 | 
			
		||||
    } catch(e: IOException) {
 | 
			
		||||
 
 | 
			
		||||
@@ -80,8 +80,8 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
 | 
			
		||||
        LineKnowledge.select {
 | 
			
		||||
            LineKnowledge.linenum eq lineNum
 | 
			
		||||
        }.map {
 | 
			
		||||
            Pair(getKnowledgeAcct(it[LineKnowledge.knowledgeacctid]).authors,
 | 
			
		||||
                 it[LineKnowledge.knowledge])
 | 
			
		||||
            val acct = getKnowledgeAcct(it[LineKnowledge.knowledgeacctid])
 | 
			
		||||
            Pair(acct.authors, it[LineKnowledge.knowledge])
 | 
			
		||||
        }.sortedBy {
 | 
			
		||||
            it.first.joinToString("\n")
 | 
			
		||||
        }.copyOf()
 | 
			
		||||
@@ -95,7 +95,7 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun getKnowledgeAcct(knowledgeAcctId : Int) = transaction(db) {
 | 
			
		||||
    private fun getKnowledgeAcct(knowledgeAcctId : Int) : KnowledgeAcct = transaction(db) {
 | 
			
		||||
        KnowledgeAcctsTable.select {
 | 
			
		||||
            KnowledgeAcctsTable.id eq knowledgeAcctId
 | 
			
		||||
        }.map {
 | 
			
		||||
@@ -104,7 +104,7 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
 | 
			
		||||
                it[KnowledgeAcctsTable.authors].split("\n"),
 | 
			
		||||
                it[KnowledgeAcctsTable.authors]
 | 
			
		||||
            )
 | 
			
		||||
        }.first()
 | 
			
		||||
        }.firstOrNull() ?: KnowledgeAcct(-1, listOf(), "")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun destroyLineKnowledge(knowledgeId : Int, lineNum : Int) = transaction(db) {
 | 
			
		||||
@@ -194,9 +194,9 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
 | 
			
		||||
        val authorStr = authors.sorted().joinToString("\n")
 | 
			
		||||
        var newId = KnowledgeAcctsTable.select {
 | 
			
		||||
            KnowledgeAcctsTable.authors eq authorStr
 | 
			
		||||
        }.first().let {
 | 
			
		||||
        }.map {
 | 
			
		||||
            it[KnowledgeAcctsTable.id]
 | 
			
		||||
        }
 | 
			
		||||
        }.firstOrNull() ?: -1
 | 
			
		||||
        if (newId != -1) {
 | 
			
		||||
            KnowledgeAcctsTable.insert { 
 | 
			
		||||
                it[KnowledgeAcctsTable.authors] = authorStr
 | 
			
		||||
@@ -231,12 +231,14 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
 | 
			
		||||
    private fun totalLineKnowledge(linenum : Int) = transaction(db) {
 | 
			
		||||
        LineKnowledge.select {
 | 
			
		||||
            LineKnowledge.linenum eq linenum
 | 
			
		||||
        }.first().let {
 | 
			
		||||
        }.map {
 | 
			
		||||
            it[LineKnowledge.knowledge]
 | 
			
		||||
        }
 | 
			
		||||
        }.firstOrNull() ?: 0.0
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun createTables() = transaction(db) {
 | 
			
		||||
        println ("-- In create tables")
 | 
			
		||||
        SchemaUtils.dropDatabase()
 | 
			
		||||
        SchemaUtils.createMissingTablesAndColumns(AuthorsTable, KnowledgeAcctsTable, KnowledgeAuthorsTable, LineKnowledge)
 | 
			
		||||
        AuthorsTable.insertIgnore { 
 | 
			
		||||
            it[id] = 1
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
package me.msoucy.gbat.models
 | 
			
		||||
 | 
			
		||||
import java.io.File
 | 
			
		||||
 | 
			
		||||
enum class ChangeType {
 | 
			
		||||
    Add, Change, Remove
 | 
			
		||||
}
 | 
			
		||||
@@ -34,8 +36,8 @@ data class Condensation(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class CondensedAnalysis(
 | 
			
		||||
    var repoRoot : String = "",
 | 
			
		||||
    var projectRoot : String = "",
 | 
			
		||||
    var fileName : String = "",
 | 
			
		||||
    var repoRoot : File,
 | 
			
		||||
    var projectRoot : File,
 | 
			
		||||
    var fileName : File,
 | 
			
		||||
    var lineSummaries : MutableList<Pair<String, List<Condensation>>> = mutableListOf()
 | 
			
		||||
)
 | 
			
		||||
@@ -26,7 +26,7 @@ class RiskModel(val threshold : Double,
 | 
			
		||||
    fun isDeparted(author : String) = author.trim() in departed
 | 
			
		||||
 | 
			
		||||
    fun jointBusProb(authors : List<String>) =
 | 
			
		||||
        authors.map { this[it] }.reduce { a, b -> a * b }
 | 
			
		||||
        (authors.map { this[it] } + 1.0).reduce { a, b -> a * b }
 | 
			
		||||
 | 
			
		||||
    fun jointBusProbBelowThreshold(authors : List<String>) =
 | 
			
		||||
        jointBusProb(authors) <= threshold
 | 
			
		||||
 
 | 
			
		||||
@@ -97,8 +97,10 @@ class SummaryModel(val db : Database) {
 | 
			
		||||
    private val allJoined = (manyJoined leftJoin AuthorsGroupsTable)
 | 
			
		||||
 | 
			
		||||
    fun summarize(ca : CondensedAnalysis) {
 | 
			
		||||
        val fname = adjustFname(File(ca.repoRoot), File(ca.projectRoot), File(ca.fileName))
 | 
			
		||||
        val projectId = findOrCreateProject(ca.projectRoot)
 | 
			
		||||
        val fname = adjustFname(ca.repoRoot.absoluteFile,
 | 
			
		||||
                                ca.projectRoot.absoluteFile,
 | 
			
		||||
                                ca.fileName.absoluteFile)
 | 
			
		||||
        val projectId = findOrCreateProject(ca.projectRoot.absolutePath)
 | 
			
		||||
 | 
			
		||||
        var parentDirId = 0
 | 
			
		||||
        splitAllDirs(fname.parentFile).forEach {
 | 
			
		||||
@@ -404,7 +406,11 @@ class SummaryModel(val db : Database) {
 | 
			
		||||
    private fun splitAllDirs(dirname : File) = dirname.toPath().iterator().asSequence().toList()
 | 
			
		||||
 | 
			
		||||
    private fun adjustFname(repoRoot : File, projectRoot : File, fname : File) : File {
 | 
			
		||||
        var rootDiff = projectRoot.relativeTo(repoRoot)
 | 
			
		||||
        val rootDiff = if(projectRoot.canonicalPath != repoRoot.canonicalPath) {
 | 
			
		||||
            projectRoot.relativeTo(repoRoot)
 | 
			
		||||
        } else {
 | 
			
		||||
            repoRoot
 | 
			
		||||
        }
 | 
			
		||||
        return if(rootDiff.toString().length != 0) {
 | 
			
		||||
            fname.relativeTo(rootDiff)
 | 
			
		||||
        } else {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user