Skip to content

Commit

Permalink
Merge pull request #171 from theSimpleCloud/feature/overview
Browse files Browse the repository at this point in the history
feat: overview year specification
  • Loading branch information
FllipEis authored Dec 30, 2023
2 parents 50d5f62 + b2cd261 commit c123b4b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import eu.thesimplecloud.base.manager.database.SQLiteOfflineCloudPlayerHandler
import eu.thesimplecloud.base.manager.startup.Manager
import eu.thesimplecloud.module.rest.javalin.RestServer
import eu.thesimplecloud.module.statistics.rest.overview.OverviewController
import eu.thesimplecloud.module.statistics.rest.overview.data.Overview
import eu.thesimplecloud.module.statistics.rest.timed.TimedValueController
import eu.thesimplecloud.module.statistics.timed.TimedValueCollectorManager
import eu.thesimplecloud.module.statistics.timed.collector.CPUUsageTimedCollector
Expand All @@ -41,6 +42,7 @@ import eu.thesimplecloud.module.statistics.timed.store.ITimedValueStore
import eu.thesimplecloud.module.statistics.timed.store.MongoTimedValueStore
import eu.thesimplecloud.module.statistics.timed.store.SQLTimedValueStore
import eu.thesimplecloud.module.statistics.timed.store.SQLiteTimedValueStore
import java.util.*
import java.util.concurrent.CopyOnWriteArrayList

/**
Expand Down Expand Up @@ -69,6 +71,7 @@ class StatisticsModule : ICloudModule {

RestServer.instance.controllerHandler.registerController(TimedValueController())
RestServer.instance.controllerHandler.registerController(OverviewController())
Overview.create(false, 2023)
}

override fun onDisable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import eu.thesimplecloud.module.rest.annotation.RequestType
import eu.thesimplecloud.module.rest.annotation.RestController
import eu.thesimplecloud.module.rest.controller.IController
import eu.thesimplecloud.module.statistics.rest.overview.data.Overview
import java.util.*

@RestController(path = "statistics/overview/")
class OverviewController : IController {

@RequestMapping(RequestType.GET, additionalPath = "", permission = "web.cloud.overview.get")
fun handleOverviewRequest(@RequestParam("force", required = false) force: Boolean?): Overview {
return Overview.create(force ?: false)
fun handleOverviewRequest(@RequestParam("force", required = false) force: Boolean?, @RequestParam("year", required = false) year: Int?): Overview {
return Overview.create(force ?: false, year ?: Calendar.getInstance().get(Calendar.YEAR))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ data class Overview(

companion object {

val client = OkHttpClient()
private val client = OkHttpClient()
private const val USER_STATS_FORMAT = "https://laby.net/api/v3/user/%s/game-stats"
fun create(force: Boolean): Overview {
fun create(force: Boolean, year: Int): Overview {

if (!force) {
val saved = get()
Expand All @@ -52,7 +52,7 @@ data class Overview(
var playerRecord = TimedValue(-1)
var serversRecord = TimedValue(-1)

val currentYear: Long = GregorianCalendar(Calendar.getInstance().get(Calendar.YEAR), 0, 0).timeInMillis
val currentYear: Long = GregorianCalendar(year, 0, 0).timeInMillis
val currentTime = System.currentTimeMillis()

val calender = Calendar.getInstance()
Expand Down Expand Up @@ -192,7 +192,6 @@ data class Overview(
scoreAverageColor = "#474747"
}

//TODO: Add ServerPersonality detection
val generatedOverview = Overview(
ServerPersonality.DEVELOPING_NETWORK,
installDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ enum class ServerPersonality {
}
}
if (isEveryDayEveryNight) return EVERY_DAY_EVERY_NIGHT
val fridayScore = overview.weekAverage[5].score
if (fridayScore >= (overview.averageScore + overview.averageScore / 10) && overview.averageScore > 0) return FRIDAY_CLUB
var highestScore = 0
overview.weekAverage.forEach { average ->
if (highestScore < average.score) highestScore = average.score
}
val fridayScore = overview.weekAverage[5].score
if (fridayScore >= highestScore && fridayScore >= overview.averageScore + (overview.averageScore / 4)) return FRIDAY_CLUB
if (highestScore > (overview.averageScore + overview.averageScore / 3)) return MAYFLY
var underWeekAverage = 0
overview.weekAverage.forEach { average ->
Expand All @@ -46,7 +46,7 @@ enum class ServerPersonality {
underWeekAverage /= 5
if (overview.averageScore < underWeekAverage) return WORKAHOLIC
if (overview.players >= 10 && overview.players < overview.averageStartedServers) return STARTUP_NETWORK
if (overview.players * 15 > overview.startedServers) return DISHWASHER
if (overview.players * 10 < overview.startedServers) return DISHWASHER
var averageJoins = 0
var averagePlayers = 0
overview.weekAverage.forEach { average ->
Expand Down

0 comments on commit c123b4b

Please sign in to comment.