Managed to move sunday to the end of the graph...
This commit is contained in:
parent
5814377cf1
commit
1dd0170a63
@ -150,24 +150,39 @@ func monthlyaveragedaygraph(db *sql.DB, id int, title string) {
|
|||||||
defer ifile.Close()
|
defer ifile.Close()
|
||||||
|
|
||||||
// get the server's data and write it to the file
|
// get the server's data and write it to the file
|
||||||
// TODO: Move sunday (first day in list at 0) to the end...
|
rows, err := db.Query("select "+
|
||||||
rows, err := db.Query("select strftime('%w', created) as weekday, avg(players) from gameservers_serverhistory where server_id = ? and created >= ? group by weekday;", id, LAST_MONTH)
|
"strftime('%w', created) as weekday, avg(players) "+
|
||||||
|
"from gameservers_serverhistory "+
|
||||||
|
"where server_id = ? and created >= ? "+
|
||||||
|
"group by weekday;", id, LAST_MONTH)
|
||||||
checkerror(err)
|
checkerror(err)
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
day int
|
day int
|
||||||
players float64
|
players float64
|
||||||
|
avg_players [7]float64
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Scan in the rows
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err := rows.Scan(&day, &players)
|
err := rows.Scan(&day, &players)
|
||||||
checkerror(err)
|
checkerror(err)
|
||||||
_, err = ifile.WriteString(fmt.Sprintf("%s, %f\n", WEEK_DAYS[day], players))
|
avg_players[day] = players
|
||||||
checkerror(err)
|
|
||||||
}
|
}
|
||||||
err = rows.Err()
|
err = rows.Err()
|
||||||
checkerror(err)
|
checkerror(err)
|
||||||
|
|
||||||
|
// Then write each day's average to the file
|
||||||
|
for i := 1; i <= 6; i++ {
|
||||||
|
_, err = ifile.WriteString(fmt.Sprintf("%s, %f\n", WEEK_DAYS[i], avg_players[i]))
|
||||||
|
checkerror(err)
|
||||||
|
}
|
||||||
|
// Oh hey! Look at what I found! It's sunday!!
|
||||||
|
_, err = ifile.WriteString(fmt.Sprintf("%s, %f\n", WEEK_DAYS[0], avg_players[0]))
|
||||||
|
checkerror(err)
|
||||||
|
// Fucking wankers and their stupid usage of sunday as the first day of week...
|
||||||
|
|
||||||
// run the plotter against the data file
|
// run the plotter against the data file
|
||||||
err = exec.Command("./plot_bar.sh", ifilename, ofilename).Run()
|
err = exec.Command("./plot_bar.sh", ifilename, ofilename).Run()
|
||||||
checkerror(err)
|
checkerror(err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user