Skip to content

Commit

Permalink
add swiss tournament runner (#16)
Browse files Browse the repository at this point in the history
update version to 0.7.0

Signed-off-by: John Burns <[email protected]>
  • Loading branch information
wakingrufus authored Feb 7, 2018
1 parent 8a6567e commit 7fe0366
Show file tree
Hide file tree
Showing 25 changed files with 1,063 additions and 183 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.2.20'
ext.kotlin_version = '1.2.21'
ext.jackson_version = '2.9.2'
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
Expand All @@ -13,7 +13,7 @@ plugins {
id 'java'
id 'application'
id 'idea'
id "org.jetbrains.kotlin.jvm" version "1.2.20"
id "org.jetbrains.kotlin.jvm" version "1.2.21"
id 'jacoco'
}
apply plugin: 'javafx-gradle-plugin'
Expand All @@ -24,10 +24,10 @@ repositories {
maven { url 'https://jitpack.io' }
}

version = "0.6.0"
version = "0.7.0"

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.17'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ data class SwissTeamData(

data class SwissGameData(val id: String,
val gameId: String,
val winningTeam: String)
val winningTeamId: String)

data class SwissRound(val results: List<SwissResultData>)
data class SwissRound(val roundNumber: Int, val pairings: List<SwissPairingData>)

data class SwissResultData(val pairing: SwissPairing, val games: List<SwissGameData>)

data class SwissPairing(val id: String,
val teamIds: Pair<String, String>)
data class SwissPairingData(val id: String,
val teamIds: List<String>,
val games: List<SwissGameData>,
val drops: List<String> = ArrayList())

@JsonIgnoreProperties(ignoreUnknown = true)
data class SwissTournamentData(val id: String,
val startTime: Long,
val name: String,
val teams: List<SwissTeamData>,
val rounds: Map<Int, SwissRound>)
val rounds: List<SwissRound>)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.wakingrufus.eloleague.game

import com.github.wakingrufus.eloleague.isValidInt
import com.github.wakingrufus.eloleague.league.LeagueModel
import com.github.wakingrufus.eloleague.player.PlayerItem
import com.github.wakingrufus.eloleague.player.PlayerListBuilder
import mu.KLogging
import tornadofx.*
Expand Down Expand Up @@ -36,7 +37,7 @@ class GameView : Fragment("Edit Game") {
fieldset("Team 1") {
this += find<PlayerListBuilder>(mapOf(
"selectedPlayers" to gameModel.team1Players.value,
"otherIneligiblePlayers" to gameModel.team2Players.value,
"otherIneligiblePlayers" to { gameModel.team2Players.value.map(PlayerItem::id) },
"allPlayers" to leagueModel.players.value
))
field("team 1 score") {
Expand All @@ -49,7 +50,7 @@ class GameView : Fragment("Edit Game") {
fieldset("Team 2") {
this += find<PlayerListBuilder>(mapOf(
"selectedPlayers" to gameModel.team2Players.value,
"otherIneligiblePlayers" to gameModel.team1Players.value,
"otherIneligiblePlayers" to { gameModel.team1Players.value.map(PlayerItem::id) },
"allPlayers" to leagueModel.players.value
))
field("team 2 score") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.github.wakingrufus.eloleague.game.GameItem
import com.github.wakingrufus.eloleague.game.toData
import com.github.wakingrufus.eloleague.player.PlayerItem
import com.github.wakingrufus.eloleague.swiss.SwissTournamentItem
import com.github.wakingrufus.eloleague.swiss.toData
import com.github.wakingrufus.eloleague.swiss.fromTournamentData
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleListProperty
import javafx.beans.property.SimpleStringProperty
Expand Down Expand Up @@ -90,7 +90,7 @@ fun fromData(leagueData: LeagueData): LeagueItem {
})
})
if (leagueData.tournamentData.isNotEmpty()) {
item.tournamentsProperty.setAll(leagueData.tournamentData.map { com.github.wakingrufus.eloleague.swiss.fromData(it, item.players) })
item.tournamentsProperty.setAll(leagueData.tournamentData.map { fromTournamentData(data = it, league = item) })
}
return item
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import com.github.wakingrufus.eloleague.results.results
import com.github.wakingrufus.eloleague.swiss.SwissTournamentItem
import com.github.wakingrufus.eloleague.swiss.SwissTournamentModel
import com.github.wakingrufus.eloleague.swiss.SwissView
import javafx.beans.binding.BooleanBinding
import javafx.scene.control.TabPane
import javafx.stage.StageStyle
import mu.KLogging
import tornadofx.*
import java.util.*
import javax.naming.Binding

class LeagueView : View("League View") {
companion object : KLogging()
Expand Down Expand Up @@ -63,7 +61,7 @@ class LeagueView : View("League View") {
this += GameListView::class
}
tab("tournaments") {
visibleWhen(false.toProperty())
// visibleWhen(false.toProperty())
fieldset("Tournaments") {
val tournamentTable = tableview(model.tournaments) {
column("Time", SwissTournamentItem::startTime)
Expand Down Expand Up @@ -107,18 +105,17 @@ class LeagueView : View("League View") {

button("View Results").setOnAction {
val games = games(model.games.value.map(GameItem::toData))
val modal: ResultsView =
find<ResultsView>(mapOf(
"leagueResultItem" to results(
leagueItem = model.item,
leagueState = calculateNewLeague(
league = league(toData(model.item)),
games = games)))).apply {
openModal(
stageStyle = StageStyle.UTILITY,
block = false
)
}
find<ResultsView>(mapOf(
"leagueResultItem" to results(
leagueItem = model.item,
leagueState = calculateNewLeague(
league = league(toData(model.item)),
games = games)))).apply {
openModal(
stageStyle = StageStyle.UTILITY,
block = false
)
}
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.wakingrufus.eloleague.player

import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.stage.StageStyle
import mu.KLogging
Expand All @@ -11,27 +10,16 @@ class PlayerListBuilder : Fragment() {

val selectedPlayers: ObservableList<PlayerItem> by param()
val allPlayers: ObservableList<PlayerItem> by param()
val otherIneligiblePlayers: ObservableList<PlayerItem> by param(FXCollections.observableArrayList())
val otherIneligiblePlayers: () -> List<String> by param()


val choosePlayer: (allPlayers: ObservableList<PlayerItem>, selectedPlayers: ObservableList<PlayerItem>) -> PlayerItem? = { allPlayers, selectedPlayers ->
find<PlayerChooserView>(
mapOf("players" to allPlayers
.filter { lp -> !selectedPlayers.any { lp.id == it.id } }
.filter { lp -> !otherIneligiblePlayers.any{ lp.id == it.id} }
.observable())
).apply {
openModal(stageStyle = StageStyle.UTILITY, block = true)
}.choice
}

override val root = vbox {
override val root = vbox {
vbox {
style {
minHeight = 8.em
}
children.bind(selectedPlayers) { player: PlayerItem ->
field(player.name) {
hbox {
label(player.name)
button("Remove") {
action {
selectedPlayers.remove(player)
Expand All @@ -41,9 +29,14 @@ class PlayerListBuilder : Fragment() {
}
}
button("Add Player").setOnAction {
selectedPlayers.add(choosePlayer(
allPlayers,
selectedPlayers))
find<PlayerChooserView>(
mapOf("players" to allPlayers
.filter { lp -> !selectedPlayers.any { lp.id == it.id } }
.filter { lp -> lp.id !in otherIneligiblePlayers() }
.observable())
).apply {
openModal(stageStyle = StageStyle.UTILITY, block = true)
}.choice?.let { selectedPlayers.add(it) }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.wakingrufus.eloleague.swiss

import com.github.wakingrufus.eloleague.game.GameItem
import javafx.beans.property.SimpleObjectProperty
import javafx.collections.ObservableList
import mu.KLogging
import tornadofx.*

class GamePicker : Fragment() {
companion object : KLogging()

val games: List<GameItem> by param()
val selectedGame = SimpleObjectProperty<GameItem>()

override val root = vbox {
combobox(values = games, property = selectedGame) {
cellFormat {
text = StringBuilder()
.apply {
append(it.team1Players.joinToString(" & ") { it.name }).append(" ")
}.apply {
append(it.team1Score).append(" vs ")
}.apply {
append(it.team2Players.joinToString(" & ") { it.name }).append(" ")
}.apply {
append(it.team2Score).append(" ")
}.toString()
}
}
buttonbar {
button("Ok") {
enableWhen(selectedGame.isNotNull)
action {
close()
}
}
button("Cancel") {
action {
selectedGame.value = null
close()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.wakingrufus.eloleague.swiss

import javafx.beans.property.ReadOnlyDoubleWrapper
import javafx.beans.property.ReadOnlyListWrapper
import mu.KLogging
import tornadofx.*

class StandingsView : Fragment() {
companion object : KLogging()

val standings: List<SwissStanding> by param()

override val root = borderpane {

center {
id = "standings-wrapper"

tableview(ReadOnlyListWrapper(standings.observable())) {
column<SwissStanding, String>("Name", { it.value.team.nameProperty })
column("Points", SwissStanding::matchPoints)
column("Opponent Match win %", SwissStanding::opponentMatchWinPct)
column<SwissStanding, Number>("Game win %") {
ReadOnlyDoubleWrapper(gameWinPct(it.value))
}
column("Opponent Game win %", SwissStanding::opponentGameWinPct)
columnResizePolicy = SmartResize.POLICY
}

}

}
}
Loading

0 comments on commit 7fe0366

Please sign in to comment.