-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplate.qmd
More file actions
337 lines (247 loc) · 8.91 KB
/
Template.qmd
File metadata and controls
337 lines (247 loc) · 8.91 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
---
title: "Weekly Pass Use Comparison"
subtitle: "First Full Week of January"
theme: _brand.yml
execute:
echo: false
format: html
---
```{r}
#| label: libraries
#| warning: false
library(DT)
library(tidyverse)
# library(rsconnect)
```
```{r eval=FALSE}
# rsconnect::writeManifest()
```
```{r}
#| label: data
ay_2024 <- read_rds("2024.rds")
ay_2025 <- read_rds("2025.rds")
ay_2026 <- read_rds("2026.rds")
full_data <- rbind(ay_2024, ay_2025, ay_2026)
```
```{r}
# create new columns to make it easier to select specific academic years
full_data <- full_data |>
mutate(visit_24 = ifelse(year(Date) == 2024, 1, 0),
visit_25 = ifelse(year(Date) == 2025, 1, 0),
visit_26 = ifelse(year(Date) == 2026, 1, 0))
```
```{r}
#| label: sort facility data
south_rec <- full_data |>
filter(Facility == "1")
north_rec <- full_data |>
filter(Facility == "2")
bd_rec <- full_data |>
filter(Facility == "3")
s91 <- full_data |>
filter(Facility == "4")
unassigned <- full_data |>
filter(Facility == "5")
```
```{r}
#| label: build functions for datasets
# Function to create pass comparison with totals
create_pass_comparison <- function(data) {
# Calculate totals
totals <- data |>
summarize(
Pass_Type = "Total",
Visits24 = sum(visit_24, na.rm = TRUE),
Visits25 = sum(visit_25, na.rm = TRUE),
Visits26 = sum(visit_26, na.rm = TRUE)
)
# Calculate by pass type
by_pass <- data |>
group_by(Pass_Type) |>
summarize(
Visits24 = sum(visit_24, na.rm = TRUE),
Visits25 = sum(visit_25, na.rm = TRUE),
Visits26 = sum(visit_26, na.rm = TRUE),
.groups = "drop"
)
# Combine and return
bind_rows(totals, by_pass)
}
# function to create comparison plots
create_plot <- function(data, title, y_limit = NULL, subtitle = "First Week of January", padding = 1.15) {
# Prepare data
plot_data <- data |>
mutate(Day = wday(Date, label = TRUE, abbr = FALSE),
Year = year(Date)) |>
group_by(Day, Year) |>
summarize(TotalVisits = n(), .groups = "drop") |>
complete(Day = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"),
Year,
fill = list(TotalVisits = 0)) |>
mutate(Day = factor(Day, levels = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")))
if (is.null(y_limit)) {
y_limit <- max(plot_data$TotalVisits, na.rm = TRUE) * padding
}
# Calculate averages
mean_24 <- plot_data |>
filter(Year == 2024) |>
summarize(mean.visits = mean(TotalVisits)) |>
pull(mean.visits)
mean_25 <- plot_data |>
filter(Year == 2025) |>
summarize(mean.visits = mean(TotalVisits)) |>
pull(mean.visits)
mean_26 <- plot_data |>
filter(Year == 2026) |>
summarize(mean.visits = mean(TotalVisits)) |>
pull(mean.visits)
# Create plot
ggplot(plot_data, aes(x = Day, y = TotalVisits, color = factor(Year), group = Year)) +
geom_line(linewidth = 0.8) +
geom_point(aes(fill = factor(Year)), size = 2.3, shape = 21, color = "white", stroke = 1) +
scale_color_manual(
values = c("2024" = "gray70", "2025" = "gray40", "2026" = "#AB0520"),
name = "Year") +
scale_fill_manual(
values = c("2024" = "gray70", "2025" = "gray40", "2026" = "#AB0520"),
name = "Year") +
scale_y_continuous(expand = c(0, 0), limits = c(0, y_limit)) +
labs(
title = title,
subtitle = subtitle,
x = "Day of Week",
y = "Total Visits") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
annotate("label", x = Inf, y = Inf,
label = paste("2024 Avg:", round(mean_24), "\n2025 Avg:", round(mean_25), "\n2026 Avg:", round(mean_26)),
hjust = 1, vjust = 1,
fill = "white", alpha = 0.8, size = 3,
color = "black")
}
# function for data tables
comparison_table <- function(data,
page_length = 15,
total_col = "Pass_Type") {
datatable(data, options = list(pageLength = page_length)) |>
formatStyle(
columns = 1:ncol(data),
target = "row",
fontWeight = styleEqual("Total", "bold"),
valueColumns = total_col)
}
```
```{r}
#| label: create data to visualize
# apply functions to create dataset
TotalPassCompare <- create_pass_comparison(full_data)
SRECPassCompare <- create_pass_comparison(south_rec)
NRECPassCompare <- create_pass_comparison(north_rec)
bd_recPassCompare <- create_pass_comparison(bd_rec)
s91PassCompare <- create_pass_comparison(s91)
unassignedCompare <- create_pass_comparison(unassigned)
TotalPlotFinal <- create_plot(full_data, "Total Pass Usage by Day of the Week")
SouthPlot <- create_plot(south_rec, "South Rec Pass Usage by Day of the Week")
NorthPlot <- create_plot(north_rec, "North Rec Visits by Day of the Week")
BDPlot <- create_plot(bd_rec, "Bear Down Rec Pass Usage by Day of the Week")
s91Plot <- create_plot(s91, "Studio 91 Pass Usage by Day of the Week")
unassignedPlot <- create_plot(unassigned, "Unassigned Pass Usage by Day of the Week")
SenSource <- tibble(Facility = "Bear Down Building", Visits24 = "6373", Visits25 = "1688", Visits26 = "1486")
facility_overview <- bind_rows(
TotalPassCompare |> filter(Pass_Type == "Total") |> mutate(Facility = "Total Campus"),
SRECPassCompare |> filter(Pass_Type == "Total") |> mutate(Facility = "South Rec"),
NRECPassCompare |> filter(Pass_Type == "Total") |> mutate(Facility = "North Rec"),
bd_recPassCompare |> filter(Pass_Type == "Total") |> mutate(Facility = "Bear Down Rec"),
s91PassCompare |> filter(Pass_Type == "Total") |> mutate(Facility = "Studio 91"),
) |>
select(Facility, Visits24, Visits25, Visits26) |>
mutate(across(c(Visits24, Visits25, Visits26), as.character)) |>
bind_rows(SenSource)
```
### Overview
```{r}
datatable(
facility_overview,
options = list(
pageLength = 10,
dom = 't'
)
) |>
formatStyle(
columns = 1:ncol(facility_overview),
target = "row",
fontWeight = styleEqual("Total Campus", "bay_2024"),
valueColumns = "Facility"
)
```
<br>
Some notes about last week:
* In 2024, classes began a week earlier, explaining the spike in traffic for 2024.
* Bear Down Rec doesn't show any activity from 1.6.2024 to 1.21.2024. If this doesn't seem right, let me know and I can dig in to see if the numbers are elsewhere. If there was a closure or gap in staff, you can expect to see the numbers for Bear Down Rec again beginning the last week in January.
* Same situation may be true for Studio 91 this January.
Percent change when comparing 2024 visits to 2026: `r round(((TotalPassCompare[1, 4] / TotalPassCompare[1, 2]) - 1) * 100, 1)`%
Percent change when comparing 2025 visits to 2026: `r round(((TotalPassCompare[1, 4] / TotalPassCompare[1, 3]) - 1) * 100, 1)`%
### Weekly Review
::: {.panel-tabset}
### Total Campus
```{r}
#| label: Plot total visits
print(TotalPlotFinal)
```
```{r}
#| label: build datatable for all visits
comparison_table(TotalPassCompare)
```
### South Rec
```{r}
#| label: Plot SREC
print(SouthPlot)
```
```{r}
#| label: build datatable for SREC
comparison_table(SRECPassCompare)
```
### North Rec
```{r}
#| label: Plot NREC
print(NorthPlot)
```
```{r}
#| label: build NREC datatable
comparison_table(NRECPassCompare)
```
### Bear Down Rec
```{r}
#| label: Plot bd_rec
print(BDPlot)
```
```{r}
#| label: build datatable for bd_rec
comparison_table(bd_recPassCompare)
```
### Studio 91
```{r}
#| label: Studio 91 plot
print(s91Plot)
```
```{r}
#| label: build datatable for s91
comparison_table(s91PassCompare)
```
### Unassigned
```{r}
#| label: unassigned plot
print(unassignedPlot)
```
```{r}
#| label: build datatable for unassigned
comparison_table(unassignedCompare)
```
:::
<br>
**Why is there an "unassigned" tab?**
Mostly, these are passes counted for specific classes that aren't tied to a facility. Sometimes it'll catch student passes. They're here to ensure everything is complete.
**Why is the total number of visits different from the Pass Visit Log summary in RecTrac?**
To capture all pass usage, I've included additional passes, like Group Fitness passes, and excluded CREC Employee passes. So there is some overlap between students swiping in and then checking-in to their program. I've also hard-coded a two-minute coay_2024own for swipes, which doesn't appear to be applied to the Pass Visit Log in RecTrac.
**Why isn't my program or pass represented in this report?**
Great question. [Email me](mailto:jcbetts@arizona.edu?subject=Weekly%20Pass%20Report%20Question(s)) and we'll work to get it added!