Created
June 15, 2018 21:52
-
-
Save westernmagic/68280c9546ced727f6c75b5419ed13c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
chess <- read_lines( | |
"~/Downloads/all_with_filtered_anotations/all_with_filtered_anotations_since1998.txt", | |
skip = 5 | |
) %>% | |
str_split(" ", 18, TRUE) %>% | |
as_tibble %>% | |
rename( | |
id = V1, | |
d = V2, | |
result = V3, | |
welo = V4, | |
belo = V5, | |
len = V6, | |
date_c = V7, | |
resu_c = V8, | |
welo_c = V9, | |
belo_c = V10, | |
edate_c = V11, | |
setup = V12, | |
fen = V13, | |
resu2_c = V14, | |
oyrange = V15, | |
bad_len = V16, | |
hashes = V17, | |
game = V18 | |
) %>% | |
select(-hashes) | |
chess_clean <- chess %>% | |
mutate( | |
id = id %>% as.numeric, | |
date_c = case_when(date_c == "date_false" ~ FALSE, date_c == "date_true" ~ TRUE, TRUE ~ NA), | |
resu_c = case_when(resu_c == "result_false" ~ FALSE, resu_c == "result_true" ~ TRUE, TRUE ~ NA), | |
welo_c = case_when(welo_c == "welo_false" ~ FALSE, welo_c == "welo_true" ~ TRUE, TRUE ~ NA), | |
belo_c = case_when(belo_c == "belo_false" ~ FALSE, belo_c == "belo_true" ~ TRUE, TRUE ~ NA), | |
edate_c = case_when(edate_c == "edate_false" ~ FALSE, edate_c == "edate_true" ~ TRUE, TRUE ~ NA), | |
setup = case_when(setup == "setup_false" ~ FALSE, setup == "setup_true" ~ TRUE, TRUE ~ NA), | |
fen = case_when(fen == "fen_false" ~ FALSE, fen == "fen_true" ~ TRUE, TRUE ~ NA), | |
resu2_c = case_when(resu2_c == "result2_false" ~ FALSE, resu2_c == "result2_true" ~ TRUE, TRUE ~ NA), | |
oyrange = case_when(oyrange == "oyrange_false" ~ FALSE, oyrange == "oyrange_true" ~ TRUE, TRUE ~ NA), | |
bad_len = case_when(bad_len == "blen_false" ~ FALSE, bad_len == "blen_true" ~ TRUE, TRUE ~ NA) | |
) %>% | |
mutate( | |
d = if_else(date_c, as.character(NA), d), | |
result = if_else(resu_c, as.character(NA), result), | |
welo = if_else(welo_c, as.character(NA) , welo), | |
belo = if_else(belo_c, as.character(NA), belo) | |
) %>% | |
select(-date_c, -resu_c, -welo_c, -belo_c) %>% | |
mutate( | |
d = d %>% ymd, | |
welo = welo %>% na_if("None") %>% as.numeric, | |
belo = belo %>% na_if("None") %>% as.numeric, | |
) | |
chess_clean %>% | |
filter(str_detect(game, "^W1\\.")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment