statistics/mysql.R

57 lines
1.2 KiB
R
Raw Normal View History

2022-09-02 17:06:02 -04:00
library(RMySQL)
2022-09-03 18:54:56 -04:00
conn <- dbConnect(
2022-09-02 17:06:02 -04:00
MySQL(),
user = dbuser,
password = dbpass,
dbname = dbname,
host = dbhost,
port = dbport
)
2022-09-03 18:54:56 -04:00
2022-09-03 19:01:20 -04:00
query_frames <- "
2022-09-03 18:54:56 -04:00
SELECT
f.coins, CAST((f.elapsed_time / 1000) AS INT)
FROM game g
LEFT JOIN frame f ON (f.game_id = g.id)
WHERE (
f.id = (
SELECT id FROM frame WHERE game_id = g.id ORDER BY elapsed_time DESC LIMIT 1
)
)
GROUP BY g.id;
"
2022-09-03 23:03:05 -04:00
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;
"