Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions decoder/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ type areaPokemonCountDetail struct {
ivCount map[pokemonForm]int
}

type raidPokemonKey struct {
pokemonId int16
formId int
tempEvoId int
}

type areaRaidCountDetail struct {
count map[pokemonForm]int
count map[raidPokemonKey]int
}

type areaInvasionCountDetail struct {
Expand Down Expand Up @@ -471,13 +477,14 @@ func updateRaidStats(gym *Gym, areas []geo.AreaName) {
countStats := raidCount[area]
raidLevel := gym.RaidLevel.ValueOrZero()
if countStats[raidLevel] == nil {
countStats[raidLevel] = &areaRaidCountDetail{count: make(map[pokemonForm]int)}
countStats[raidLevel] = &areaRaidCountDetail{count: make(map[raidPokemonKey]int)}
}
pf := pokemonForm{
rk := raidPokemonKey{
pokemonId: int16(gym.RaidPokemonId.ValueOrZero()),
formId: int(gym.RaidPokemonForm.ValueOrZero()),
tempEvoId: int(gym.RaidPokemonEvolution.ValueOrZero()),
}
countStats[raidLevel].count[pf]++
countStats[raidLevel].count[rk]++
}
}

Expand Down Expand Up @@ -858,6 +865,7 @@ type raidStatsDbRow struct {
Level int64 `db:"level"`
PokemonId int `db:"pokemon_id"`
FormId int `db:"form_id"`
TempEvoId int `db:"temp_evo_id"`
Count int `db:"count"`
}

Expand All @@ -876,14 +884,15 @@ func logRaidStats(statsDb *sqlx.DB) {
midnightString := t.Format("2006-01-02")

for area, stats := range currentStats {
addRows := func(rows *[]raidStatsDbRow, level int64, pokemonId int, formId int, count int) {
addRows := func(rows *[]raidStatsDbRow, level int64, rk raidPokemonKey, count int) {
*rows = append(*rows, raidStatsDbRow{
Date: midnightString,
Area: area.Parent,
Fence: area.Name,
Level: level,
PokemonId: pokemonId,
FormId: formId,
PokemonId: int(rk.pokemonId),
FormId: rk.formId,
TempEvoId: rk.tempEvoId,
Count: count,
})
}
Expand All @@ -892,9 +901,9 @@ func logRaidStats(statsDb *sqlx.DB) {
if raidDetail.count == nil {
continue // nothing to do
}
for pf, count := range raidDetail.count {
for rk, count := range raidDetail.count {
if count > 0 {
addRows(&rows, level, int(pf.pokemonId), pf.formId, count)
addRows(&rows, level, rk, count)
}
}
}
Expand All @@ -909,8 +918,8 @@ func logRaidStats(statsDb *sqlx.DB) {
batchRows := rows[i:end]
_, err := statsDb.NamedExec(
"INSERT INTO raid_stats "+
"(date, area, fence, level, pokemon_id, form_id, `count`)"+
" VALUES (:date, :area, :fence, :level, :pokemon_id, :form_id, :count)"+
"(date, area, fence, level, pokemon_id, form_id, temp_evo_id, `count`)"+
" VALUES (:date, :area, :fence, :level, :pokemon_id, :form_id, :temp_evo_id, :count)"+
" ON DUPLICATE KEY UPDATE `count` = `count` + VALUES(`count`);", batchRows)
if err != nil {
log.Errorf("Error inserting raid_stats: %v", err)
Expand Down
8 changes: 8 additions & 0 deletions sql/52_raid_stats_temp_evo_id.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE raid_stats
ADD COLUMN temp_evo_id SMALLINT UNSIGNED NOT NULL DEFAULT 0 AFTER form_id;

ALTER TABLE raid_stats
DROP PRIMARY KEY;

ALTER TABLE raid_stats
ADD PRIMARY KEY (date, area, fence, pokemon_id, form_id, temp_evo_id, level);
Loading