Skip to content

Commit

Permalink
Add winning pct to league results view (#25)
Browse files Browse the repository at this point in the history
* add ability to open data from file and save to file
add ability to open data from url

Signed-off-by: John Burns <[email protected]>

* fix #14 Show win percentage in league results view

add new calculator for most improved over a period of time

Signed-off-by: John Burns <[email protected]>
  • Loading branch information
wakingrufus authored Sep 6, 2018
1 parent 04cdf70 commit b24a937
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.github.wakingrufus.eloleague.results

import com.github.wakingrufus.eloleague.player.PlayerItem
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import tornadofx.*
import java.time.LocalDate
import java.time.ZoneOffset
import java.time.ZonedDateTime

class MostImprovedView : Fragment() {
val leagueResultItem: LeagueResultItem by param()
var startDate = SimpleObjectProperty<LocalDate>(LocalDate.now())
var endDate = SimpleObjectProperty<LocalDate>(LocalDate.now())
var winner = SimpleStringProperty()
override val root = borderpane {
center {
form {
fieldset {
field {
label("Start Date")
datepicker {
bind(startDate)
}
}
field {
label("End Date")
datepicker {
bind(endDate)
}
}
}
textfield {
isEditable = false
bind(winner)
}
}

}
bottom {
buttonbar {
button("Calculate") {
action {
winner.value = leagueResultItem.games.asSequence()
.filter { ZonedDateTime.parse(it.entryDate).isAfter(startDate.value.atStartOfDay().atOffset(ZoneOffset.UTC).toZonedDateTime()) }
.filter { ZonedDateTime.parse(it.entryDate).isBefore(endDate.value.plusDays(1).atStartOfDay().atOffset(ZoneOffset.UTC).toZonedDateTime()) }
.fold(mapOf<PlayerItem, Int>()) { map, game ->
map + (game.player to (map[game.player] ?: 0) + game.ratingAdjustment)
}.maxBy { it.value }?.let {
"${it.key.name} (${it.value})"
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.github.wakingrufus.eloleague.results

import javafx.beans.binding.Bindings
import javafx.beans.property.ReadOnlyStringWrapper
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.stage.StageStyle
import mu.KLogging
import tornadofx.*
import java.math.BigDecimal
import java.math.MathContext

class ResultsView : Fragment() {
companion object : KLogging()
Expand All @@ -26,6 +29,17 @@ class ResultsView : Fragment() {
id = "results-tableview"
column("Name", PlayerResultItem::nameProperty)
column("Rating", PlayerResultItem::currentRatingProperty)
column<PlayerResultItem, String>("Win %") {
if (it.value.gamesPlayedProperty.value > 0) {
ReadOnlyStringWrapper((BigDecimal(it.value.winsProperty.value)
.divide(BigDecimal(it.value.gamesPlayedProperty.value), MathContext.DECIMAL32))
.movePointRight(2)
.toString())
} else {
ReadOnlyStringWrapper("N/A")
}

}
column("Games", PlayerResultItem::gamesPlayedProperty)
column("Wins", PlayerResultItem::winsProperty)
column("Losses", PlayerResultItem::lossesProperty)
Expand Down Expand Up @@ -66,6 +80,16 @@ class ResultsView : Fragment() {
playerList.predicate = { it.gamesPlayedProperty >= trialPeriod }
}
}
button("Most Improved") {
action {
find<MostImprovedView>(mapOf("leagueResultItem" to leagueResultItem)).apply {
openModal(
stageStyle = StageStyle.UTILITY,
block = true
)
}
}
}
}
}
}
Expand Down

0 comments on commit b24a937

Please sign in to comment.