Ugh, I hate multiple params for the same func...
This commit is contained in:
parent
1ddec78fc0
commit
5814377cf1
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
# arg 1: path to file with the raw data
|
# arg 1: path to file with the raw data
|
||||||
# arg 2: path to file to save the graph in (.png will be appended)
|
# arg 2: path to file to save the graph in (.png will be appended)
|
||||||
# arg 3: periodic sampling of data, see http://gnuplot.info/docs_4.2/node121.html
|
|
||||||
|
|
||||||
gnuplot << EOF
|
gnuplot << EOF
|
||||||
set datafile separator ","
|
set datafile separator ","
|
||||||
@ -17,6 +16,8 @@ set grid
|
|||||||
unset key
|
unset key
|
||||||
set terminal png size 800,200 transparent truecolor
|
set terminal png size 800,200 transparent truecolor
|
||||||
set output "$2.png"
|
set output "$2.png"
|
||||||
|
set xtics rotate
|
||||||
|
set format x "%H:%M\n%d/%m"
|
||||||
|
|
||||||
plot "$1" every $3 using 1:2 linewidth 2
|
plot "$1" using 1:2 linewidth 2
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
@ -53,10 +52,9 @@ func main() {
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err := rows.Scan(&id, &title)
|
err := rows.Scan(&id, &title)
|
||||||
checkerror(err)
|
checkerror(err)
|
||||||
// stats are updated 4 times per hour, so: 2 = 30 min, 24 = 6 hours
|
weeklyhistorygraph(db, id, title)
|
||||||
createtimegraph(db, "week-time-", id, title, LAST_WEEK, 4)
|
monthlyhistorygraph(db, id, title)
|
||||||
createtimegraph(db, "month-time-", id, title, LAST_MONTH, 24)
|
monthlyaveragedaygraph(db, id, title)
|
||||||
createweekdaygraph(db, "month-avg_day-", id, title, LAST_MONTH)
|
|
||||||
}
|
}
|
||||||
err = rows.Err()
|
err = rows.Err()
|
||||||
checkerror(err)
|
checkerror(err)
|
||||||
@ -82,12 +80,13 @@ func setuptemppaths(prefix string, title string) (f *os.File, name string, path
|
|||||||
return file, file.Name(), path
|
return file, file.Name(), path
|
||||||
}
|
}
|
||||||
|
|
||||||
func createtimegraph(db *sql.DB, prefix string, id int, title string, period time.Time, every int) {
|
func weeklyhistorygraph(db *sql.DB, id int, title string) {
|
||||||
|
prefix := "week-time-"
|
||||||
ifile, ifilename, ofilename := setuptemppaths(prefix, title)
|
ifile, ifilename, ofilename := setuptemppaths(prefix, title)
|
||||||
defer ifile.Close()
|
defer ifile.Close()
|
||||||
|
|
||||||
// get the server's data and write it to the file
|
// Rows for server, newer then LAST_WEEK and only on the hour
|
||||||
rows, err := db.Query("select created,players from gameservers_serverhistory where server_id = ? and created >= ? order by created asc", id, period)
|
rows, err := db.Query("select created,players from gameservers_serverhistory where server_id = ? and created >= ? and strftime('%M', created) = '00' order by created asc", id, LAST_WEEK)
|
||||||
checkerror(err)
|
checkerror(err)
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
@ -105,7 +104,7 @@ func createtimegraph(db *sql.DB, prefix string, id int, title string, period tim
|
|||||||
checkerror(err)
|
checkerror(err)
|
||||||
|
|
||||||
// run the plotter against the data file
|
// run the plotter against the data file
|
||||||
err = exec.Command("./plot_time.sh", ifilename, ofilename, strconv.Itoa(every)).Run()
|
err = exec.Command("./plot_time.sh", ifilename, ofilename).Run()
|
||||||
checkerror(err)
|
checkerror(err)
|
||||||
|
|
||||||
// close and remove the tmp file
|
// close and remove the tmp file
|
||||||
@ -113,13 +112,46 @@ func createtimegraph(db *sql.DB, prefix string, id int, title string, period tim
|
|||||||
os.Remove(ifilename)
|
os.Remove(ifilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createweekdaygraph(db *sql.DB, prefix string, id int, title string, period time.Time) {
|
func monthlyhistorygraph(db *sql.DB, id int, title string) {
|
||||||
|
prefix := "month-time-"
|
||||||
|
ifile, ifilename, ofilename := setuptemppaths(prefix, title)
|
||||||
|
defer ifile.Close()
|
||||||
|
|
||||||
|
// Rows for server, newer then LAST_WEEK and only every 6th hour
|
||||||
|
rows, err := db.Query("select created,players from gameservers_serverhistory where server_id = ? and created >= ? and strftime('%M', created) = '00' and strftime('%H', created) in ('00', '06', '12', '18') order by created asc", id, LAST_MONTH)
|
||||||
|
checkerror(err)
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
var (
|
||||||
|
created time.Time
|
||||||
|
players int
|
||||||
|
)
|
||||||
|
for rows.Next() {
|
||||||
|
err := rows.Scan(&created, &players)
|
||||||
|
checkerror(err)
|
||||||
|
_, err = ifile.WriteString(fmt.Sprintf("%d, %d\n", created.Unix(), players))
|
||||||
|
checkerror(err)
|
||||||
|
}
|
||||||
|
err = rows.Err()
|
||||||
|
checkerror(err)
|
||||||
|
|
||||||
|
// run the plotter against the data file
|
||||||
|
err = exec.Command("./plot_time.sh", ifilename, ofilename).Run()
|
||||||
|
checkerror(err)
|
||||||
|
|
||||||
|
// close and remove the tmp file
|
||||||
|
ifile.Close()
|
||||||
|
os.Remove(ifilename)
|
||||||
|
}
|
||||||
|
|
||||||
|
func monthlyaveragedaygraph(db *sql.DB, id int, title string) {
|
||||||
|
prefix := "month-avg_day-"
|
||||||
ifile, ifilename, ofilename := setuptemppaths(prefix, title)
|
ifile, ifilename, ofilename := setuptemppaths(prefix, title)
|
||||||
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...
|
// TODO: Move sunday (first day in list at 0) to the end...
|
||||||
rows, err := db.Query("select strftime('%w', created) as weekday, avg(players) from gameservers_serverhistory where server_id = ? and created >= ? group by weekday;", id, period)
|
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)
|
||||||
checkerror(err)
|
checkerror(err)
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user