-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement advanced online players chart (#210)
* Implement advanced online players chart * Implement test * Document function
- Loading branch information
1 parent
7570ba8
commit 2f27625
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
...n/java/com/github/kevindagame/voxelsniper/integration/bstats/ServerSizeCategoryCounter.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,35 @@ | ||
package com.github.kevindagame.voxelsniper.integration.bstats | ||
|
||
object ServerSizeCategoryCounter { | ||
private val categories = listOf( | ||
ServerSizeCategory("0", 0, 0), | ||
ServerSizeCategory("1-10", 1, 10), | ||
ServerSizeCategory("11-20", 11, 20), | ||
ServerSizeCategory("21-50", 21, 50), | ||
ServerSizeCategory("51-100", 51, 100), | ||
ServerSizeCategory("101-200", 101, 200), | ||
ServerSizeCategory("201-500", 201, 500), | ||
ServerSizeCategory("501-1000", 501, 1000), | ||
ServerSizeCategory("More than 1000", 1001, Int.MAX_VALUE), | ||
|
||
|
||
) | ||
|
||
/** | ||
* Gets the data for the server size category chart. | ||
* @param playerCount The amount of players online on the server. | ||
* @return The data for the server size category chart. | ||
* The data consists of a map with the label of the category, and a map with the exact value. The bstats docs do not explain the hardcoded 1. I assume this means that it's either 1 deep or a weight of 1 | ||
*/ | ||
fun getData(playerCount: Int): Map<String, Map<String, Int>> { | ||
val map = mutableMapOf<String, Map<String, Int>>() | ||
val entries = mutableMapOf<String, Int>() | ||
val category = categories.find { playerCount in it.min..it.max } | ||
entries[playerCount.toString()] = 1 | ||
map[category!!.label] = entries | ||
|
||
return map | ||
} | ||
} | ||
|
||
data class ServerSizeCategory(val label: String, val min: Int, val max: Int) |
28 changes: 28 additions & 0 deletions
28
...va/com/github/kevindagame/voxelsniper/integration/bstats/ServerSizeCategoryCounterTest.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,28 @@ | ||
package com.github.kevindagame.voxelsniper.integration.bstats | ||
|
||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class ServerSizeCategoryCounterTest { | ||
|
||
@Test | ||
fun testGetData() { | ||
val testData = listOf( | ||
0 to "0", | ||
5 to "1-10", | ||
15 to "11-20", | ||
30 to "21-50", | ||
75 to "51-100", | ||
150 to "101-200", | ||
300 to "201-500", | ||
750 to "501-1000", | ||
2000 to "More than 1000" | ||
) | ||
|
||
for ((playerCount, expectedCategory) in testData) { | ||
val result = ServerSizeCategoryCounter.getData(playerCount) | ||
val categoryMap = result[expectedCategory] | ||
Assert.assertEquals(1, categoryMap?.get(playerCount.toString())) | ||
} | ||
} | ||
} |