add time series

This commit is contained in:
Chris Cromer 2022-09-03 23:03:05 -04:00
parent eb3e6d1f4b
commit 76f4466652
8 changed files with 60 additions and 0 deletions

33
mysql.R
View File

@ -21,3 +21,36 @@ WHERE (
)
GROUP BY g.id;
"
query_get_players <- "
SELECT id, name FROM player;
"
query_game_coin_vs_time <- "
SELECT DISTINCT name, f.coins, CAST((f.elapsed_time / 1000) AS INT) as time
FROM frame f
LEFT JOIN game g ON (f.game_id = g.id)
LEFT JOIN player p ON (g.player_id = p.id)
WHERE (
f.game_id = (
SELECT id FROM game WHERE (won = 1) ORDER BY timestamp DESC LIMIT 1
)
)
ORDER BY f.elapsed_time ASC;
"
query_game_coin_vs_time_start <- "
SELECT DISTINCT(CAST((f.elapsed_time / 1000) AS INT)) AS time, f.coins
FROM frame f
LEFT JOIN game g ON (f.game_id = g.id)
WHERE (
f.game_id = (
SELECT id FROM game WHERE (player_id = "
query_game_coin_vs_time_end <- "
) ORDER BY timestamp DESC LIMIT 1
)
)
GROUP BY CAST((f.elapsed_time / 1000) AS INT)
ORDER BY f.elapsed_time ASC;
"

BIN
out/Christopher Cromer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
out/Cristian Soto.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
out/Jorge Millar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -0,0 +1,27 @@
library(stringi)
result <- dbSendQuery(conn, query_get_players)
players <- fetch(result)
if (nrow(players) > 0) {
for (row in 1:nrow(players)) { # nolint
id <- players[row, "id"]
name <- players[row, "name"]
filename <- stri_trans_general(str = name, id = "Latin-ASCII")
query <- query_game_coin_vs_time_start
query <- paste(query, id)
query <- paste(query, query_game_coin_vs_time_end)
data <- dbGetQuery(conn, query)
time_series <- ts(data[2], start = 0, frequency = 1)
png(file = paste("out/", paste(filename, ".png", sep = ""), sep = ""))
plot(time_series, main = name, yaxt = "n")
axis(2, pretty(c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), n = 12))
}
}