diff --git a/mysql.R b/mysql.R index 1676725..60ca84d 100644 --- a/mysql.R +++ b/mysql.R @@ -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; +" diff --git a/out/Christopher Cromer.png b/out/Christopher Cromer.png new file mode 100644 index 0000000..7e238ec Binary files /dev/null and b/out/Christopher Cromer.png differ diff --git a/out/Cristian Soto.png b/out/Cristian Soto.png new file mode 100644 index 0000000..5603945 Binary files /dev/null and b/out/Cristian Soto.png differ diff --git a/out/Felipe Munoz Sanchez.png b/out/Felipe Munoz Sanchez.png new file mode 100644 index 0000000..523efa7 Binary files /dev/null and b/out/Felipe Munoz Sanchez.png differ diff --git a/out/Francisco Fernando Munoz Coletti.png b/out/Francisco Fernando Munoz Coletti.png new file mode 100644 index 0000000..b0536b6 Binary files /dev/null and b/out/Francisco Fernando Munoz Coletti.png differ diff --git a/out/Jorge Millar.png b/out/Jorge Millar.png new file mode 100644 index 0000000..d1f79a9 Binary files /dev/null and b/out/Jorge Millar.png differ diff --git a/out/Martin Araneda Acuna.png b/out/Martin Araneda Acuna.png new file mode 100644 index 0000000..11a92ed Binary files /dev/null and b/out/Martin Araneda Acuna.png differ diff --git a/time_series.R b/time_series.R index e69de29..079b992 100644 --- a/time_series.R +++ b/time_series.R @@ -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)) + } +}