-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flyttet oppholdstilatelse stats funksjon til arbeidssøker-regler
- Loading branch information
Showing
4 changed files
with
88 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
...pp-perioder/src/main/kotlin/no/nav/paw/arbeidssokerregisteret/services/PersonInfoStats.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../src/main/kotlin/no/nav/paw/arbeidssokerregisteret/application/OppholdstillatelseStats.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package no.nav.paw.arbeidssokerregisteret.application | ||
|
||
import io.micrometer.core.instrument.Tag | ||
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry | ||
import no.nav.paw.arbeidssokerregisteret.application.opplysninger.DomeneOpplysning | ||
import no.nav.paw.arbeidssokerregisteret.application.opplysninger.Opplysning | ||
import java.time.LocalDate | ||
import java.time.temporal.ChronoUnit | ||
|
||
data class StatsOppholdtilatelse( | ||
val fra: LocalDate?, | ||
val til: LocalDate?, | ||
val type: String | ||
) | ||
|
||
fun statsOppholdstilatelse(type: String, fra: String?, til: String?) = | ||
StatsOppholdtilatelse( | ||
fra = fra?.let(LocalDate::parse), | ||
til = til?.let(LocalDate::parse), | ||
type = type | ||
) | ||
|
||
fun PrometheusMeterRegistry.oppholdstillatelseStats(oppholdtilatelse: StatsOppholdtilatelse?, opplysninger: Collection<Opplysning>) { | ||
val tags = listOf( | ||
Tag.of( | ||
"oppholdstillatelse_type", | ||
oppholdtilatelse?.type ?: "NA" | ||
), | ||
Tag.of( | ||
"dager_siden_oppholdstillatelse_start", | ||
oppholdtilatelse?.fra?.let(::daysBetweenNow)?.let(::asBucket) ?: if (oppholdtilatelse == null) "NA" else "undefined" | ||
), | ||
Tag.of( | ||
"dager_til_oppholdstillatelse_stopp", | ||
oppholdtilatelse?.til?.let(::daysBetweenNow)?.let(::asBucket) ?: if (oppholdtilatelse == null) "NA" else "undefined" | ||
), | ||
Tag.of( | ||
"avtale_land", | ||
(opplysninger.contains(DomeneOpplysning.ErEuEoesStatsborger) || opplysninger.contains(DomeneOpplysning.ErGbrStatsborger)).toString() | ||
), | ||
Tag.of( | ||
"norsk_statsborger", | ||
opplysninger.contains(DomeneOpplysning.ErNorskStatsborger).toString() | ||
) | ||
) + opplysningerTags(opplysninger) | ||
counter("paw_bosatt_vs_oppholds_stats_v1", tags).increment() | ||
} | ||
|
||
fun opplysningerTags(opplysninger: Collection<Opplysning>): Collection<Tag> = | ||
setOf( | ||
DomeneOpplysning.BosattEtterFregLoven, | ||
DomeneOpplysning.IkkeBosatt, | ||
DomeneOpplysning.HarGyldigOppholdstillatelse, | ||
DomeneOpplysning.UkjentStatusForOppholdstillatelse, | ||
DomeneOpplysning.OppholdstillatelseUtgaaatt, | ||
DomeneOpplysning.IngenInformasjonOmOppholdstillatelse | ||
).map { Tag.of(it.id, opplysninger.contains(it).toString()) } | ||
|
||
|
||
fun daysBetweenNow(then: LocalDate): Long { | ||
val now = LocalDate.now() | ||
return ChronoUnit.DAYS.between(now, then) | ||
} | ||
|
||
fun asBucket(number: Long): String = | ||
when { | ||
number < 7 -> number.toString() | ||
number < 14 -> "[7, 14>" | ||
number < 28 -> "[14-28>" | ||
number < 56 -> "[28-56>" | ||
number < 112 -> "[56-112>" | ||
number < 224 -> "[112-224>" | ||
else -> "[224-" | ||
} |