]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Connect to the DB and pass it to a GameProcessor.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 3 Dec 2017 15:25:07 +0000 (10:25 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 3 Dec 2017 15:25:07 +0000 (10:25 -0500)
xonstat/util/xs_glicko.go

index 8bdcca4ee23f097e935b224dfd9d66b7828d9955..a90751f1ca05e4d982e5527a85782fbdec89fb30 100644 (file)
@@ -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)
 }