10 "github.com/jmoiron/sqlx"
14 const DefaultStartGameID = 0
15 const DefaultEndGameID = -1
16 const DefaultRankingWindowDays = 7
19 // database connection string
22 // the starting game_id in the games table
25 // the ending game_id in the games table
28 // the number of days constituting the ranking window
32 func loadConfig(path string) (*Config, error) {
36 config.ConnStr = "user=xonstat host=localhost dbname=xonstatdb sslmode=disable"
37 config.StartGameID = DefaultStartGameID
38 config.EndGameID = DefaultEndGameID
39 config.RankingWindowDays = DefaultRankingWindowDays
41 file, err := os.Open(path)
43 fmt.Println("Failed opening the file.")
47 decoder := json.NewDecoder(file)
49 // overwrite in-mem config with new values
50 err = decoder.Decode(config)
52 fmt.Println("Failed to decode the JSON.")
59 type GameProcessor struct {
64 func NewGameProcessor(config Config) *GameProcessor {
65 processor := new(GameProcessor)
67 db, err := sqlx.Connect("postgres", config.ConnStr)
76 func (gp *GameProcessor) GameIDsInRange() []int {
77 gameIDs := make([]int, 0)
78 // fetch game_ids using gp.db
83 path := flag.String("config", "xs_glicko.json", "configuration file path")
84 start := flag.Int("start", DefaultStartGameID, "starting game_id")
85 end := flag.Int("end", DefaultEndGameID, "ending game_id")
86 days := flag.Int("days", DefaultRankingWindowDays, "number of days in the ranking window")
89 config, err := loadConfig(*path)
91 log.Fatalf("Unable to load config file: %s.\n", err)
94 if *start != DefaultStartGameID {
95 config.StartGameID = *start
98 if *end != DefaultEndGameID {
99 config.EndGameID = *end
102 if *days != DefaultRankingWindowDays {
103 config.RankingWindowDays = *days
106 processor := NewGameProcessor(*config)
107 fmt.Printf("%+v\n", processor)