tribe dominance should be calculated based on the number of player villages, a number of barbarian villages should include a number of bonus villages (server stats)

This commit is contained in:
Dawid Wysokiński 2020-06-21 13:26:20 +02:00 committed by Kichiyaki
parent 1a07278d62
commit 0ee2f8f52d
3 changed files with 14 additions and 2 deletions

View File

@ -7,6 +7,8 @@ import (
"io"
"io/ioutil"
"net/http"
"github.com/tribalwarshelp/shared/models"
)
func uncompressAndGetCsvLines(r io.Reader) ([][]string, error) {
@ -43,3 +45,13 @@ func getXML(url string, decode interface{}) error {
}
return xml.Unmarshal(bytes, decode)
}
func countPlayerVillages(villages []*models.Village) int {
count := 0
for _, village := range villages {
if village.PlayerID != 0 {
count++
}
}
return count
}

View File

@ -399,7 +399,7 @@ func (h *updateServerDataHandler) update() error {
}
numberOfVillages := len(villages)
tribes, err := h.getTribes(tod, numberOfVillages)
tribes, err := h.getTribes(tod, countPlayerVillages(villages))
if err != nil {
return err
}

View File

@ -34,7 +34,7 @@ func (h *updateServerStatsHandler) prepare() (*models.ServerStats, error) {
}
tribes := activeTribes + inactiveTribes
barbarianVillages, err := h.db.Model(&models.Village{}).Where("player_id = 0 AND bonus = 0").Count()
barbarianVillages, err := h.db.Model(&models.Village{}).Where("player_id = 0").Count()
if err != nil {
return nil, errors.Wrap(err, "cannot count barbarian villages")
}