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( data class ApiObject(
@SerializedName("tag") val tag: String, @SerializedName("tag") val tag: String,
@SerializedName("date") val date: LocalDate, @SerializedName("probability") val probability: Double
@SerializedName("decision") val decision: Boolean,
@SerializedName("confidence") val confidence: Double
) )

View File

@ -24,13 +24,19 @@ class OutputServiceRDBServer() {
} }
get("/output/filter/negative") { 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) call.respond(resultList)
} }
get("/output/filter/positive") { 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) call.respond(resultList)
} }

View File

@ -7,8 +7,7 @@ import java.time.LocalDate
object ResultObjects : IntIdTable() { object ResultObjects : IntIdTable() {
val tag: Column<String> = varchar("tag",32) val tag: Column<String> = varchar("tag",32)
val date: Column<LocalDate> = date("date") val date: Column<LocalDate> = date("date").default(LocalDate.now())
val decision: Column<Boolean> = bool("decision") val probability: Column<Double> = double("probability")
val confidence: Column<Double> = double("confidence")
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id") 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) { class ResultObject(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<ResultObject>(ResultObjects) companion object : IntEntityClass<ResultObject>(ResultObjects)
var tag by ResultObjects.tag var tag by ResultObjects.tag
var date by ResultObjects.tag var date by ResultObjects.date
var decision by ResultObjects.decision var probability by ResultObjects.probability
var confidence by ResultObjects.confidence
} }

View File

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