Last active
January 22, 2023 21:01
-
-
Save dubsnipe/d2dc94a23271de2669925ce48e072c51 to your computer and use it in GitHub Desktop.
Script used to calculate attendance to classes for students over Zoom.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(tidyverse) | |
require(lubridate) | |
setwd("") # | |
files <- (Sys.glob("*.csv")) | |
topics <- lapply(files, read.csv, nrows=2, header=T, encoding="UTF-8") | |
topics <- lapply(topics, function(x) x["Topic"][1,]) %>% unlist() | |
ldf <- lapply(files, read.csv, skip=3, header=T, encoding="UTF-8") | |
the_colnames <- c("name", "email", "join_time", "leave_time", "duration", "guest", "topic") | |
for (i in 1:length(ldf)){ | |
ldf[[i]]["topic"] <- topics[i] | |
colnames(ldf[[i]]) <- the_colnames | |
} | |
l2 <- map(ldf,~data.frame(.)) | |
l3 <-map_dfr(l2,~mutate_all(.,as.character)) | |
l4<-as_tibble(l3) | |
l4 <- l4 %>% select(name, join_time, leave_time) | |
l4$join_time <- l4$join_time %>% mdy_hms(tz = "America/El_Salvador") | |
l4$leave_time <- l4$leave_time %>% mdy_hms(tz = "America/El_Salvador") | |
l4$hms_join_time = hms::as_hms(l4$join_time) | |
l4$hms_leave_time = hms::as_hms(l4$leave_time) | |
l4$wday = wday(l4$join_time, week_start = 1) | |
l4 <- l4 %>% mutate(name = str_replace_all(name, "[^a-zA-Z\u00C0-\u017F \\n]", "")) | |
l4$name <- l4$name %>% str_trim() | |
report <- function(l4, class) { | |
entered_late = vector() | |
left_early = vector() | |
duration = vector() | |
l5 <- l4 %>% filter(wday == class[1] & hms(hms_leave_time) < hms(class[3]) + minutes(60) & hms(hms_join_time) > hms(class[2]) - minutes(90)) | |
l5$date <- date(l5$join_time) | |
l5 <- l5 %>% unique() %>% mutate(duration = round(interval(hms_join_time, hms_leave_time, tzone = "America/El_Salvador")/minutes(1), 0)) | |
l5 <- l5 %>% | |
group_by(name, date) %>% | |
summarize(total_duration = sum(duration), across()) %>% | |
select(name, date, wday, hms_join_time, hms_leave_time, total_duration) %>% | |
unique() | |
l6 <- l5 %>% mutate(on_time = hms(hms_join_time) < hms(class[2]) + minutes(30)) %>% | |
unique() | |
l6 <- l6 %>% mutate( | |
above_quantile = total_duration >= l5$total_duration %>% quantile(as.numeric(class[4]))) | |
l7 <- l6 %>% | |
select(name, | |
date, | |
total_duration, | |
join_time=hms_join_time, | |
leave_time=hms_leave_time, | |
on_time, | |
above_quantile) | |
l7 <- l7 %>% | |
group_by(name) %>% | |
# filter(attendances >= 3) %>% | |
unique() | |
l7 <- left_join(l7, | |
l7 %>% | |
group_by(name, date, above_quantile) %>% | |
summarize(on_time = sum(on_time) > 0) %>% | |
mutate(real_attendance = on_time * above_quantile) | |
) | |
return (l7) | |
} | |
# class_1 <- c( | |
# "1", # día de la semana | |
# "10:25:00", # hora de inicio | |
# "12:05:00", # hora de fin | |
# ".25" # percentil aceptado como asistencia | |
# ) | |
# class_2 <- c( | |
# "5", # día de la semana | |
# "10:25:00", # hora de inicio | |
# "12:05:00", # hora de fin | |
# ".25" # percentil aceptado como asistencia | |
# ) | |
class_3 <- c( | |
"2", # día de la semana | |
"14:40:00", # hora de inicio | |
"16:20:00", # hora de fin | |
".25" # percentil aceptado como asistencia | |
) | |
class_4 <- c( | |
"3", # día de la semana | |
"18:20:00", # hora de inicio | |
"20:00:00", # hora de fin | |
".25" # percentil aceptado como asistencia | |
) | |
asistencias_1 <- tibble() | |
asistencias_2 <- tibble() | |
asistencias_1 <- report(l4, class_3) | |
asistencias_2 <- report(l4, class_4) | |
asistencias <- tibble() | |
asistencias <- bind_rows(asistencias_1, asistencias_2) | |
asistencias <- drop_na(asistencias_1) %>% filter(real_attendance == 1) | |
asistencias <- asistencias %>% | |
filter(on_time == T) %>% | |
group_by(name) %>% | |
summarize(attendances = sum(attendances), across()) %>% | |
distinct(name, date, attendances, total_duration) | |
# asistencias %>% ggplot(aes(date, name, fill=total_duration)) + | |
# geom_tile(aes(width=1.5, height=1.9), show.legend = FALSE) + | |
# scale_fill_gradientn(colours=c("white","green")) + | |
# theme_minimal() + | |
# labs(x="Fecha", y="Nombre") | |
asistencias %>% ggplot(aes(date, name, fill=total_duration)) + | |
geom_point(color="#482374", show.legend = FALSE) + | |
theme_minimal() + | |
labs(x="Fecha", y="Nombre") | |
asistencias %>% group_by(name) %>% summarize(total = sum(real_attendance)) %>% arrange(desc(total)) %>% View() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment