Skip to content

Commit 0f1a2a5

Browse files
committed
Merge branch 'add_vacancy_history_to_dashboard'
1 parent 9ea0fbe commit 0f1a2a5

7 files changed

Lines changed: 6087 additions & 5996 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.Rproj
44
*.html
55
.Rhistory
6+
.superpowers/

dashboard.qmd

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ format:
1515
href: https://botsin.space/@bcchildcarebot
1616
- icon: house-fill
1717
href: https://victoryuan.com/
18-
editor_options:
18+
editor_options:
1919
chunk_output_type: console
20+
params:
21+
fast_render: false
2022
---
2123

2224
```{r load_libraries}
@@ -36,6 +38,26 @@ library(tippy)
3638
url <- 'https://catalogue.data.gov.bc.ca/dataset/4cc207cc-ff03-44f8-8c5f-415af5224646/resource/9a9f14e1-03ea-4a11-936a-6e77b15eeb39/download/childcare_locations.csv'
3739
bccc <- readr::read_csv(url)
3840
.today <- lubridate::today(tzone = 'Canada/Pacific')
41+
42+
if (file.exists("data/vacancy_history.csv")) {
43+
history <- readr::read_csv(
44+
"data/vacancy_history.csv",
45+
col_types = readr::cols(
46+
FAC_PARTY_ID = readr::col_integer(),
47+
last_vacancy_under36 = readr::col_date(),
48+
last_vacancy_30mos_5yrs = readr::col_date(),
49+
last_vacancy_licpre = readr::col_date(),
50+
last_vacancy_gr1_age12 = readr::col_date(),
51+
.default = readr::col_skip()
52+
)
53+
)
54+
bccc <- dplyr::left_join(bccc, history, by = "FAC_PARTY_ID")
55+
} else {
56+
bccc$last_vacancy_under36 <- NA_Date_
57+
bccc$last_vacancy_30mos_5yrs <- NA_Date_
58+
bccc$last_vacancy_licpre <- NA_Date_
59+
bccc$last_vacancy_gr1_age12 <- NA_Date_
60+
}
3961
```
4062

4163

@@ -44,6 +66,10 @@ bccc <- readr::read_csv(url)
4466
# latest vacancy update
4567
dataset_last_update <- max(bccc$VACANCY_LAST_UPDATE, na.rm = TRUE)
4668
69+
if (isTRUE(params$fast_render)) {
70+
bccc <- bccc |> dplyr::filter(VACANCY_LAST_UPDATE >= dataset_last_update - 3)
71+
}
72+
4773
tbl_data <- bccc |>
4874
4975
# filter to last vacancy update - 14 days
@@ -70,18 +96,39 @@ tbl_data <- bccc |>
7096
select(NAME, everything()) |>
7197
7298
mutate(
99+
lbl_under36 = if_else(
100+
!is.na(last_vacancy_under36),
101+
paste0(" (last seen ", format(last_vacancy_under36, "%Y-%m-%d"), ")"),
102+
""
103+
),
104+
lbl_30mos = if_else(
105+
!is.na(last_vacancy_30mos_5yrs),
106+
paste0(" (last seen ", format(last_vacancy_30mos_5yrs, "%Y-%m-%d"), ")"),
107+
""
108+
),
109+
lbl_licpre = if_else(
110+
!is.na(last_vacancy_licpre),
111+
paste0(" (last seen ", format(last_vacancy_licpre, "%Y-%m-%d"), ")"),
112+
""
113+
),
114+
lbl_gr1 = if_else(
115+
!is.na(last_vacancy_gr1_age12),
116+
paste0(" (last seen ", format(last_vacancy_gr1_age12, "%Y-%m-%d"), ")"),
117+
""
118+
),
73119
popup = glue::glue(
74120
"<b>{NAME}</b>",
75121
"{SERVICE_TYPE_CD}",
76122
"{PHONE}",
77123
"<br>Vacancy:",
78-
"&nbsp;&nbsp;&nbsp;&nbsp;<36 months: {VACANCY_SRVC_UNDER36}",
79-
"&nbsp;&nbsp;&nbsp;&nbsp;30 months -- 5 years: {VACANCY_SRVC_30MOS_5YRS}",
80-
"&nbsp;&nbsp;&nbsp;&nbsp;Preschool: {VACANCY_SRVC_LICPRE}",
81-
"&nbsp;&nbsp;&nbsp;&nbsp;Grade 1 - Age 12: {VACANCY_SRVC_OOS_GR1_AGE12}",
124+
"&nbsp;&nbsp;&nbsp;&nbsp;<36 months: {VACANCY_SRVC_UNDER36}{lbl_under36}",
125+
"&nbsp;&nbsp;&nbsp;&nbsp;30 months - 5 years: {VACANCY_SRVC_30MOS_5YRS}{lbl_30mos}",
126+
"&nbsp;&nbsp;&nbsp;&nbsp;Preschool: {VACANCY_SRVC_LICPRE}{lbl_licpre}",
127+
"&nbsp;&nbsp;&nbsp;&nbsp;Grade 1 - Age 12: {VACANCY_SRVC_OOS_GR1_AGE12}{lbl_gr1}",
82128
.sep = "<br>"
83129
)
84130
) |>
131+
select(-starts_with("lbl_")) |>
85132
86133
# crosstalk key
87134
mutate(id = row_number()) |>
@@ -380,15 +427,42 @@ row_details <- function(index, bccc) {
380427
df_field(
381428
"Vacancy type",
382429
reactable(
383-
bccc |>
384-
select(contains('VACANCY_SRVC_')) |>
385-
pivot_longer(
386-
everything(),
387-
names_to = 'Age Group',
388-
values_to = 'Vacancy?',
389-
names_prefix = 'VACANCY_SRVC_'
390-
) |>
391-
mutate(`Vacancy?` = ifelse(!is.na(`Vacancy?`), 'Y', 'N')),
430+
tibble::tibble(
431+
`Age Group` = c(
432+
"Under 36 months",
433+
"30 months - 5 years",
434+
"Licensed Pre-school",
435+
"Grade 1 - Age 12"
436+
),
437+
`Vacancy?` = c(
438+
ifelse(!is.na(bccc$VACANCY_SRVC_UNDER36), "Y", "N"),
439+
ifelse(!is.na(bccc$VACANCY_SRVC_30MOS_5YRS), "Y", "N"),
440+
ifelse(!is.na(bccc$VACANCY_SRVC_LICPRE), "Y", "N"),
441+
ifelse(!is.na(bccc$VACANCY_SRVC_OOS_GR1_AGE12), "Y", "N")
442+
),
443+
`Last vacancy` = c(
444+
ifelse(
445+
is.na(bccc$last_vacancy_under36),
446+
"Never",
447+
format(bccc$last_vacancy_under36, "%Y-%m-%d")
448+
),
449+
ifelse(
450+
is.na(bccc$last_vacancy_30mos_5yrs),
451+
"Never",
452+
format(bccc$last_vacancy_30mos_5yrs, "%Y-%m-%d")
453+
),
454+
ifelse(
455+
is.na(bccc$last_vacancy_licpre),
456+
"Never",
457+
format(bccc$last_vacancy_licpre, "%Y-%m-%d")
458+
),
459+
ifelse(
460+
is.na(bccc$last_vacancy_gr1_age12),
461+
"Never",
462+
format(bccc$last_vacancy_gr1_age12, "%Y-%m-%d")
463+
)
464+
)
465+
),
392466
pagination = FALSE,
393467
defaultColDef = colDef(headerClass = "header"),
394468
class = "vacancy-table",

0 commit comments

Comments
 (0)