Show license status for French players in EGF ladder
This commit is contained in:
@@ -17,10 +17,12 @@ object EGFRatingsHandler: RatingsHandler(RatingsManager.Ratings.EGF) {
|
||||
val pairs = groups.map {
|
||||
Pair(it, match.groups[it]?.value)
|
||||
}.toTypedArray()
|
||||
Json.MutableObject(*pairs).also {
|
||||
it["origin"] = "EGF"
|
||||
Json.MutableObject(*pairs).also { player ->
|
||||
player["origin"] = "EGF"
|
||||
// override rank with rating equivalent
|
||||
val rating = it["rating"]?.toString()?.toIntOrNull()
|
||||
player["rating"]?.toString()?.toIntOrNull()?.let { rating ->
|
||||
player["rank"] = ((rating - 2050)/100).let { if (rating < 0) "${-it+1}k" else "${it+1}d" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,5 +37,5 @@ object FFGRatingsHandler: RatingsHandler(RatingsManager.Ratings.FFG) {
|
||||
|
||||
var linePattern =
|
||||
Regex("(?<name>$atom+(?:\\((?:$atom|[0-9])+\\))?)\\s(?<firstname>$atom+(?:\\((?:$atom|[0-9])+\\))?)\\s+(?<rating>-?[0-9]+)\\s(?<license>[-eCLX])\\s(?<ffg>(?:\\d|[A-Z]){7}|-------)\\s(?<club>xxxx|XXXX|\\d{2}[a-zA-Z0-9]{2})\\s(?<country>[A-Z]{2})")
|
||||
val groups = arrayOf("name", "firstname", "rating", "license", "club", "country")
|
||||
val groups = arrayOf("name", "firstname", "rating", "license", "ffg", "club", "country")
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package org.jeudego.pairgoth.ratings
|
||||
|
||||
import com.republicate.kson.Json
|
||||
import org.jeudego.pairgoth.util.getResourceAsStream
|
||||
import org.jeudego.pairgoth.web.WebappManager
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.BufferedReader
|
||||
import java.lang.Exception
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
@@ -37,6 +39,12 @@ object RatingsManager: Runnable {
|
||||
val timer = Timer()
|
||||
lateinit var players: Json.MutableArray
|
||||
val updateLock: ReadWriteLock = ReentrantReadWriteLock()
|
||||
val egf2ffg by lazy {
|
||||
BufferedReader(getResourceAsStream("/egf2ffg.csv").reader()).readLines().associate {
|
||||
it.split(',').zipWithNext().first()
|
||||
}
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
logger.info("launching ratings manager")
|
||||
timer.scheduleAtFixedRate(Task, 0L, 3600000L)
|
||||
@@ -58,6 +66,25 @@ object RatingsManager: Runnable {
|
||||
updateLock.writeLock().unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// propagate French players license status from ffg to egf
|
||||
val licenseStatus = players.map { it -> it as Json.MutableObject }.filter {
|
||||
it["origin"] == "FFG"
|
||||
}.associate { player ->
|
||||
Pair(player.getString("ffg")!!, player.getString("license") ?: "-")
|
||||
}
|
||||
players.map { it -> it as Json.MutableObject }.filter {
|
||||
it["origin"] == "EGF" && it["country"] == "FR"
|
||||
}.forEach { player ->
|
||||
player.getString("egf")?.let { egf ->
|
||||
egf2ffg[egf]?.let { ffg ->
|
||||
licenseStatus[ffg]?.let {
|
||||
player["license"] = it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
logger.error("could not build or refresh index", e)
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
package org.jeudego.pairgoth.util
|
||||
|
||||
fun getResourceAsStream(path: String) = object{}::class.java.getResourceAsStream(path)
|
6390
view-webapp/src/main/resources/egf2ffg.csv
Normal file
6390
view-webapp/src/main/resources/egf2ffg.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -259,7 +259,7 @@
|
||||
#[[
|
||||
<script id="result" type="text/template">
|
||||
{{for #data}}
|
||||
<div class="result-line" data-index="{{:#getIndex()}}">[{{:origin}}] {{:country}} - {{:name}} {{:firstname}} {{:rank}} ({{:club}}) {{if origin === 'FFG' && country === 'FR' && license !== 'L'}}<span class="darkred">non licencié</span>{{/if}}</div>
|
||||
<div class="result-line" data-index="{{:#getIndex()}}">[{{:origin}}] {{:country}} - {{:name}} {{:firstname}} {{:rank}} ({{:club}}) {{if country === 'FR' && license !== 'L'}}<span class="darkred">non licencié</span>{{/if}}</div>
|
||||
{{/for}}
|
||||
</script>
|
||||
<script type="text/javascript" src="/lib/jsrender-1.0.13/jsrender.min.js"></script>
|
||||
|
Reference in New Issue
Block a user