From e94b2e1d4b374517b0fed753f0dfe19346638ecf Mon Sep 17 00:00:00 2001 From: Matt Soucy Date: Fri, 3 Jul 2020 18:47:10 -0400 Subject: [PATCH] Fixes --- src/main/kotlin/me/msoucy/gbat/Main.kt | 1 + .../kotlin/me/msoucy/gbat/ParseHistory.kt | 16 ++++++++++++- src/main/kotlin/me/msoucy/gbat/Repo.kt | 2 +- .../me/msoucy/gbat/models/SummaryModel.kt | 24 ++++++++++++------- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/me/msoucy/gbat/Main.kt b/src/main/kotlin/me/msoucy/gbat/Main.kt index d677689..80ecf43 100644 --- a/src/main/kotlin/me/msoucy/gbat/Main.kt +++ b/src/main/kotlin/me/msoucy/gbat/Main.kt @@ -136,6 +136,7 @@ fun main(args: Array) = mainBody { val riskModel = RiskModel(riskThresh, default_bus_risk, risk_file, departed) val dbFname = File(outDir, "summary.db") + dbFname.delete(); val summaryDb = Database.connect("jdbc:sqlite:${dbFname.absolutePath}", driver="org.sqlite.JDBC") transaction(summaryDb) { addLogger(StdOutSqlLogger) diff --git a/src/main/kotlin/me/msoucy/gbat/ParseHistory.kt b/src/main/kotlin/me/msoucy/gbat/ParseHistory.kt index d32ccf6..730ddbd 100644 --- a/src/main/kotlin/me/msoucy/gbat/ParseHistory.kt +++ b/src/main/kotlin/me/msoucy/gbat/ParseHistory.kt @@ -98,13 +98,27 @@ fun diffWalk(diff : Diff) : List { val maxLen = max(oldLen, newLen) var lineNum = hunk.lineNum - for (i in 0..maxLen) { + for (i in 0 until maxLen) { if(i < oldLen && i < newLen) { events += Event( ChangeType.Change, lineNum, hunk.newLines[i].substring(1) ) + lineNum++ + } else if(i < oldLen) { + events += Event( + ChangeType.Remove, + lineNum, + null + ) + } else { + events += Event( + ChangeType.Add, + lineNum, + hunk.newLines[i].substring(1) + ) + lineNum++ } } } diff --git a/src/main/kotlin/me/msoucy/gbat/Repo.kt b/src/main/kotlin/me/msoucy/gbat/Repo.kt index d90d6d2..328781f 100644 --- a/src/main/kotlin/me/msoucy/gbat/Repo.kt +++ b/src/main/kotlin/me/msoucy/gbat/Repo.kt @@ -60,7 +60,7 @@ class GitRepo(val projectRoot : File, val git_exe : String) { private fun parseAuthor(header : List) : String { val segs = header.getOrNull(1)?.trim()?.split("\\s+".toRegex())?: listOf() - return segs.subList(1, segs.size - 2).joinToString(" ") + return segs.subList(1, segs.size - 1).joinToString(" ") } private fun splitEntryHeader(entry : String) : Pair, List> { diff --git a/src/main/kotlin/me/msoucy/gbat/models/SummaryModel.kt b/src/main/kotlin/me/msoucy/gbat/models/SummaryModel.kt index d239242..01ab595 100644 --- a/src/main/kotlin/me/msoucy/gbat/models/SummaryModel.kt +++ b/src/main/kotlin/me/msoucy/gbat/models/SummaryModel.kt @@ -267,7 +267,9 @@ class SummaryModel(val db : Database) { fun fileSummary(fileId : Int) = transaction(db) { var fileTree = FileTree() - lineAllocationGroups.select { + lineAllocationGroups + .slice(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum(), AuthorsGroupsTable.authors) + .select { LinesTable.fileid eq fileId }.groupBy(AuthorsGroupsTable.id).forEach { row -> val authors = row[AuthorsGroupsTable.authors] @@ -276,7 +278,9 @@ class SummaryModel(val db : Database) { Join(lineAllocations, FilesTable, JoinType.LEFT, LinesTable.fileid, FilesTable.id - ).select { LinesTable.fileid eq fileId } + ) + .slice(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum()) + .select { LinesTable.fileid eq fileId } .first().let { row -> fileTree.stats = Statistics(row) } @@ -287,13 +291,17 @@ class SummaryModel(val db : Database) { .map { it[LinesTable.id].value } .forEach { lineId -> val lineDict = LineDict() - lineAllocationGroups.select { + lineAllocationGroups + .slice(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum(), AuthorsGroupsTable.authors) + .select { LinesTable.id eq lineId }.groupBy(AuthorsGroupsTable.id).forEach { lineRow -> lineDict.authorRisks[lineRow[AuthorsGroupsTable.authors]] = Statistics(lineRow) } - lineAllocations.select { + lineAllocations + .slice(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum()) + .select { LinesTable.id eq lineId }.first().let { lineDict.stats = Statistics(it) @@ -313,7 +321,7 @@ class SummaryModel(val db : Database) { private fun transformNode(tree : MutableMap, dirId : Int) : ProjectTreeNode { val result = ProjectTreeNode() - tree[dirId]?.let {dirdict -> + tree[dirId]?.let { dirdict -> result.dirs = mutableListOf().apply { dirdict.dirs.forEach { add(transformNode(tree, it)) @@ -412,7 +420,7 @@ class SummaryModel(val db : Database) { } private fun findOrCreateDir(dirname : String, projectId : Int, parentDirId : Int) : Int = transaction(db) { - DirsTable.insertIgnoreAndGetId { + DirsTable.insertIgnore { it[dir] = dirname it[parentdirid] = parentDirId it[projectid] = projectId @@ -422,8 +430,8 @@ class SummaryModel(val db : Database) { DirsTable.parentdirid eq parentDirId DirsTable.projectid eq projectId }.map { - it[DirsTable.id] - }.first().value + it[DirsTable.id].value + }.first() } private fun splitAllDirs(dirname : File) = dirname.toPath().iterator().asSequence().toList()