mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-04-19 17:26:51 +00:00
Fetch overall request statistic using sql query
This commit is contained in:
parent
5c6384e878
commit
ed17a803bf
@ -57,9 +57,12 @@ interface RequestRepository : CrudRepository<Request, Long> {
|
||||
|
||||
fun findByUuidEquals(uuid: String): Optional<Request>
|
||||
|
||||
@Query("SELECT count(*) AS count, status FROM request GROUP BY status ORDER BY status, count DESC;")
|
||||
fun countStates(): List<CountedState>
|
||||
|
||||
@Query("SELECT count(*) AS count, status FROM (" +
|
||||
"SELECT status, rank() OVER (PARTITION BY patient_id ORDER BY processed_at DESC) AS rank FROM request WHERE status NOT IN ('DUPLICATION')" +
|
||||
") rank WHERE rank = 1 GROUP BY status ORDER BY count DESC;")
|
||||
") rank WHERE rank = 1 GROUP BY status ORDER BY status, count DESC;")
|
||||
fun findPatientUniqueStates(): List<CountedState>
|
||||
|
||||
}
|
@ -19,10 +19,8 @@
|
||||
|
||||
package dev.dnpm.etl.processor.web
|
||||
|
||||
import dev.dnpm.etl.processor.monitoring.PatientUniqueState
|
||||
import dev.dnpm.etl.processor.monitoring.RequestRepository
|
||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.codec.ServerSentEvent
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
@ -30,13 +28,10 @@ import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Sinks
|
||||
import reactor.kotlin.core.publisher.toFlux
|
||||
import java.time.Instant
|
||||
import java.time.Month
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.time.temporal.TemporalUnit
|
||||
|
||||
@RestController
|
||||
@RequestMapping(path = ["/statistics"])
|
||||
@ -47,16 +42,15 @@ class StatisticsRestController(
|
||||
|
||||
@GetMapping(path = ["requeststates"])
|
||||
fun requestStates(): List<NameValue> {
|
||||
return requestRepository.findAll()
|
||||
.groupBy { it.status }
|
||||
return requestRepository.countStates()
|
||||
.map {
|
||||
val color = when (it.key) {
|
||||
val color = when (it.status) {
|
||||
RequestStatus.ERROR -> "red"
|
||||
RequestStatus.WARNING -> "darkorange"
|
||||
RequestStatus.SUCCESS -> "green"
|
||||
else -> "slategray"
|
||||
}
|
||||
NameValue(it.key.toString(), it.value.size, color)
|
||||
NameValue(it.status.toString(), it.count, color)
|
||||
}
|
||||
.sortedByDescending { it.value }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user