1 setwd("~/online_communities/coldcallbot/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:4]}))
11 colnames(call.list) <- gsub("_", ".", colnames(call.list))
13 table(call.list$unique.name[call.list$answered])
15 ## drop calls where the person wasn't present
16 call.list.full <- call.list
17 call.list[!call.list$answered,]
18 call.list <- call.list[call.list$answered,]
20 ## show the distribution of assessments
21 prop.table(table(call.list$assessment))
23 call.counts <- data.frame(table(call.list$unique.name))
24 colnames(call.counts) <- c("unique.name", "num.calls")
26 ## create list of folks who are missing in class w/o reporting it
27 absence.data.cols <- c("unique.name", "date.absent", "reported")
29 missing.in.class <- call.list.full[!call.list.full$answered,
30 c("unique.name", "timestamp")]
31 missing.in.class$date.absent <- as.Date(missing.in.class$timestamp)
32 missing.in.class$reported <- FALSE
33 missing.in.class <- missing.in.class[,absence.data.cols]
34 missing.in.class <- unique(missing.in.class)
36 ################################################
37 ## LOAD absence data TSV data
38 ################################################
40 absence.google <- read.delim("absence_poll_data.tsv")
41 colnames(absence.google) <- c("timestamp", "unique.name", "date.absent")
42 absence.google$date.absent <- as.Date(absence.google$date.absent, format="%m/%d/%Y")
43 absence.google$reported <- TRUE
44 absence.google <- absence.google[,absence.data.cols]
45 absence.google <- unique(absence.google)
47 ## combine the two absence lists and then create a unique subset
48 absence <- rbind(missing.in.class[,absence.data.cols],
49 absence.google[,absence.data.cols])
51 ## these are people that show up in both lists (i.e., probably they
52 ## submitted too late but it's worth verifying before we penalize
53 ## them. i'd actually remove them from the absence sheet to suppress
55 absence[duplicated(absence[,1:2]),]
56 absence <- absence[!duplicated(absence[,1:2]),]
58 ## print total questions asked and absences
59 absence.count <- data.frame(table(unique(absence[,c("unique.name", "date.absent")])[,"unique.name"]))
60 colnames(absence.count) <- c("unique.name", "absences")
63 ## load up the full class list
64 gs <- read.delim("student_information.tsv")
65 d <- gs[,c("Your.UW.student.number", "Name.you.d.like.to.go.by.in.class")]
66 colnames(d) <- c("unique.name", "short.name")
68 ## merge in the call counts
69 d <- merge(d, call.counts, all.x=TRUE, all.y=FALSE, by="unique.name")
70 d <- merge(d, absence.count, by="unique.name", all.x=TRUE, all.y=FALSE)
74 ## set anything that's missing to zero
75 d$num.calls[is.na(d$num.calls)] <- 0
76 d$absences[is.na(d$absences)] <- 0
78 ################################################
79 ## list people who have been absent often or called on a lot
80 ################################################
83 ## list students sorted in terms of (a) absences and (b) prev questions
84 d[sort.list(d$absences),]
86 d[sort.list(d$num.calls, decreasing=TRUE),]
88 ################################################
89 ## build visualizations
90 ################################################
95 color.gradient <- scales::seq_gradient_pal("yellow", "magenta", "Lab")(seq(0,1,length.out=range(d$absences)[2]+1))
97 table(d$num.calls, d$absences)
100 aes(x=as.factor(num.calls), y=absences) +
103 ## png("questions_absence_histogram_combined.png", units="px", width=600, height=400)
106 aes(x=as.factor(num.calls), fill=as.factor(absences)) +
107 geom_bar(color="black") +
109 scale_x_discrete("Number of questions asked") +
110 scale_y_continuous("Number of students") +
111 ##scale_fill_brewer("Absences", palette="Blues") +
112 scale_fill_manual("Absences", values=color.gradient) +
117 absence.labeller <- function (df) {
118 lapply(df, function (x) { paste("Absences:", x) })
121 ## png("questions_absence_histogram_facets.png", units="px", width=600, height=400)
124 aes(x=as.factor(num.calls)) +
127 scale_x_discrete("Number of questions asked as of 2020-02-12") +
128 scale_y_continuous("Number of students") +
130 facet_wrap(.~absences, ncol=5, labeller="absence.labeller")