This commit is contained in:
Matt Soucy 2020-07-03 18:47:10 -04:00
parent 2b4d799d4a
commit e94b2e1d4b
4 changed files with 33 additions and 10 deletions

View File

@ -136,6 +136,7 @@ fun main(args: Array<String>) = 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)

View File

@ -98,13 +98,27 @@ fun diffWalk(diff : Diff) : List<Event> {
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++
}
}
}

View File

@ -60,7 +60,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+".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<String>, List<String>> {

View File

@ -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)
@ -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()