Skip to content

Commit

Permalink
new UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ssadat-guscheh-aimit committed Feb 3, 2024
1 parent f4fe27c commit 944f2e9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
30 changes: 19 additions & 11 deletions src/main/kotlin/com/bitkid/itsfranking/ITSFPlayers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,32 @@ class ITSFPlayers(rankings: List<Ranking>) {

fun find(search: String, searchForNameParts: Boolean = false): List<ITSFPlayer> {
val res = findPlayer(search)
val newRes = res.ifEmpty { findPlayer(search.split(" ").reversed().joinToString(" ")) }
if (newRes.isEmpty() && searchForNameParts) {
search.split(" ").forEach {
val splitRes = findPlayer(it)
if (splitRes.isNotEmpty())
return splitRes
if (res.isEmpty()) {
val phoneticRes = phoneticSearch(search)
if (phoneticRes.isEmpty()) {
val reversedName = search.split(" ").reversed().joinToString(" ")
val reversedRes = if (reversedName != search) findPlayer(reversedName) else emptyList()
if (reversedRes.isEmpty() && searchForNameParts) {
return findPlayerWithNameParts(search)
}
return reversedRes
}
return phoneticRes
}
return newRes
return res
}

private fun findPlayer(search: String): List<ITSFPlayer> {
val normalSearch = players.filter { it.value.name.contains(search, true) }.map { it.value }
return normalSearch.ifEmpty {
phoneticSearch(search)
private fun findPlayerWithNameParts(search: String): List<ITSFPlayer> {
search.split(" ").forEach {
val splitRes = findPlayer(it)
if (splitRes.isNotEmpty())
return splitRes
}
return emptyList()
}

private fun findPlayer(search: String): List<ITSFPlayer> = players.filter { it.value.name.contains(search, true) }.map { it.value }

private fun phoneticSearch(search: String): List<ITSFPlayer> {
val enc = engine.encode(search).split("|")
return phoneticNames.filter {
Expand Down
32 changes: 25 additions & 7 deletions src/main/kotlin/com/bitkid/itsfranking/ITSFRankingApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ private class LoadCsvPanel(private val jFrame: JFrame, private val load: (File,
}
}

private class ResultTableModel(columns: List<String>) : DefaultTableModel(Vector(columns), 0) {
private class ResultTableModel(columns: List<String>, private val editable: Boolean = false) : DefaultTableModel(Vector(columns), 0) {
override fun isCellEditable(row: Int, column: Int): Boolean {
return false
return editable
}
}

Expand All @@ -146,13 +146,23 @@ object ITSFRankingApp {
cellSelectionEnabled = true
}

private val jTableList = JTable(emptyListResultModelSingles()).apply {
cellSelectionEnabled = true
}

private val jTableRanking = JTable(emptyRankingModel()).apply {
cellSelectionEnabled = true
}

private val tabbedPane = JTabbedPane()


private fun emptyModel() = ResultTableModel(listOf("itsf no.", "name") + Categories.all.map { it.targetAudience })

private fun emptyRankingModel() = ResultTableModel(listOf("itsf no.", "name", "country", "rank", "points"))

private fun emptyListResultModelSingles() = ResultTableModel(listOf("player", "country", "points", "status"))
private fun emptyListResultModelDoubles() = ResultTableModel(listOf("player1", "player2", "p1 country", "p1 points", "p1 status", "p2 country", "p2 points", "p2 status"))
private fun emptyListResultModelSingles() = ResultTableModel(listOf("player", "country", "points", "status"), true)
private fun emptyListResultModelDoubles() = ResultTableModel(listOf("player1", "player2", "p1 country", "p1 points", "p1 status", "p2 country", "p2 points", "p2 status"), true)

private fun showRanking(category: String) {
if (checkRankingLoaded()) {
Expand All @@ -164,7 +174,8 @@ object ITSFRankingApp {
val props = listOf(it.licenseNumber, it.name, it.country, itsfRank.rank.toString(), itsfRank.points.toString())
m.addRow(props)
}
jTable.model = m
jTableRanking.model = m
tabbedPane.selectedIndex = 2
}
}

Expand Down Expand Up @@ -197,6 +208,7 @@ object ITSFRankingApp {
jTable.model = emptyModel()
else
jTable.model = modelWithPlayers(listOf(player))
tabbedPane.selectedIndex = 0
}
}
}
Expand All @@ -207,6 +219,7 @@ object ITSFRankingApp {
if (!text.isNullOrBlank()) {
val player = itsfPlayers.find(text, true)
jTable.model = modelWithPlayers(player)
tabbedPane.selectedIndex = 0
}
}
}
Expand Down Expand Up @@ -238,7 +251,8 @@ object ITSFRankingApp {
}
model
}
jTable.model = model
jTableList.model = model
tabbedPane.selectedIndex = 1
}

private fun addPlayerToRow(list: MutableList<String?>, category: Category, playerNameWithResults: PlayerNameWithResults) {
Expand Down Expand Up @@ -304,7 +318,11 @@ object ITSFRankingApp {
panel.add(LoadCsvPanel(jFrame, ::loadFile, ::checkRankingLoaded), "growx")

panel.add(JLabel("Results"))
panel.add(JScrollPane(jTable), "growx, height :400:")

tabbedPane.addTab("Search results", JScrollPane(jTable))
tabbedPane.addTab("Player list", JScrollPane(jTableList))
tabbedPane.addTab("Rankings", JScrollPane(jTableRanking))
panel.add(tabbedPane, "growx, height :400:")

return panel
}
Expand Down
7 changes: 3 additions & 4 deletions src/test/kotlin/com/bitkid/itsfranking/ListMatcherTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test
import strikt.api.expectThat
import strikt.api.expectThrows
import strikt.assertions.hasSize
import strikt.assertions.isEmpty
import strikt.assertions.isEqualTo
import java.io.File
import java.nio.charset.Charset
Expand All @@ -20,8 +19,8 @@ class ListMatcherTest {
fun singles() {
val matcher = ListMatcher(players)
val result = matcher.matchPlayer(singles, Charset.forName("WINDOWS-1252"), Categories.openSingles)
expectThat(result.filter { it.results.size > 1 }).hasSize(1)
expectThat(result.filter { it.results.isEmpty() }).isEmpty()
expectThat(result.filter { it.results.size > 1 }).hasSize(3)
expectThat(result.filter { it.results.isEmpty() }).hasSize(1)
}

@Test
Expand All @@ -45,6 +44,6 @@ class ListMatcherTest {
val matcher = ListMatcher(players)
val result = matcher.matchTeam(mixed, Charsets.UTF_8, Categories.mixedDoubles)
expectThat(result.filter { it.player1.results.isEmpty() || it.player2.results.isEmpty() }).hasSize(0)
expectThat(result.filter { it.player1.results.size > 1 || it.player2.results.size > 1 }).hasSize(2)
expectThat(result.filter { it.player1.results.size > 1 || it.player2.results.size > 1 }).hasSize(3)
}
}

0 comments on commit 944f2e9

Please sign in to comment.