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