Compare commits
No commits in common. "d638b98d1adc11a3cca402820a1ff279b5131875" and "1997df3da92d3e0d3a7f6c587c10c6debac5e1a1" have entirely different histories.
d638b98d1a
...
1997df3da9
10
build.gradle
10
build.gradle
@ -7,21 +7,15 @@ buildscript {
|
|||||||
dependencies {
|
dependencies {
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
|
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
|
||||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
|
||||||
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.21'
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
apply plugin: 'kotlinx-serialization'
|
|
||||||
apply plugin: "com.github.johnrengelman.shadow"
|
apply plugin: "com.github.johnrengelman.shadow"
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
|
|
||||||
@ -49,15 +43,13 @@ dependencies {
|
|||||||
compile 'org.jetbrains.exposed:exposed-jdbc:0.33.1'
|
compile 'org.jetbrains.exposed:exposed-jdbc:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-java-time:0.33.1'
|
compile 'org.jetbrains.exposed:exposed-java-time:0.33.1'
|
||||||
compile 'com.zaxxer:HikariCP:5.0.0'
|
compile 'com.zaxxer:HikariCP:5.0.0'
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
|
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.2.1"
|
|
||||||
implementation "io.insert-koin:koin-core:$koin_version"
|
implementation "io.insert-koin:koin-core:$koin_version"
|
||||||
implementation "io.insert-koin:koin-ktor:$koin_version"
|
implementation "io.insert-koin:koin-ktor:$koin_version"
|
||||||
implementation "io.ktor:ktor-serialization:$ktor_version"
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation "io.ktor:ktor-server-netty:$ktor_version"
|
implementation "io.ktor:ktor-server-netty:$ktor_version"
|
||||||
implementation "ch.qos.logback:logback-classic:$logback_version"
|
implementation "ch.qos.logback:logback-classic:$logback_version"
|
||||||
implementation "io.ktor:ktor-server-core:$ktor_version"
|
implementation "io.ktor:ktor-server-core:$ktor_version"
|
||||||
|
implementation "io.ktor:ktor-gson:$ktor_version"
|
||||||
implementation "io.ktor:ktor-server-host-common:$ktor_version"
|
implementation "io.ktor:ktor-server-host-common:$ktor_version"
|
||||||
implementation "io.ktor:ktor-client-core:$ktor_version"
|
implementation "io.ktor:ktor-client-core:$ktor_version"
|
||||||
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
|
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
|
||||||
|
@ -5,11 +5,11 @@ import io.ktor.application.*
|
|||||||
import io.ktor.response.*
|
import io.ktor.response.*
|
||||||
import io.ktor.routing.*
|
import io.ktor.routing.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
|
import io.ktor.gson.*
|
||||||
import io.ktor.features.*
|
import io.ktor.features.*
|
||||||
import org.apache.http.HttpException
|
import org.apache.http.HttpException
|
||||||
import com.kmalbz.database.DatabaseFactory
|
import com.kmalbz.database.DatabaseFactory
|
||||||
import com.kmalbz.database.dao.ResultObjects
|
import com.kmalbz.database.dao.ResultObjects
|
||||||
import io.ktor.serialization.*
|
|
||||||
import io.ktor.util.KtorExperimentalAPI
|
import io.ktor.util.KtorExperimentalAPI
|
||||||
import org.jetbrains.exposed.sql.SchemaUtils
|
import org.jetbrains.exposed.sql.SchemaUtils
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
@ -21,7 +21,8 @@ fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
|||||||
@Suppress("unused") // Referenced in application.conf
|
@Suppress("unused") // Referenced in application.conf
|
||||||
fun Application.module() {
|
fun Application.module() {
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
json()
|
gson {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
install(Koin) {
|
install(Koin) {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.kmalbz.api.model
|
package com.kmalbz.api.model
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import com.google.gson.annotations.SerializedName
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class ApiObject(
|
data class ApiObject(
|
||||||
val tag: String,
|
@SerializedName("tag") val tag: String,
|
||||||
val probability: Double
|
@SerializedName("probability") val probability: Double
|
||||||
)
|
)
|
@ -6,9 +6,11 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Routing
|
import io.ktor.routing.Routing
|
||||||
import io.ktor.routing.get
|
import io.ktor.routing.get
|
||||||
import kotlinx.datetime.LocalDateTime
|
|
||||||
import org.koin.ktor.ext.inject
|
import org.koin.ktor.ext.inject
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output Service - RDB
|
* Output Service - RDB
|
||||||
@ -38,39 +40,41 @@ class OutputServiceRDBServer {
|
|||||||
|
|
||||||
get("/output/filter/negative") {
|
get("/output/filter/negative") {
|
||||||
val resultList =
|
val resultList =
|
||||||
resultObjectService.getResultObjecLessthanProbability(0.5)
|
resultObjectService.getResultObjecLessthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/filter/positive") {
|
get("/output/filter/positive") {
|
||||||
val resultList =
|
val resultList =
|
||||||
resultObjectService.getResultObjecGreaterthanProbability(0.5)
|
resultObjectService.getResultObjecGreaterthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/filter/undecided") {
|
get("/output/filter/undecided") {
|
||||||
val resultList =
|
val resultList =
|
||||||
resultObjectService.getResultObjecEqualsProbability(0.5)
|
resultObjectService.getResultObjecEqualsProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/after/{dateAfter}") {
|
get("/output/after/{dateAfter}") {
|
||||||
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val localDateAfter: LocalDateTime = LocalDateTime.parse(dateAfter)
|
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
||||||
|
val localDateAfter: LocalDate = LocalDate.parse(dateAfter, dateTimeFormatter)
|
||||||
val resultList =
|
val resultList =
|
||||||
resultObjectService.getResultObjectafterDate(localDateAfter)
|
resultObjectService.getResultObjectafterDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/before/{dateBefore}") {
|
get("/output/before/{dateBefore}") {
|
||||||
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val localDateBefore: LocalDateTime = LocalDateTime.parse(dateAfter)
|
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
||||||
|
val localDateBefore: LocalDate = LocalDate.parse(dateAfter, dateTimeFormatter)
|
||||||
val resultList =
|
val resultList =
|
||||||
resultObjectService.getResultObjectbeforeDate(localDateBefore)
|
resultObjectService.getResultObjectbeforeDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ package com.kmalbz.database.dao
|
|||||||
|
|
||||||
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.`java-time`.datetime
|
import org.jetbrains.exposed.sql.`java-time`.date
|
||||||
import java.time.LocalDateTime
|
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<LocalDateTime> = datetime("date").default(LocalDateTime.now())
|
val date: Column<LocalDate> = date("date").default(LocalDate.now())
|
||||||
val probability: Column<Double> = double("probability")
|
val probability: Column<Double> = double("probability")
|
||||||
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")
|
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")
|
||||||
}
|
}
|
@ -1,7 +1,8 @@
|
|||||||
package com.kmalbz.database.service
|
package com.kmalbz.database.service
|
||||||
|
|
||||||
import com.kmalbz.api.model.ApiObject
|
import com.kmalbz.api.model.ApiObject
|
||||||
import kotlinx.datetime.LocalDateTime
|
import java.time.LocalDate
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
interface IResultObjectService{
|
interface IResultObjectService{
|
||||||
fun addOne(apiObject: ApiObject)
|
fun addOne(apiObject: ApiObject)
|
||||||
@ -9,10 +10,10 @@ interface IResultObjectService{
|
|||||||
suspend fun getCount(): Long
|
suspend fun getCount(): Long
|
||||||
suspend fun getPage(page: Long): List<ApiObject>
|
suspend fun getPage(page: Long): List<ApiObject>
|
||||||
suspend fun getResultObjectbyTag(tag: String): ApiObject?
|
suspend fun getResultObjectbyTag(tag: String): ApiObject?
|
||||||
suspend fun getResultObjectbyDate(date: LocalDateTime): List<ApiObject>
|
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>?
|
||||||
suspend fun getResultObjectbeforeDate(date: LocalDateTime): List<ApiObject>
|
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>?
|
||||||
suspend fun getResultObjectafterDate(date: LocalDateTime): List<ApiObject>
|
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>?
|
||||||
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>
|
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>?
|
||||||
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>
|
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>?
|
||||||
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>
|
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>?
|
||||||
}
|
}
|
@ -4,12 +4,12 @@ import com.kmalbz.database.DatabaseFactory.dbQuery
|
|||||||
import com.kmalbz.database.model.ResultObject
|
import com.kmalbz.database.model.ResultObject
|
||||||
import com.kmalbz.database.dao.ResultObjects
|
import com.kmalbz.database.dao.ResultObjects
|
||||||
import com.kmalbz.api.model.ApiObject
|
import com.kmalbz.api.model.ApiObject
|
||||||
import kotlinx.datetime.LocalDateTime
|
|
||||||
import kotlinx.datetime.toJavaLocalDateTime
|
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
import org.jetbrains.exposed.sql.select
|
import org.jetbrains.exposed.sql.select
|
||||||
import org.jetbrains.exposed.sql.selectAll
|
import org.jetbrains.exposed.sql.selectAll
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
class ResultObjectService : IResultObjectService {
|
class ResultObjectService : IResultObjectService {
|
||||||
@ -42,37 +42,37 @@ class ResultObjectService : IResultObjectService {
|
|||||||
.singleOrNull()
|
.singleOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjectbyDate(date: LocalDateTime): List<ApiObject> = dbQuery {
|
override suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date eq date.toJavaLocalDateTime())
|
(ResultObjects.date eq date)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjectbeforeDate(date: LocalDateTime): List<ApiObject> = dbQuery {
|
override suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date less date.toJavaLocalDateTime())
|
(ResultObjects.date less date)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjectafterDate(date: LocalDateTime): List<ApiObject> = dbQuery {
|
override suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date greater date.toJavaLocalDateTime())
|
(ResultObjects.date greater date)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject> = dbQuery {
|
override suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.probability greater probability)
|
(ResultObjects.probability greater probability)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject> = dbQuery {
|
override suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.probability less probability)
|
(ResultObjects.probability less probability)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject> = dbQuery {
|
override suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.probability eq probability)
|
(ResultObjects.probability eq probability)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
|
Loading…
Reference in New Issue
Block a user