refactor api
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Torma Kristóf 2020-04-08 03:09:24 +02:00
parent f4ce568aa8
commit 928c9888dd
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
5 changed files with 29 additions and 19 deletions

View File

@ -5,7 +5,5 @@ import java.time.LocalDate
data class ApiObject(
@SerializedName("tag") val tag: String,
@SerializedName("date") val date: LocalDate,
@SerializedName("decision") val decision: Boolean,
@SerializedName("confidence") val confidence: Double
@SerializedName("probability") val probability: Double
)

View File

@ -24,13 +24,19 @@ class OutputServiceRDBServer() {
}
get("/output/filter/negative") {
val resultList = resultObjectService.getResultObjectbyDecision(false) ?: call.respond(HttpStatusCode.NotFound)
val resultList = resultObjectService.getResultObjecLessthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}
get("/output/filter/positive") {
val resultList = resultObjectService.getResultObjectbyDecision(true) ?: call.respond(HttpStatusCode.NotFound)
val resultList = resultObjectService.getResultObjecGreaterthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}
get("/output/filter/undecided") {
val resultList = resultObjectService.getResultObjecEqualsProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}

View File

@ -7,8 +7,7 @@ import java.time.LocalDate
object ResultObjects : IntIdTable() {
val tag: Column<String> = varchar("tag",32)
val date: Column<LocalDate> = date("date")
val decision: Column<Boolean> = bool("decision")
val confidence: Column<Double> = double("confidence")
val date: Column<LocalDate> = date("date").default(LocalDate.now())
val probability: Column<Double> = double("probability")
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")
}

View File

@ -8,7 +8,6 @@ import org.jetbrains.exposed.dao.id.EntityID
class ResultObject(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<ResultObject>(ResultObjects)
var tag by ResultObjects.tag
var date by ResultObjects.tag
var decision by ResultObjects.decision
var confidence by ResultObjects.confidence
var date by ResultObjects.date
var probability by ResultObjects.probability
}

View File

@ -17,9 +17,7 @@ class ResultObjectService {
transaction {
ResultObject.new {
tag = apiObject.tag
date = apiObject.date.toString()
decision = apiObject.decision
confidence = apiObject.confidence
probability = apiObject.probability
}
}
}
@ -53,17 +51,27 @@ class ResultObjectService {
}.mapNotNull { toResultObject(it) }
}
suspend fun getResultObjectbyDecision(decision: Boolean): List<ApiObject>? = dbQuery {
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>? = dbQuery {
ResultObjects.select {
(ResultObjects.decision eq decision)
(ResultObjects.probability greater probability)
}.mapNotNull { toResultObject(it) }
}
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>? = dbQuery {
ResultObjects.select {
(ResultObjects.probability less probability)
}.mapNotNull { toResultObject(it) }
}
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>? = dbQuery {
ResultObjects.select {
(ResultObjects.probability eq probability)
}.mapNotNull { toResultObject(it) }
}
private fun toResultObject(row: ResultRow): ApiObject =
ApiObject(
tag = row[ResultObjects.tag],
date = row[ResultObjects.date],
decision = row[ResultObjects.decision],
confidence = row[ResultObjects.confidence]
probability = row[ResultObjects.probability]
)
}