Skip to content

Instantly share code, notes, and snippets.

@kylebutts
Created October 6, 2021 02:11
Show Gist options
  • Select an option

  • Save kylebutts/4e282ff657a6796d874bb95a8f17913b to your computer and use it in GitHub Desktop.

Select an option

Save kylebutts/4e282ff657a6796d874bb95a8f17913b to your computer and use it in GitHub Desktop.
How to Blastula
library(tidyverse)
library(here)
library(blastula)
# Setup ----
# create_smtp_creds_key(
# id = "kybu6659",
# user = "kybu6659@colorado.edu",
# provider = "gmail"
# )
#
# Additional Setup:
# 1. go to email -> settings -> security -> less secure access -> Turn it on
# - This lets RStudio send emails
# 2. https://accounts.google.com/b/0/DisplayUnlockCaptcha
# - Not sure why, but I also had to click this right before I sent emails for it to work
#
# Testing ----
# test_message <- prepare_test_message()
#
# test_message %>%
# smtp_send(
# from = "kybu6659@colorado.edu",
# to = "kybu6659@colorado.edu",
# subject = "Testing the `smtp_send()` function",
# credentials = creds_key("kybu6659")
# )
#
# Get names and emails set up from raw data
student_names <- read.csv(here::here("Progress Report/midterm1.csv")) |>
# Remove unnecessary columns
select(Student, email = SIS.Login.ID) |>
mutate(email = paste0(email, "@colorado.edu")) |>
# Remove unneeded rows
slice(2:(n()-1))
# Loop through students
for(i in 1:nrow(student_names)) {
name <- student_names[i,"Student"]
email_to <- student_names[i,"email"]
# update message
cli::cli_alert_info("Working on {name} at {email_to}")
# Render email using blastula
# notice I use the params from the template.Rmd
report <- blastula::render_email(
here::here("Progress Report/midterm1_report.Rmd"),
render_options = list(params = list(student = name))
)
# Send generated email to the correct email
smtp_send(
report,
to = email_to,
from = "kybu6659@colorado.edu",
subject = "Post 1st Midterm Progress Report",
credentials = creds_key("kybu6659")
)
}
Student ID SIS User ID SIS Login ID Section Chapter 1 Homework (1144701) Chapter 2 Homework (1144702) Chapter 13 Homework (1144703) Chapter 12 Homework (1144704) Chapter 14 Homework (1144705) Chapter 3 Homework (1144706) Chapter 9 Homework (1144707) Chapter 8 Homework (1144708) Chapter 16 Homework (1144709) Chapter 15 Homework (1144710) Chapter 18 Homework (1144711) Chapter 17 Homework (1144712) Chapter 20 Homework (1144713) Chapter 21 Homework (1144714) Chapter 22 Homework (1144715) Chapter 23 Homework (1144716) Chapter 4 Homework (1144717) Chapter 6 Homework (1144718) Chapter 5 Homework (1144719) Chapter 26 Homework (1144720) R Homework 0 (1143848) R Homework 1 (1126145) R Homework 2 (1126146) R Homework 3 (1126147) R Homework 4 (1126148) R Homework 5 (1126149) R Day 1 and 2 Practice (1181609) R Day 3 Practice (1181610) Midterm 1 Curve (1126143) Midterm 2 Curve (1126144) R Project (1126150) Final Curve (1126142) Midterm 1 (1126120) Final (1126119) Midterm 2 (1126121) Homework Current Score Homework Unposted Current Score Homework Final Score Homework Unposted Final Score R Problem Sets Current Score R Problem Sets Unposted Current Score R Problem Sets Final Score R Problem Sets Unposted Final Score Midterm 1 Current Score Midterm 1 Unposted Current Score Midterm 1 Final Score Midterm 1 Unposted Final Score Midterm 2 Current Score Midterm 2 Unposted Current Score Midterm 2 Final Score Midterm 2 Unposted Final Score R Project Current Score R Project Unposted Current Score R Project Final Score R Project Unposted Final Score Final Current Score Final Unposted Current Score Final Final Score Final Unposted Final Score Exams Current Score Exams Unposted Current Score Exams Final Score Exams Unposted Final Score Current Score Unposted Current Score Final Score Unposted Final Score Current Grade Unposted Current Grade Final Grade Unposted Final Grade
Points Possible 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 0 0 100 100 100 100 100 100 100 (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only) (read only)
1, Fake 339100 109584710 fakeemail1 ECON 3818-010 and ECON 3818-012 90.26 92.61 98.61 96.29 91.71 94.17 95.81 97.08 100 85 92 62 95.76 95.76 42.03 42.03 96 96 55.4 55.4 0 0 0 0 0 0 0 0 62 62 20.67 20.67 95.9 95.9 13.17 13.17 A A F F
2, Fake 399486 109475989 fakeemail2 ECON 3818-010 and ECON 3818-012 92.19 88.94 96.25 89.62 95.64 83.33 87.67 98.47 100 90 92 36 93.52 93.52 40.67 40.67 96 96 56.4 56.4 0 0 0 0 0 0 0 0 36 36 12 12 95.01 95.01 13.19 13.19 A A F F
3, Fake 359351 109821039 fakeemail3 ECON 3818-010 and ECON 3818-012 96.88 91.44 86.2 94.66 87.68 99.17 89.26 96.46 100 94 80 89 94.65 94.65 41.21 41.21 97 97 54.8 54.8 0 0 0 0 0 0 0 0 89 89 29.67 29.67 96.06 96.06 12.99 12.99 A A F F
4, Fake 303853 109180966 fakeemail4 ECON 3818-010 and ECON 3818-011 85.42 77.44 93.33 97.39 98.22 92.36 93.37 96.04 100 85 92 63 95.12 95.12 40.75 40.75 96 96 55.4 55.4 0 0 0 0 0 0 0 0 63 63 21 21 95.65 95.65 13.04 13.04 A A F F
5, Fake 340721 109516732 edal4338 ECON 3818-010 and ECON 3818-011 86.15 85.86 94.26 98.56 85 98.33 98.11 93.33 100 94 85 94 94.79 94.79 41.09 41.09 97 97 55.8 55.8 0 0 0 0 0 0 0 0 94 94 31.33 31.33 96.12 96.12 13.14 13.14 A A F F
Student, Test 406287 1255500750ad51f92de804f4e6cd3ebe8448caf4 ECON 3818-010, ECON 3818-011, and ECON 3818-012 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 F F F F
---
title: "Midterm 1 Progress Report"
output: blastula::blastula_email
params:
student: "3, Fake"
---
```{r, include = F}
library(icons)
library(tidyverse)
library(gt)
coral <- "#F26D21"
```
<style>
.purple {color: #5601A4;}
.navy {color: #0D3D56;}
.ruby {color: #9A2515;}
.alice {color: #107895;}
.daisy {color: #EBC944;}
.coral {color: #F26D21;}
.kelly {color: #829356;}
.jet {color: #131516;}
.asher {color: #555F61;}
.slate {color: #314F4F;}
.cranberry {color: #E64173;}
</style>
<!--
<h1 class="hi text-2xl center coral">Post-First Midterm Progress Report</h1>
-->
```{r "Clean Grades", include = F}
students <- read.csv("midterm1_fake.csv") |>
# Remove unnecessary columns
select(!contains("Grade") & !contains("Score")) |>
# Remove unneeded rows
slice(2:(n()-1))
# Extract name
names <- str_match(students$Student, "(.*), (.*)")
students$first_name <- names[,3]
students$last_name <- names[,2]
hw_scores <- as.matrix(select(students, starts_with("Chapter")))
students$avg_hw <- apply(hw_scores, 1, function(row) {
# Remove two lowest
row <- row[-which(row == min(row, na.rm = T))]
row <- row[-which(row == min(row, na.rm = T))]
round(mean(row, na.rm = T), digits = 2)
})
Rhw_scores <- as.matrix(select(students, starts_with("R.Homework")))
students$avg_Rhw <- apply(Rhw_scores, 1, function(row) {
round(mean(row, na.rm = T), digits = 2)
})
# Midterm including bonus point
bonus1 <- as.numeric(!is.na(students[["R.Day.1.and.2.Practice..1181609."]]))
bonus2 <- as.numeric(!is.na(students[["R.Day.3.Practice..1181610."]]))
students$midterm1 <- students[["Midterm.1..1126120."]] + bonus1 + bonus2
# Form email
students$email <- paste0(students$SIS.Login.ID, "@colorado.edu")
students <- students |> select(Student, first_name, last_name, email, avg_hw, avg_Rhw, midterm1)
# Tentative grade
students$tent_grade <- 0.1 * students$avg_hw + 0.15 * students$avg_Rhw + 0.15 * students$avg_Rhw + 0.2 * students$midterm1 + 0.2 * students$midterm1 + 0.2 * students$midterm1
# Midterm 1 Percentile
students$top_decile <- students$midterm1 >= quantile(students$midterm1, probs = 0.9)
students$bottom_decile <- students$midterm1 <= quantile(students$midterm1, probs = 0.1)
```
```{r "Select Student", include = F}
student <- students |>
filter(Student == params$student)
```
Hi `r student$first_name`,
I am writing you to let you know how you are performing in the class after the first midterm. On the midterm, you received a <b>`r scales::percent(student$midterm1, scale = 1)`</b>. Here is how that grade performed relative to the rest of the class
```{r "Box Plot of Midterm 1", echo = F, fig.width=5.5, fig.height=2, fig.align="center"}
ggplot(students) +
geom_density(aes(x = midterm1/100)) +
# Individual Student Label
geom_vline(xintercept = student$midterm1/100, color = coral, size = 1.2) +
labs(x = NULL, y = NULL) +
scale_x_continuous(labels = scales::percent) +
theme_minimal(base_size = 18) +
theme(
axis.text.y = element_blank()
)
```
`r if(student$top_decile) "As you can see, you scored in the top 10% of the class. Congrats on the job well done!"`
`r if(student$bottom_decile) "As you can see, you scored in the bottom 10% of the class. That makes me nervous for your performance, so I think it's a really good idea for us to meet and talk about this."`
As for the rest of the course, you have a <b>`r scales::percent(student$avg_hw, scale = 1)` average on the online homework</b> and a <b>`r scales::percent(student$avg_Rhw, scale = 1)` average on the R homework</b>. To get a sense of what this means for a final grade, let's assume you get the same test score on the 2nd Midterm and the Final as you got on the 1st Midterm and the same grade on the R Project as you got on the R Homework.
```{r grading-summary, echo = F}
grades <- tribble(
~Assignment, ~Weight, ~Score,
"Homework", "10%", glue::glue("<span class=''>{scales::percent(student$avg_hw, scale = 1)}</span>"),
"R Problem Sets", "15%", glue::glue("<span class=''>{scales::percent(student$avg_Rhw, scale = 1)}</span>"),
"R Project", "15%", glue::glue("<span class='coral'>{scales::percent(student$avg_Rhw, scale = 1)}</span>"),
"Midterm 1", "20%", glue::glue("<span class=''>{scales::percent(student$midterm1, scale = 1)}</span>"),
"Midterm 2", "20%", glue::glue("<span class='coral'>{scales::percent(student$midterm1, scale = 1)}</span>"),
"Final", "20%", glue::glue("<span class='coral'>{scales::percent(student$midterm1, scale = 1)}</span>"),
"<i>\"Nothing Changes\"<br/>Final Score</i>", "", glue::glue("<span class='coral'>{scales::percent(student$tent_grade, scale = 1)}</span>")
) %>%
mutate(
Assignment = map(Assignment, gt::html),
Score = map(Score, gt::html),
)
gt(grades) |>
# kfbmisc::gt_theme_kyle() |>
cols_align(align = "left") |>
tab_style(
style = list(cell_borders(
sides = c("top"),
color = "black",
weight = px(2)
)),
locations = list(cells_body(rows = 7))
)
```
<!--
0.1 * `r student$avg_hw` + 0.15 * `r student$avg_Rhw` + 0.15 * `r student$avg_Rhw` + 0.2 * `r student$midterm1` + 0.2 * `r student$midterm1` + 0.2 * `r student$midterm1` = `r student$tent_grade`
-->
<!--
\begin{equation}
\underbrace{0.1 \cdot `r student$avg_hw`}_{\text{HW}} +
\underbrace{0.15 \cdot `r student$avg_Rhw`}_{\text{R HW}} +
\underbrace{0.15 \cdot \color{coral}{`r student$avg_Rhw`}}_{\text{R Project}} +
\underbrace{0.2 \cdot `r student$midterm1`}_{\text{Midterm 1}} +
\underbrace{0.2 \cdot \color{coral}{`r student$midterm1`}}_{\text{Midterm 2}} +
\underbrace{0.2 \cdot \color{coral}{`r student$midterm1`}}_{\text{Final}}
\approx \color{coral}{`r student$tent_grade`}
\end{equation}
-->
Now, of course this doesn't mean that this is what your grade will end up being. It could be higher or lower depending on how you do in the rest of the course. You can play around with this by changing the numbers around and recomputing the *weighted average*.
If you are nervous about your grade, we should work together to develop a plan. The easiest way to do that is via my office hours:
```{r info-table, echo = F}
table <- tribble(
~Icon, ~Name, ~Time, ~Location,
as.character(icons::fontawesome("laptop-house")), "Office Hours", "M 2-4pm and W 9-11am", "<a href = 'https://cuboulder.zoom.us/s/3975335005'>Zoom</a>",
)
table %>%
mutate(
Icon = map(Icon, gt::html),
Location = map(Location, gt::html),
Time = map(Time, gt::html),
Name = paste0("<i>", Name, "</i>"),
Name = map(Name, gt::html)
) %>%
gt::gt(table) %>%
# kfbmisc::gt_theme_kyle() %>%
gt::cols_label(Icon = "") %>%
gt::cols_width(
Icon ~ px(40)
) %>%
gt::cols_align(columns = c(Name, Time, Location), align = "left") %>%
gt::tab_options(
data_row.padding = px(4),
column_labels.hidden = TRUE
)
```
<br/>
All the best,
-- ky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment