forked from groene/TK2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparty_utils.R
123 lines (89 loc) · 3.72 KB
/
party_utils.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#
# print("hello")
#
# print(getwd())
all_dat <- readRDS("../data/all_dat.rds")
# print("hello")
sets <- jsonlite::fromJSON("../settings.json")
options(scipen = 999)
# wtm_data %>% count(party,sort = T)
# source("../party_utils.R")
color_dat <- tibble(
colors = c("#00b13d", "#80c31c", "#0a2cca", "#008067", "#bf0000", "#ff0000", "#6f2421", "#02a6e9", "#92107d", "#04d3d4", "#242b57", "#66cdaa", "#242b57", "#006b28", "#012758", "#ea5b0b", "#582c83", "#698c0c", "#fdfd00", "#8da6d6", "#dc1f26", "#FFD700"),
party = c("D66", "GroenLinks", "VVD", "CDA", "SP", "PvdA", "FvD", "ChristenUnie", "50PLUS", "Alliantie", "BVNL", "DENK", "Ja21", "PvdD", "PVV", "SGP", "Volt Nederland", "BBB", "BIJ1", "NSC", "GroenLinks-PvdA", "Libertaire Partij"))
most_left_party <- "VVD"
scale_fill_parties <- function(...){
ggplot2:::manual_scale(
'fill',
values = setNames(color_dat$colors, color_dat$party),
...
)
}
scale_color_parties <- function(...){
ggplot2:::manual_scale(
'color',
values = setNames(color_dat$colors, color_dat$party),
...
)
}
# election_dat30 <- read_rds("https://github.com/groene/TK2023/raw/main/historic/2023-11-17/30.rds") %>%
# # left_join(all_dat) %>%
# rename(internal_id = page_id) %>%
# filter(party != "And") %>%
# filter(is.na(no_data)) %>%
# mutate(party = ifelse(party %in% c("GroenLinks", "PvdA"), "GroenLinks-PvdA", party))
#
# election_dat7 <- read_rds("https://github.com/groene/TK2023/raw/main/historic/2023-11-17/7.rds") %>%
# # left_join(all_dat) %>%
# rename(internal_id = page_id) %>%
# filter(party != "And") %>%
# filter(is.na(no_data)) %>%
# mutate(party = ifelse(party %in% c("GroenLinks", "PvdA"), "GroenLinks-PvdA", party))
election_dat30 <- readRDS("../data/election_dat30.rds") %>%
# left_join(all_dat) %>%
rename(internal_id = page_id) %>%
filter(party != "And") %>%
filter(is.na(no_data)) %>%
mutate(party = ifelse(party %in% c("GroenLinks", "PvdA"), "GroenLinks-PvdA", party))
election_dat7 <- readRDS("../data/election_dat7.rds") %>%
# left_join(all_dat) %>%
rename(internal_id = page_id) %>%
filter(party != "And") %>%
filter(is.na(no_data)) %>%
mutate(party = ifelse(party %in% c("GroenLinks", "PvdA"), "GroenLinks-PvdA", party))
# saveRDS(election_dat30, "../data/election_dat30.rds")
# saveRDS(election_dat7, "../data/election_dat7.rds")
fin <- (as.Date(election_dat30$ds[1])-lubridate::days(1))
begin7 <- fin-lubridate::days(6)
begin30 <- fin-lubridate::days(29)
tibble(fin,
begin7,
begin30) %>%
write_csv("../data/dates.csv")
# Setting the system locale to Dutch for time/date formatting
Sys.setlocale("LC_TIME", "nl_NL")
# Function to create Dutch date strings with suffixes
create_date <- function(x) {
the_date <- format(x, "%e %b") # %e for day of the month without leading zeros, %B for full month name in Dutch
# In Dutch, date suffixes are not commonly used so we can omit the 'append_date_suffix' part
return(trimws(the_date)) # trimws to remove any leading or trailing whitespace which might be left after %e
}
last7days_string <- paste0(create_date(begin7), " - ", create_date(fin), " ", lubridate::year(fin)) %>% str_replace("Oct", "Okt")
last30days_string <- paste0(create_date(begin30), " - ", create_date(fin), " ", lubridate::year(fin)) %>% str_replace("Oct", "Okt")
# # Print the Dutch date range strings
# print(last7days_string)
# print(last30days_string)
#
# # Reset locale back to the original if necessary
# Sys.setlocale("LC_TIME", "C")
the_currency <- election_dat30 %>%
count(main_currency, sort = T) %>%
slice(1) %>%
pull(main_currency)
if(the_currency == "EUR"){
currency_symbol <- "€"
} else if(the_currency=="INR"){
currency_symbol <- "₹"
} else {
currency_symbol <- the_currency
}