generated from maehr/open-research-data-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_missing_info.R
46 lines (35 loc) · 1.71 KB
/
get_missing_info.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Setup -----
## Packages -----
library(httr)
library(dplyr)
library(here)
## External Functions -----
source(here("src", "get_content.R"), local = TRUE)
source(here("src", "get_max_page_number.R"), local = TRUE)
# Definition -----
get_missing_info <- function(input_df) {
missing_results_df <- input_df %>%
filter(konklusion == "")
input_df <- input_df %>%
mutate(ft_for = 0, ft_imod = 0, ft_hverken = 0)
input_df$ft_for[input_df$konklusion != ""] <- NA
input_df$ft_imod[input_df$konklusion != ""] <- NA
input_df$ft_hverken[input_df$konklusion != ""] <- NA
for (p in seq_len(nrow(missing_results_df))) {
temp_NAafst_id <- missing_results_df$id[p]
for (q in seq(0, 100, 100)) { # captures all 179 votes spread out on two pages with max. 100 entries each
temp_NAcontent_results <- paste0("https://oda.ft.dk/api/Afstemning(", temp_NAafst_id, ")/Stemme?$inlinecount=allpages&$skip=", q) %>%
get_content()
for (z in 1:length(temp_NAcontent_results[[3]])) {
vote_type_id <- temp_NAcontent_results[[3]][[z]][[2]]
switch(vote_type_id,
"1" = {input_df[input_df$id == temp_NAafst_id, "ft_for"] <- input_df[input_df$id == temp_NAafst_id, "ft_for"] + 1},
"2" = {input_df[input_df$id == temp_NAafst_id, "ft_imod"] <- input_df[input_df$id == temp_NAafst_id, "ft_imod"] + 1},
#"3" = { temp_sum_fravaer <- temp_sum_fravaer + 1 }, implemented in clean_ballot_results(), since this detail is not included in this particular list
"4" = {input_df[input_df$id == temp_NAafst_id, "ft_hverken"] <- input_df[input_df$id == temp_NAafst_id, "ft_hverken"] + 1}
)
}
}
}
return(input_df)
}