From: Ant Zucaro Date: Sun, 3 Dec 2017 15:25:07 +0000 (-0500) Subject: Connect to the DB and pass it to a GameProcessor. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7f6f392ab5ba354be8fae0cb3cb288728df1a84e;p=xonotic%2Fxonstat.git Connect to the DB and pass it to a GameProcessor. --- diff --git a/xonstat/util/xs_glicko.go b/xonstat/util/xs_glicko.go index 8bdcca4..a90751f 100644 --- a/xonstat/util/xs_glicko.go +++ b/xonstat/util/xs_glicko.go @@ -6,6 +6,9 @@ import ( "fmt" "log" "os" + + "github.com/jmoiron/sqlx" + _ "github.com/lib/pq" ) const DefaultStartGameID = 0 @@ -53,6 +56,29 @@ func loadConfig(path string) (*Config, error) { return config, nil } +type GameProcessor struct { + config *Config + db *sqlx.DB +} + +func NewGameProcessor(config Config) *GameProcessor { + processor := new(GameProcessor) + + db, err := sqlx.Connect("postgres", config.ConnStr) + if err != nil { + log.Fatal(err) + } + processor.db = db + + return processor +} + +func (gp *GameProcessor) GameIDsInRange() []int { + gameIDs := make([]int, 0) + // fetch game_ids using gp.db + return gameIDs +} + func main() { path := flag.String("config", "xs_glicko.json", "configuration file path") start := flag.Int("start", DefaultStartGameID, "starting game_id") @@ -77,5 +103,6 @@ func main() { config.RankingWindowDays = *days } - fmt.Printf("%+v\n", config) + processor := NewGameProcessor(*config) + fmt.Printf("%+v\n", processor) }