forked from herndonj/dvs_cal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_attendance_worksheets.Rmd
96 lines (73 loc) · 3.54 KB
/
03_attendance_worksheets.Rmd
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
---
title: "Create Attendance Worksheets"
---
Make one blank attendance template for each workshop. Write each blank template to Google Drive as a spreadsheet.
## Library Packages
```{r message=FALSE, warning=FALSE, include=FALSE}
Sys.setenv(TZ="America/New_York")
library(rvest)
library(clock)
library(tidyverse)
library(fs)
library(googlesheets4)
```
## Get Data
Ingest data from web page (LibCal API) & make a column headers template for the attendance sheets that will be written to Google.
### harvest webpage data from LibCal API
this next CODE CHUNK is DISABLED, but designed to rerun the harvest script. INSTEAD skip to the `ingest_csv` code chunk.
```
{r get wrangled data, include=FALSE}
source("01_gather_and_wrangle.R", local = knitr::knit_global())
# or sys.source("your-script.R", envir = knitr::knit_global())
```
Since the API can only be used at the beginning of the semester, and since `01_gather_and_wrangle.R` was already called (by `02_foo.Rmd`) and generated `output/workshops.csv`, here, rather, we will simply ingest the file output/workshops.csv. NOTE: `01_gather_and_wrangle.R`, if run after the beginning fo the semester, will overwrite `workshops.csv`. In this case, use `read_csv()` to import one of the back-up files found in the `output` directory.
```{r ingest csv, message=FALSE, warning=FALSE, include=FALSE}
my_df <- read_csv("output/workshops.csv")
```
### worksheets template header
make a vector of column headings that will become the headings of the google sheests attendance records
```{r}
blank_df <- tibble("Attended (x or blank)" = NA,
"Registration Status (Registered, Waitlist, or Walk-in)" = NA,
"First Name" = NA,
"Last Name" = NA,
"Email" = NA,
"Booking Made" = NA,
"Registration Type" = NA,
"Attendance" = NA,
"Are you affiliated with Duke University, Duke Medical Center, DCRI, or another Duke group?" = NA,
"Academic Status (or other)" = NA,
"Discipline or Affiliation" = NA,
"Institutes, Initiatives, or Program Affiliation" = NA,
"Where did you hear about this event?" = NA,
"Have you consulted with Data and Visualization Services before this workshop?" = NA,
"Would you like to receive more information about DVS events and training?" = NA,
"I'm interested in registering for this workshop because:" = NA,
"If other, describe below:" = NA)
```
## Wrangle
```{r}
my_df <- my_df %>%
bind_cols(blank_df) %>%
rename(`Workshop Date` = date) %>%
select(`Attended (x or blank)`,
`Registration Status (Registered, Waitlist, or Walk-in)`,
`Workshop Date`,
`Workshop Name` = title,
`WorkshopID` = workshop_id,
`First Name`:last_col())
```
## Upload to Google Drive
The following code chunks are manually disabled because they write files to google drive. This is "belt and suspenders" caution. To enable the code-blocks, remove the carriage-return at the end of the third backtick and before the first open curly brace.
After uploaded to Google Account's homedrive, ...
Move to `Google Drive > CDVS > Services > Workshops > [2021 Fall] > Attendance`
```
{r}
workshop_list_to_upload_into_GoogleDrive <- my_df %>%
rowwise() %>%
group_map(tibble) # make each row it's own tibble
walk(
workshop_list_to_upload_into_GoogleDrive,
~ googlesheets4::gs4_create(.$`Workshop Name`, sheets = list(attendance = .))
)
```