Skip to content

Commit

Permalink
Add MMR to sumamry. Fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonnold committed Aug 23, 2020
1 parent 2a92db2 commit 24c50e9
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 34 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
implementation group: "org.springframework.boot", name: "spring-boot-starter-security", version: "2.3.3.RELEASE"
implementation group: "org.springframework.boot", name: "spring-boot-starter-data-r2dbc", version: "2.3.3.RELEASE"
annotationProcessor group: "org.springframework.boot", name: "spring-boot-configuration-processor", version: "2.3.3.RELEASE"
developmentOnly group: "org.springframework.boot", name: "spring-boot-devtools", version: "2.3.3.RELEASE"

implementation group: "org.flywaydb", name: "flyway-core", version: "6.5.2"
implementation group: "io.r2dbc", name: "r2dbc-postgresql", version: "0.8.4.RELEASE"
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/me/honnold/ladderhero/dao/domain/Summary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ data class Summary(
var name: String,
@Column("did_win")
var didWin: Boolean,
@Column("mmr")
var mmr: Long = 0,
@Column("collected_minerals")
var collectedMinerals: Long = 0,
@Column("collected_vespene")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ data class ReplayDetailRow(
var teamId: Long,
@Column("did_win")
var didWin: Boolean,
@Column("mmr")
var mmr: Long,
@Column("profile_id")
var profileId: Long,
@Column("region_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ data class ReplaySummaryRow(
var teamId: Long,
@Column("did_win")
var didWin: Boolean,
@Column("mmr")
var mmr: Long,
@Column("profile_id")
var profileId: Long,
@Column("region_id")
Expand Down
5 changes: 0 additions & 5 deletions src/main/kotlin/me/honnold/ladderhero/service/AuthService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import me.honnold.ladderhero.service.domain.UserService
import me.honnold.ladderhero.service.dto.AuthedUser
import me.honnold.ladderhero.service.dto.JWTToken
import me.honnold.ladderhero.web.request.AuthRequest
import org.slf4j.LoggerFactory
import org.springframework.dao.DataIntegrityViolationException
import org.springframework.security.authentication.BadCredentialsException
import org.springframework.security.core.userdetails.UsernameNotFoundException
Expand All @@ -21,10 +20,6 @@ class AuthService(
private val jwtService: JWTService,
private val blizzardService: BlizzardService
) {
companion object {
private val logger = LoggerFactory.getLogger(AuthService::class.java)
}

fun getMe(username: String): Mono<AuthedUser> {
val authedUser = AuthedUser(username)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package me.honnold.ladderhero.service

import me.honnold.ladderhero.service.domain.FileService
import me.honnold.ladderhero.service.dto.upload.UploadResult
import org.slf4j.LoggerFactory
import org.springframework.http.codec.multipart.FilePart
import org.springframework.stereotype.Service
import reactor.core.publisher.Flux
Expand All @@ -13,10 +12,6 @@ class UploadService(
private val fileService: FileService,
private val replayProcessingService: ReplayProcessingService
) {
companion object {
private val logger = LoggerFactory.getLogger(UploadService::class.java)
}

fun uploadFiles(files: Flux<FilePart>): Flux<UploadResult> {
return files
.flatMap { part -> this.s3ClientService.upload(part) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ package me.honnold.ladderhero.service.domain
import me.honnold.ladderhero.dao.FileUploadDAO
import me.honnold.ladderhero.dao.domain.FileUpload
import me.honnold.ladderhero.service.dto.upload.UploadResult
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import reactor.core.publisher.Mono

@Service
class FileService(private val fileUploadDAO: FileUploadDAO) {
companion object {
private val logger = LoggerFactory.getLogger(FileService::class.java)
}

fun saveUploadResult(result: UploadResult): Mono<UploadResult> {
val fileUpload = FileUpload(key = result.fileKey, fileName = result.fileName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class ReplayService(private val replayDAO: ReplayDAO) {
player.name,
player.profileId,
player.teamId,
player.didWin
player.didWin,
player.mmr
)
}
)
Expand Down Expand Up @@ -91,6 +92,7 @@ class ReplayService(private val replayDAO: ReplayDAO) {
playerSnapshots[0].name,
playerSnapshots[0].teamId,
playerSnapshots[0].didWin,
playerSnapshots[0].mmr,
playerSnapshots[0].profileId,
playerSnapshots[0].totalLostMinerals,
playerSnapshots[0].totalLostVespene,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class SummaryService(

val jsonPlayer = data.metadata.players.find { p -> p.playerId == workingId }
val didWin = jsonPlayer?.result == "Win"
val mmr = jsonPlayer?.mmr ?: 0

val summary = Summary(null, replay.id, player.id, workingId, teamId, race, name, didWin)
val summary = Summary(null, replay.id, player.id, workingId, teamId, race, name, didWin, mmr)
return this.summaryDAO.save(summary)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ package me.honnold.ladderhero.service.domain

import me.honnold.ladderhero.dao.UserDAO
import me.honnold.ladderhero.dao.domain.User
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import reactor.core.publisher.Mono

@Service
class UserService(private val userDAO: UserDAO) {
companion object {
private val logger = LoggerFactory.getLogger(UserService::class.java)
}

fun getUser(username: String): Mono<User> {
return this.userDAO.findByUsername(username)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data class ReplayDetails(
val name: String = "",
val teamId: Long = 0,
val didWin: Boolean = false,
var mmr: Long = 0,
val profileId: Long = 0,
val totalLostMinerals: Long = 0,
val totalLostVespene: Long = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class ReplaySummary(
val name: String,
val profileId: Long,
val teamId: Long,
var didWin: Boolean
var didWin: Boolean,
var mmr: Long
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package me.honnold.ladderhero.web

import me.honnold.ladderhero.service.BlizzardService
import me.honnold.ladderhero.util.toUUID
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.http.HttpStatus
import org.springframework.http.server.reactive.ServerHttpResponse
Expand All @@ -21,10 +20,6 @@ class BlizzardController(
@Qualifier("homePageUri")
private val homePageUri: URI
) {
companion object {
private val logger = LoggerFactory.getLogger(BlizzardController::class.java)
}

@GetMapping(path = ["/authorize"])
fun authorizeBlizzard(principal: Principal, response: ServerHttpResponse): Mono<Void> {
return blizzardService.getAuthorizeRedirectUri(principal.name).flatMap { uri ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package me.honnold.ladderhero.web.api.v1
import me.honnold.ladderhero.service.domain.ReplayService
import me.honnold.ladderhero.service.dto.replay.ReplayDetails
import me.honnold.ladderhero.service.dto.replay.ReplaySummary
import org.slf4j.LoggerFactory
import org.springframework.data.domain.PageRequest
import org.springframework.web.bind.annotation.*
import reactor.core.publisher.Flux
Expand All @@ -12,10 +11,6 @@ import reactor.core.publisher.Mono
@RestController
@RequestMapping("/api/v1/replays")
class ReplayController(private val replayService: ReplayService) {
companion object {
private val logger = LoggerFactory.getLogger(ReplayController::class.java)
}

@GetMapping
fun getReplays(
@RequestParam(defaultValue = "25")
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/me/honnold/mpq/Archive.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import java.nio.ByteOrder
import java.nio.channels.SeekableByteChannel
import java.nio.charset.StandardCharsets
import java.nio.file.Path
import java.util.*
import kotlin.math.ceil

class Archive(path: Path) : AutoCloseable {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE public.summary ADD mmr int NULL;
UPDATE public.summary SET mmr = 0 WHERE mmr IS NULL;
ALTER TABLE public.summary ALTER COLUMN mmr SET NOT NULL;

0 comments on commit 24c50e9

Please sign in to comment.