-
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.
Add winning pct to league results view (#25)
* 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
1 parent
04cdf70
commit b24a937
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/com/github/wakingrufus/eloleague/results/MostImprovedView.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,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})" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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