Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Pipeline version dashboard #3169

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.loculus.backend.controller

import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import org.loculus.backend.service.submission.PipelineVersionDashboardService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

data class PipelineVersionStats(
val pipelineVersion: Long,
val sequenceCount: Long,
val isCurrentVersion: Boolean
)

data class PipelineVersionDashboard(
val stats: List<PipelineVersionStats>,
val totalSequences: Long
)

@RestController
@SecurityRequirement(name = "bearerAuth")
class PipelineVersionDashboardController(
private val pipelineVersionDashboardService: PipelineVersionDashboardService
) {
@Operation(
description = "Get statistics about how many sequences are processed with each pipeline version"
)
@GetMapping("/pipeline-version-dashboard")
fun getPipelineVersionDashboard(): PipelineVersionDashboard =
pipelineVersionDashboardService.getPipelineVersionStats()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.loculus.backend.service.submission

import org.jetbrains.exposed.sql.JoinType
import org.jetbrains.exposed.sql.Query
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.SortOrder
import org.jetbrains.exposed.sql.selectAll
import org.loculus.backend.controller.PipelineVersionDashboard
import org.loculus.backend.controller.PipelineVersionStats
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
class PipelineVersionDashboardService(
private val submissionDatabaseService: SubmissionDatabaseService
) {
fun getPipelineVersionStats(): PipelineVersionDashboard {
// Join sequence entries with preprocessed data to get version stats
val query = SequenceEntriesPreprocessedDataTable
.join(
SequenceEntriesTable,
JoinType.INNER,
additionalConstraint = {
(SequenceEntriesPreprocessedDataTable.accessionColumn eq SequenceEntriesTable.accessionColumn) and
(SequenceEntriesPreprocessedDataTable.versionColumn eq SequenceEntriesTable.versionColumn)
}
)
.selectAll()

// Count sequences per pipeline version
val versionCounts = query
.groupBy { it[SequenceEntriesPreprocessedDataTable.pipelineVersionColumn] }
.mapValues { it.value.size.toLong() }

val currentVersion = submissionDatabaseService.getCurrentProcessingPipelineVersion()

val stats = versionCounts.map { (version, count) ->
PipelineVersionStats(
pipelineVersion = version,
sequenceCount = count,
isCurrentVersion = version == currentVersion
)
}.sortedBy { it.pipelineVersion }

val totalSequences = stats.sumOf { it.sequenceCount }

return PipelineVersionDashboard(stats, totalSequences)
}
}
Loading