Fix authors
This commit is contained in:
parent
6569ec619a
commit
b85099fbbd
@ -16,15 +16,11 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
|
|||||||
var authors : List<String>,
|
var authors : List<String>,
|
||||||
var authorsStr : String)
|
var authorsStr : String)
|
||||||
|
|
||||||
object AuthorsTable : Table("authors") {
|
object AuthorsTable : IntIdTable("authors", "authorid") {
|
||||||
val id = integer("authorid")
|
|
||||||
val author = text("author").uniqueIndex("authors_idx")
|
val author = text("author").uniqueIndex("authors_idx")
|
||||||
override val primaryKey = PrimaryKey(id)
|
|
||||||
}
|
}
|
||||||
object KnowledgeAcctsTable : Table("knowledgeaccts") {
|
object KnowledgeAcctsTable : IntIdTable("knowledgeaccts", "knowledgeacctid") {
|
||||||
val id = integer("knowledgeacctid")
|
|
||||||
val authors = text("authors").uniqueIndex("knowledgeacctsauthors_idx")
|
val authors = text("authors").uniqueIndex("knowledgeacctsauthors_idx")
|
||||||
override val primaryKey = PrimaryKey(id)
|
|
||||||
}
|
}
|
||||||
object KnowledgeAuthorsTable : Table("knowedgeaccts_authors") {
|
object KnowledgeAuthorsTable : Table("knowedgeaccts_authors") {
|
||||||
val knowledgeacctid = integer("knowledgeacctid")
|
val knowledgeacctid = integer("knowledgeacctid")
|
||||||
@ -33,7 +29,7 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
|
|||||||
}
|
}
|
||||||
object LineKnowledge : Table("lineknowledge") {
|
object LineKnowledge : Table("lineknowledge") {
|
||||||
val linenum = integer("linenum")
|
val linenum = integer("linenum")
|
||||||
val knowledgeacctid = integer("knowledgeacctid")
|
val knowledgeacctid = integer("knowledgeacctid").references(KnowledgeAuthorsTable.knowledgeacctid)
|
||||||
val knowledge = double("knowledge")
|
val knowledge = double("knowledge")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +96,7 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
|
|||||||
KnowledgeAcctsTable.id eq knowledgeAcctId
|
KnowledgeAcctsTable.id eq knowledgeAcctId
|
||||||
}.map {
|
}.map {
|
||||||
KnowledgeAcct(
|
KnowledgeAcct(
|
||||||
it[KnowledgeAcctsTable.id],
|
it[KnowledgeAcctsTable.id].value,
|
||||||
it[KnowledgeAcctsTable.authors].split("\n"),
|
it[KnowledgeAcctsTable.authors].split("\n"),
|
||||||
it[KnowledgeAcctsTable.authors]
|
it[KnowledgeAcctsTable.authors]
|
||||||
)
|
)
|
||||||
@ -192,29 +188,28 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
|
|||||||
|
|
||||||
private fun lookupOrCreateKnowledgeAcct(authors : List<String>) = transaction(db) {
|
private fun lookupOrCreateKnowledgeAcct(authors : List<String>) = transaction(db) {
|
||||||
val authorStr = authors.sorted().joinToString("\n")
|
val authorStr = authors.sorted().joinToString("\n")
|
||||||
var newId = KnowledgeAcctsTable.select {
|
KnowledgeAcctsTable.select {
|
||||||
KnowledgeAcctsTable.authors eq authorStr
|
KnowledgeAcctsTable.authors eq authorStr
|
||||||
}.map {
|
}.map {
|
||||||
it[KnowledgeAcctsTable.id]
|
it[KnowledgeAcctsTable.id].value
|
||||||
}.firstOrNull() ?: -1
|
}.firstOrNull() ?: run {
|
||||||
if (newId != -1) {
|
|
||||||
KnowledgeAcctsTable.insert {
|
KnowledgeAcctsTable.insert {
|
||||||
it[KnowledgeAcctsTable.authors] = authorStr
|
it[KnowledgeAcctsTable.authors] = authorStr
|
||||||
}
|
}
|
||||||
newId = KnowledgeAcctsTable.select {
|
val theNewId = KnowledgeAcctsTable.select {
|
||||||
KnowledgeAcctsTable.authors eq authorStr
|
KnowledgeAcctsTable.authors eq authorStr
|
||||||
}.map {
|
}.map {
|
||||||
it[KnowledgeAcctsTable.id]
|
it[KnowledgeAcctsTable.id].value
|
||||||
}.first()
|
}.first()
|
||||||
|
|
||||||
authors.map(::lookupOrCreateAuthor).forEach { authorId ->
|
authors.map(::lookupOrCreateAuthor).forEach { authorId ->
|
||||||
KnowledgeAuthorsTable.insert {
|
KnowledgeAuthorsTable.insert {
|
||||||
it[KnowledgeAuthorsTable.knowledgeacctid] = newId
|
it[KnowledgeAuthorsTable.knowledgeacctid] = theNewId
|
||||||
it[KnowledgeAuthorsTable.authorid] = authorId
|
it[KnowledgeAuthorsTable.authorid] = authorId.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
theNewId
|
||||||
}
|
}
|
||||||
newId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun lookupOrCreateAuthor(authorName : String) = transaction(db) {
|
private fun lookupOrCreateAuthor(authorName : String) = transaction(db) {
|
||||||
@ -240,11 +235,9 @@ class KnowledgeModel(val db : Database, val constant : Double, val riskModel : R
|
|||||||
SchemaUtils.dropDatabase()
|
SchemaUtils.dropDatabase()
|
||||||
SchemaUtils.createMissingTablesAndColumns(AuthorsTable, KnowledgeAcctsTable, KnowledgeAuthorsTable, LineKnowledge)
|
SchemaUtils.createMissingTablesAndColumns(AuthorsTable, KnowledgeAcctsTable, KnowledgeAuthorsTable, LineKnowledge)
|
||||||
AuthorsTable.insertIgnore {
|
AuthorsTable.insertIgnore {
|
||||||
it[id] = 1
|
|
||||||
it[author] = ""
|
it[author] = ""
|
||||||
}
|
}
|
||||||
KnowledgeAcctsTable.insertIgnore {
|
KnowledgeAcctsTable.insertIgnore {
|
||||||
it[id] = 1
|
|
||||||
it[authors] = ""
|
it[authors] = ""
|
||||||
}
|
}
|
||||||
KnowledgeAuthorsTable.insertIgnore {
|
KnowledgeAuthorsTable.insertIgnore {
|
||||||
|
@ -387,7 +387,7 @@ class SummaryModel(val db : Database) {
|
|||||||
AuthorsTable.insertIgnore {
|
AuthorsTable.insertIgnore {
|
||||||
it[AuthorsTable.author] = author
|
it[AuthorsTable.author] = author
|
||||||
}
|
}
|
||||||
ProjectTable.select {
|
AuthorsTable.select {
|
||||||
AuthorsTable.author eq author
|
AuthorsTable.author eq author
|
||||||
}.map {
|
}.map {
|
||||||
it[AuthorsTable.id].value
|
it[AuthorsTable.id].value
|
||||||
|
Loading…
Reference in New Issue
Block a user