Skip to content

Instantly share code, notes, and snippets.

@krisselden
Last active April 23, 2020 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisselden/59dacc4b3c70ffeb31928e169a7b2de9 to your computer and use it in GitHub Desktop.
Save krisselden/59dacc4b3c70ffeb31928e169a7b2de9 to your computer and use it in GitHub Desktop.
library(tidyverse)
# sample, treatment, chunk size, timestamp
chunks <- read.csv("results.csv")
sorted_and_summed <- chunks %>%
group_by(sample) %>%
arrange(timestamp, .by_group = T) %>%
mutate(
bytes_received = cumsum(bytes),
progress = bytes_received / max(bytes_received)
) %>%
ungroup()
sample_summary <- sorted_and_summed %>%
group_by(treatment, sample) %>%
summarize(
time_moment100 = max(timestamp),
time_moment75 = min(timestamp[progress > 0.75]),
time_moment50 = min(timestamp[progress > 0.5]),
) %>%
ungroup() %>%
group_by(treatment) %>%
mutate(
# map time_moment to its density
dens100 = sapply(time_moment100, approxfun(density(time_moment100))),
dens75 = sapply(time_moment75, approxfun(density(time_moment75))),
dens50 = sapply(time_moment50, approxfun(density(time_moment50))),
# normalize
normalized_density = dens100 * dens75 * dens50,
normalized_density = normalized_density / max(normalized_density)
)
joined <- sorted_and_summed %>%
left_join(sample_summary) %>%
mutate(
# when lines are painted less dense will paint first
sample = factor(sample),
sample = fct_reorder(sample, normalized_density)
)
ggplot(joined, aes(
x = timestamp,
y = bytes_received,
group = sample,
alpha = normalized_density,
color = normalized_density,
size = normalized_density
)) +
geom_step() +
scale_color_continuous(type = "viridis") +
scale_alpha(range = c(0, 1), guide = F) +
scale_size(range = c(5, 2), guide = F) +
facet_grid(rows = vars(treatment)) +
theme(strip.text.y = element_text(angle = 0)) +
labs(
title = "Expirement Title",
subtitle = "Content Download",
color = "Normalized\nDensity",
x = "Milliseconds Elapsed",
y = "Bytes Received"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment