Adjusted full-calc statistics. Use new infantry skill algorithm.
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 7s

This commit is contained in:
MaxJa4
2024-01-25 18:04:45 +01:00
parent 7338d34765
commit 93908f7da5
4 changed files with 69 additions and 15 deletions

View File

@@ -112,7 +112,7 @@ func UpdateCacheAfterExpiry(key string) {
} }
if player.Clan.KeepUpdated { if player.Clan.KeepUpdated {
score, statusCode := GetPlayerScore(player.Name) score, statusCode := GetPlayerScoreNew(player.Name)
if score == score && score != -1 { // not NaN if score == score && score != -1 { // not NaN
if err := models.PlayerCache.SetScore(player.ID, score); err != nil { if err := models.PlayerCache.SetScore(player.ID, score); err != nil {
utils.Logger.Warnf("[KeepUpdated] Failed to update cache for player %s! Error: %s", player.Name, err.Error()) utils.Logger.Warnf("[KeepUpdated] Failed to update cache for player %s! Error: %s", player.Name, err.Error())

View File

@@ -25,7 +25,7 @@ func GetScoreByPlayerID(c *gin.Context) {
score, err := models.PlayerCache.GetScore(player.ID) score, err := models.PlayerCache.GetScore(player.ID)
var statusCode int = http.StatusOK var statusCode int = http.StatusOK
if err != nil || score == -1 { if err != nil || score == -1 {
score, statusCode = GetPlayerScore(player.Name) score, statusCode = GetPlayerScoreNew(player.Name)
if score == score && score != -1 { // not NaN if score == score && score != -1 { // not NaN
if err := models.PlayerCache.SetScore(player.ID, score); err != nil { if err := models.PlayerCache.SetScore(player.ID, score); err != nil {
utils.Logger.Errorf("[SCORE] Failed to cache player score: %s", err.Error()) utils.Logger.Errorf("[SCORE] Failed to cache player score: %s", err.Error())
@@ -50,7 +50,7 @@ func GetScoreByPlayerID(c *gin.Context) {
// GetScoreByPlayerName POST /score/:player_name // GetScoreByPlayerName POST /score/:player_name
func GetScoreByPlayerName(c *gin.Context) { func GetScoreByPlayerName(c *gin.Context) {
playerName := c.Param("player_name") playerName := c.Param("player_name")
score, statusCode := GetPlayerScore(playerName) score, statusCode := GetPlayerScoreNew(playerName)
switch statusCode { switch statusCode {
case 200: case 200:
@@ -73,7 +73,15 @@ func GetPlayerScore(playerName string) (float32, int) {
return calcPlayerScore(playerData), statusCode return calcPlayerScore(playerData), statusCode
} }
func getPlayerData(playerName string) (*models.TrackerWeaponJSON, int) { func GetPlayerScoreNew(playerName string) (float32, int) {
playerData, statusCode := getPlayerData(playerName)
if statusCode != 200 {
return -1, statusCode
}
return calcPlayerScoreNew(playerData), statusCode
}
func getPlayerData(playerName string) (*models.TrackerDataJSON, int) {
c := http.Client{} c := http.Client{}
reqUri := "https://api.gametools.network/bf2042/stats/?raw=false&format_values=false&name=" + playerName + "&platform=pc" reqUri := "https://api.gametools.network/bf2042/stats/?raw=false&format_values=false&name=" + playerName + "&platform=pc"
@@ -105,7 +113,7 @@ func getPlayerData(playerName string) (*models.TrackerWeaponJSON, int) {
return nil, res.StatusCode return nil, res.StatusCode
} }
var response models.TrackerWeaponJSON var response models.TrackerDataJSON
body, err := io.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
utils.Logger.Errorf("[SCORE] Failed to read response body: %s", err.Error()) utils.Logger.Errorf("[SCORE] Failed to read response body: %s", err.Error())
@@ -119,7 +127,26 @@ func getPlayerData(playerName string) (*models.TrackerWeaponJSON, int) {
return &response, 200 return &response, 200
} }
func calcPlayerScore(playerData *models.TrackerWeaponJSON) float32 { func calcPlayerScoreNew(playerData *models.TrackerDataJSON) float32 {
const KdFactor = 0.5
const KpmFactor = 0.3
const ObjectiveFactor = 0.15
const SupportFactor = 0.05
const NormalizeFactor = 1.3
cleanedKills := playerData.DivKills.ADS + playerData.DivKills.Hip - playerData.DivKills.AI
kd := float64(cleanedKills) / float64(playerData.Deaths)
kpm := float64(cleanedKills) / float64(playerData.SecondsPlayed/60.0)
objective := float64(playerData.XP[0].Ribbons.Objective) / float64(playerData.XP[0].Ribbons.Total)
support := float64(playerData.XP[0].Ribbons.Support+playerData.XP[0].Ribbons.Squad) / float64(playerData.XP[0].Ribbons.Total)
score := (kd * KdFactor) + (kpm * KpmFactor) + (objective * ObjectiveFactor) + (support * SupportFactor)
score *= NormalizeFactor
return float32(score)
}
func calcPlayerScore(playerData *models.TrackerDataJSON) float32 {
gameMetrics := GetGameMetric("BF2042") gameMetrics := GetGameMetric("BF2042")
if gameMetrics == nil { if gameMetrics == nil {
utils.Logger.Errorf("[SCORE] No game metrics specified for '%s'", "BF2042") utils.Logger.Errorf("[SCORE] No game metrics specified for '%s'", "BF2042")

View File

@@ -1,7 +1,28 @@
package models package models
type TrackerWeaponJSON struct { type TrackerDataJSON struct {
Weapons []Weapon `json:"weapons"` Weapons []Weapon `json:"weapons"`
DivKills DividedKills `json:"dividedKills"`
Deaths int `json:"deaths"`
SecondsPlayed int `json:"secondsPlayed"`
XP []XP `json:"XP"`
}
type DividedKills struct {
ADS int `json:"ads"`
Hip int `json:"hip"`
AI int `json:"ai"`
}
type XP struct {
Ribbons Ribbons `json:"ribbons"`
}
type Ribbons struct {
Objective int `json:"objective"`
Squad int `json:"squad"`
Support int `json:"support"`
Total int `json:"total"`
} }
type Weapon struct { type Weapon struct {

View File

@@ -23,20 +23,20 @@
</div> </div>
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-3 text-center fs-5 me-4 ps-0"> <div class="col-3 text-center fs-5 me-4 ps-0">
<img src="../static/icons/average.svg" alt="Avg" class="img-fluid me-1 align-top" style="height: 1.8rem; filter: invert(0.85);" data-bs-action="tooltip" data-bs-title="Durchschnitt Heim-Team" /> <i class="bi bi-graph-up me-2" data-bs-action="tooltip" data-bs-title="Durchschnitt Heim-Team"></i>
<span id="home-avg-score" class="text-warning"> <span id="home-avg-score" class="text-warning fw-bold">
<i class="spinner-grow spinner-grow-sm text-secondary align-baseline mx-2" role="status"></i> <i class="spinner-grow spinner-grow-sm text-secondary align-baseline mx-2" role="status"></i>
</span> </span>
</div> </div>
<div class="col-2 text-center fs-5"> <div class="col-2 text-center fs-5">
<i class="bi bi-plus-slash-minus me-2" data-bs-action="tooltip" data-bs-title="Differenz der Durchschnitte" ></i> <i class="bi bi-plus-slash-minus me-2" data-bs-action="tooltip" data-bs-title="Differenz der Durchschnitte" ></i>
<span id="diff-score" class="text-warning"> <span id="diff-score" class="text-warning fw-bold">
<i class="spinner-grow spinner-grow-sm text-secondary align-baseline mx-2" role="status"></i> <i class="spinner-grow spinner-grow-sm text-secondary align-baseline mx-2" role="status"></i>
</span> </span>
</div> </div>
<div class="col-3 text-center fs-5 ms-4 pe-0"> <div class="col-3 text-center fs-5 ms-4 pe-0">
<img src="../static/icons/average.svg" alt="Avg" class="img-fluid me-1 align-top" style="height: 1.8rem; filter: invert(0.85);" data-bs-action="tooltip" data-bs-title="Durchschnitt Gegner-Team" /> <i class="bi bi-graph-up me-2" data-bs-action="tooltip" data-bs-title="Durchschnitt Gegner-Team"></i>
<span id="opp-avg-score" class="text-warning"> <span id="opp-avg-score" class="text-warning fw-bold">
<i class="spinner-grow spinner-grow-sm text-secondary align-baseline mx-2" role="status"></i> <i class="spinner-grow spinner-grow-sm text-secondary align-baseline mx-2" role="status"></i>
</span> </span>
</div> </div>
@@ -167,8 +167,14 @@
homeAvgScore.innerText = homeAvg.toFixed(2); homeAvgScore.innerText = homeAvg.toFixed(2);
if (!isNaN(oppAvg)) if (!isNaN(oppAvg))
oppAvgScore.innerText = oppAvg.toFixed(2); oppAvgScore.innerText = oppAvg.toFixed(2);
if (!isNaN(homeAvg) && !isNaN(oppAvg)) if (!isNaN(homeAvg) && !isNaN(oppAvg)) {
diffScore.innerText = (homeAvg - oppAvg).toFixed(2); const diff = (((homeAvg / oppAvg) - 1.0) * 100).toFixed(1);
if (diff > 0)
diffScore.classList.replace('text-warning', 'text-success');
else if (diff < 0)
diffScore.classList.replace('text-warning', 'text-danger');
diffScore.innerText = diff + "%";
}
calcMutex = false; calcMutex = false;
} }