1 setwd("~/online_communities/coldcall_scripts-COM481-2024Q4/data/")
5 ################################################
6 ## LOAD call_list TSV data
7 ################################################
9 call.list <- do.call("rbind", lapply(list.files(".", pattern="^call_list-.*tsv$"), function (x) {read.delim(x, stringsAsFactors=FALSE)[,1:5]}))
11 colnames(call.list) <- gsub("_", ".", colnames(call.list))
12 colnames(call.list)[1] <- "unique.name"
13 colnames(call.list)[2] <- "preferred.name"
15 table(call.list$unique.name[call.list$answered])
17 ## drop calls where the person wasn't present
18 call.list.full <- call.list
19 call.list[!call.list$answered,]
20 call.list <- call.list[call.list$answered,]
22 ## show the distribution of assessments
23 prop.table(table(call.list$assessment))
25 call.counts <- data.frame(table(call.list$unique.name))
26 colnames(call.counts) <- c("unique.name", "num.calls")
28 ## create list of folks who are missing in class w/o reporting it
29 absence.data.cols <- c("unique.name", "date.absent", "reported")
31 missing.in.class <- call.list.full[!call.list.full$answered,
32 c("unique.name", "timestamp")]
33 missing.in.class$date.absent <- as.Date(missing.in.class$timestamp)
34 missing.in.class$reported <- rep(FALSE, nrow(missing.in.class))
35 missing.in.class <- missing.in.class[,absence.data.cols]
36 missing.in.class <- unique(missing.in.class)
38 ################################################
39 ## LOAD absence data TSV data
40 ################################################
42 absence.google <- read.delim("optout_poll_data.tsv")
43 colnames(absence.google) <- c("timestamp", "unique.name", "date.absent")
44 absence.google$date.absent <- as.Date(absence.google$date.absent, format="%m/%d/%Y")
45 absence.google$reported <- TRUE
46 absence.google <- absence.google[,absence.data.cols]
47 absence.google <- unique(absence.google)
49 ## combine the two absence lists and then create a unique subset
50 absence <- rbind(missing.in.class[,absence.data.cols],
51 absence.google[,absence.data.cols])
53 ## these are people that show up in both lists (i.e., probably they
54 ## submitted too late but it's worth verifying before we penalize
55 ## them. i'd actually remove them from the absence sheet to suppress
57 absence[duplicated(absence[,1:2]),]
58 absence <- absence[!duplicated(absence[,1:2]),]
60 ## print total questions asked and absences
61 absence.count <- data.frame(table(unique(absence[,c("unique.name", "date.absent")])[,"unique.name"]))
62 colnames(absence.count) <- c("unique.name", "absences")
65 ## load up the full class list
66 gs <- read.delim("student_information.tsv")
67 d <- gs[,c("Your.UW.student.number", "Name.you.d.like.to.go.by.in.class")]
68 colnames(d) <- c("unique.name", "short.name")
70 ## merge in the call counts
71 d <- merge(d, call.counts, all.x=TRUE, all.y=FALSE, by="unique.name")
72 d <- merge(d, absence.count, by="unique.name", all.x=TRUE, all.y=FALSE)
76 ## set anything that's missing to zero
77 d$num.calls[is.na(d$num.calls)] <- 0
78 d$absences[is.na(d$absences)] <- 0
80 ################################################
81 ## list people who have been absent often or called on a lot
82 ################################################
85 ## list students sorted in terms of (a) absences and (b) prev questions
86 d[sort.list(d$absences),]
88 d[sort.list(d$num.calls, decreasing=TRUE),]
90 ################################################
91 ## build visualizations
92 ################################################
97 color.gradient <- scales::seq_gradient_pal("yellow", "magenta", "Lab")(seq(0,1,length.out=range(d$absences)[2]+1))
99 table(d$num.calls, d$absences)
101 png("questions_absence_histogram_combined.png", units="px", width=600, height=400)
104 aes(x=as.factor(num.calls), fill=as.factor(absences)) +
105 geom_bar(color="black") +
107 scale_x_discrete("Number of questions answered") +
108 scale_y_continuous("Number of students") +
109 ##scale_fill_brewer("Absences", palette="Blues") +
110 scale_fill_manual("Opt-outs", values=color.gradient) +
115 absence.labeller <- function (df) {
116 lapply(df, function (x) { paste("Absences:", x) })
119 ## png("questions_absence_histogram_facets.png", units="px", width=600, height=400)
122 ## aes(x=as.factor(num.calls)) +
125 ## scale_x_discrete("Number of questions answered") +
126 ## scale_y_continuous("Number of students") +
128 ## facet_wrap(.~absences, ncol=5, labeller="absence.labeller")