Formatting

This commit is contained in:
Matt Soucy 2020-08-18 21:01:00 -04:00
parent b85099fbbd
commit 1159b87a53
10 changed files with 240 additions and 258 deletions

View File

@ -1,14 +1,13 @@
package me.msoucy.gbat package me.msoucy.gbat
import java.io.File import java.io.File
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
import me.msoucy.gbat.models.CondensedAnalysis
import me.msoucy.gbat.models.Condensation import me.msoucy.gbat.models.Condensation
import me.msoucy.gbat.models.CondensedAnalysis
import me.msoucy.gbat.models.KnowledgeModel import me.msoucy.gbat.models.KnowledgeModel
import me.msoucy.gbat.models.LineModel import me.msoucy.gbat.models.LineModel
import me.msoucy.gbat.models.RiskModel import me.msoucy.gbat.models.RiskModel
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
fun analyze( fun analyze(
riskModel: RiskModel, riskModel: RiskModel,
@ -26,7 +25,7 @@ fun analyze(
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 ?: "") lineModel.apply(change.eventType, change.lineNum, change.lineVal ?: "")
knowledgeModel.apply(change.eventType, author, change.lineNum) knowledgeModel.apply(change.eventType, author, change.lineNum)

View File

@ -1,10 +1,10 @@
package me.msoucy.gbat package me.msoucy.gbat
import me.msoucy.gbat.models.RiskModel import com.xenomachina.argparser.ArgParser
import me.msoucy.gbat.models.SummaryModel import com.xenomachina.argparser.InvalidArgumentException
import com.xenomachina.argparser.default
import com.xenomachina.argparser.mainBody
import java.io.File import java.io.File
import java.util.concurrent.Executors
import kotlin.math.pow import kotlin.math.pow
import kotlin.system.exitProcess import kotlin.system.exitProcess
import kotlin.text.Regex import kotlin.text.Regex
@ -12,14 +12,9 @@ import kotlin.text.RegexOption
import kotlin.text.startsWith import kotlin.text.startsWith
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
import me.msoucy.gbat.models.RiskModel
import com.xenomachina.argparser.ArgParser import me.msoucy.gbat.models.SummaryModel
import com.xenomachina.argparser.InvalidArgumentException
import com.xenomachina.argparser.default
import com.xenomachina.argparser.mainBody
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
val REALLY_LONG_TIME = 864000 val REALLY_LONG_TIME = 864000
val DEFAULT_INTERESTING_RES = mutableListOf( val DEFAULT_INTERESTING_RES = mutableListOf(
@ -136,13 +131,8 @@ 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")
dbFname.delete(); dbFname.delete()
val summaryDb = Database.connect("jdbc:sqlite:${dbFname.absolutePath}", driver = "org.sqlite.JDBC") val summaryDb = Database.connect("jdbc:sqlite:${dbFname.absolutePath}", driver = "org.sqlite.JDBC")
transaction(summaryDb) {
addLogger(StdOutSqlLogger)
// exec("PRAGMA journal_mode = OFF")
// exec("PRAGMA synchronous = OFF")
}
val summaryModel = SummaryModel(summaryDb) val summaryModel = SummaryModel(summaryDb)
runBlocking { runBlocking {
@ -160,6 +150,6 @@ fun main(args: Array<String>) = mainBody {
renderSummary(projectRootFile, summaryModel, outDir) renderSummary(projectRootFile, summaryModel, outDir)
// Render summary // Render summary
System.err.println("Done, summary is in ${outDir}/index.html") System.err.println("Done, summary is in $outDir/index.html")
} }
} }

View File

@ -3,7 +3,6 @@ package me.msoucy.gbat
import java.io.File import java.io.File
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.max import kotlin.math.max
import me.msoucy.gbat.models.ChangeType import me.msoucy.gbat.models.ChangeType
import me.msoucy.gbat.models.Event import me.msoucy.gbat.models.Event
@ -14,14 +13,16 @@ data class HistoryItem(
val authorDiffs: List<Pair<String, List<Event>>> val authorDiffs: List<Pair<String, List<Event>>>
) )
fun parseHistory(repo : GitRepo, fun parseHistory(
repo: GitRepo,
projectRoot: File, projectRoot: File,
fname: File, fname: File,
verbose : Boolean = false) : HistoryItem { verbose: Boolean = false
): HistoryItem {
val entries = repo.log(fname) val entries = repo.log(fname)
val repoRoot = repo.root() val repoRoot = repo.root()
if (verbose) { if (verbose) {
System.err.println("Parsing history for ${fname}") System.err.println("Parsing history for $fname")
} }
return HistoryItem(repoRoot, projectRoot, fname, return HistoryItem(repoRoot, projectRoot, fname,
entries.map { (author, diff) -> entries.map { (author, diff) ->

View File

@ -1,20 +1,18 @@
package me.msoucy.gbat.models package me.msoucy.gbat.models
import java.io.File import me.msoucy.gbat.copyOf
import java.nio.file.Path import me.msoucy.gbat.mutableCopyOf
import java.nio.file.Paths
import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import me.msoucy.gbat.copyOf
import me.msoucy.gbat.mutableCopyOf
class KnowledgeModel(val db: Database, val constant: Double, val riskModel: RiskModel) { class KnowledgeModel(val db: Database, val constant: Double, val riskModel: RiskModel) {
class KnowledgeAcct(var knowledgeAcctId : Int, class KnowledgeAcct(
var knowledgeAcctId: Int,
var authors: List<String>, var authors: List<String>,
var authorsStr : String) var authorsStr: String
)
object AuthorsTable : IntIdTable("authors", "authorid") { object AuthorsTable : IntIdTable("authors", "authorid") {
val author = text("author").uniqueIndex("authors_idx") val author = text("author").uniqueIndex("authors_idx")

View File

@ -1,13 +1,5 @@
package me.msoucy.gbat.models package me.msoucy.gbat.models
import java.io.File
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.forEachLine
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
class LineModel() { class LineModel() {
inner class Line(var num: Int, var text: String) inner class Line(var num: Int, var text: String)
val model = mutableSetOf<Line>() val model = mutableSetOf<Line>()

View File

@ -3,10 +3,12 @@ package me.msoucy.gbat.models
import java.io.File import java.io.File
import kotlin.io.forEachLine import kotlin.io.forEachLine
class RiskModel(val threshold : Double, class RiskModel(
val threshold: Double,
val default: Double, val default: Double,
val busRiskFile: File?, val busRiskFile: File?,
val departedFile : File?) { val departedFile: File?
) {
val departed = mutableSetOf<String>() val departed = mutableSetOf<String>()
val risks = mutableMapOf<String, Double>().withDefault { default } val risks = mutableMapOf<String, Double>().withDefault { default }