r/golang • u/VastDesign9517 • 16h ago
Data Analytics Question
Good morning,
I am making a star craft 2 replay analyzer in go, sc2prot reads the replay and gives you a high level api to be able to get the values out,
Here is some Code that I have as a example
type Sample struct {
Loop int64
Time time.Duration
PlayerID int64
Minerals int64
Gas int64
MineralCollectionRate int64
GasCollectionRate int64
ActiveWorkers int64
CurrentSupply float64
SupplyCapacity float64
}
type Economy []Sample
func NewFromReplay(r *rep.Rep, playerId int64) Economy {
var economy Economy
for _, event := range r.TrackerEvents.Events {
matchTime := time.Duration(event.Loop() * 44_642_857 // blizz why?
sample := Sample{
Loop: event.Loop(),
Time: matchTime,
PlayerID: event.Int("playerId"),
Minerals: event.Int("stats", "scoreValueMineralsCurrent"),
MineralCollectionRate:event.Int("stats","scoreValueMineralsCollectionRate",
GasCollectionRate: event.Int("stats","scoreValueVespeneCollectionRate"),
Gas: event.Int("stats", "scoreValueVespeneCurrent"),
ActiveWorkers: event.Int("stats", "scoreValueWorkersActiveCount"),
CurrentSupply: float64(event.Int("stats", "scoreValueFoodUsed")) / 4096,
SupplyCapacity: float64(event.Int("stats", "scoreValueFoodMade")) / 4096,
}
economy = append(economy, sample)
}
return economy
}
// MaxMinerals returns the highest recorded mineral balance.
// It returns 0 for an empty economy.
func (samples Economy) MaxMinerals() int64 {
if len(samples) == 0 {
return 0
}
var maxMinerals int64
for _, sample := range samples {
maxMinerals = max(maxMinerals, sample.Minerals)
}
return maxMinerals
}
then in main.go
func main() {
// open the replay file
r, err := rep.NewFromFile(replay.SC2Replay) // Hardcoded for now
if err != nil {
panic(err)
}
defer r.Close()
fmt.Println("Replay file opened successfully")
fmt.Println("[Map]:", r.Details.Title())
for _, player := range r.Details.Players() {
fmt.Println(player.Name, player.RaceString(), player.Result())
}
economy := e.NewFromReplay(r, 1)
fmt.Println("Max Minerals", economy.MaxMinerals())
}
this is the direction I have been taking as of recent is just methods, but when you think about something like polars or pandas it's really tedious,
I am sure someone is going to say why not just use python? Honestly I don't enjoy python at all, I never feel like I am getting a grip on the language, every new package you install requires a relearning all over again. I want to be the programmer and solve problems with my tool kit, not solve my toolkit over and over again,
My job is also doing data analytics so this ties to that as well.
I would love to hear your opinion on this