From 0e49a2686ec1dcd8725d3f231e1538746543e8f7 Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Tue, 21 Nov 2023 11:07:47 -0600 Subject: [PATCH] added time x day chart --- laundry_status.R | 24 ++++++++++++++++++++++-- laundry_status.Rmd | 5 ++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/laundry_status.R b/laundry_status.R index 5b1bec6..44b4923 100755 --- a/laundry_status.R +++ b/laundry_status.R @@ -70,12 +70,13 @@ update_data <- function(){ dryer_last_on <- values %>% filter(entity_id == entities$entity_id[2], value > power_threshhold) %>% tail(1) %>% pull(end_time) dryer_last_off <- values %>% filter(entity_id == entities$entity_id[2], value < power_threshhold) %>% tail(1) %>% pull(end_time) - # ---- generate html + current_status <- as.list(NULL) for (entity in entities$entity_id){ current_status[[entity]] <- ifelse(values %>% filter(entity_id %in% entity) %>% tail(1) %>% pull(value) > power_threshhold, "on", "off") } +# ---- make plots plot_1day <- ggplot(data = values %>% filter(time >= max(values$end_time) - hours(24))) + geom_tile(aes(x = time + seconds(round(as.numeric(difftime(end_time, time, unit = "secs")))/2), y = entity_id, @@ -103,8 +104,27 @@ update_data <- function(){ x = NULL, y = NULL, fill = NULL) - + plot_1week_days <- ggplot(data = values %>% + filter(as.Date(time, tz = "America/Chicago") == as.Date(end_time, tz = "America/Chicago")) %>% + mutate(date = as.Date(time, tz = "America/Chicago")) %>% + left_join(. , entities, by = join_by(entity_id)) %>% + mutate(name = factor(name, levels = c("washing machine", "dryer")))) + + geom_rect(aes(xmin = date - hours(8), + xmax = date + hours(8), + ymin = ymd_hms(paste("2023-01-01", strftime(time, format = "%H:%M:%S"))), + ymax = ymd_hms(paste("2023-01-01", strftime(end_time, format = "%H:%M:%S"))), + fill = status)) + + facet_grid(name ~ .) + + scale_y_datetime(date_breaks = "4 hours", date_labels = '%I:%M %p', minor_breaks = "2 hours", expand = expansion(mult = 0)) + + scale_x_datetime(date_breaks = "1 day", date_labels = '%A', minor_breaks = NULL) + + theme(axis.text.x = element_text(angle = 30, vjust = 0.5)) + + labs(title = "The past week", + x = "Day", + y = "Time of Day", + fill = NULL) + + # ---- generate html render("laundry_status.Rmd", output_dir = "html", output_file = "index.html") diff --git a/laundry_status.Rmd b/laundry_status.Rmd index fa8cfbf..b039cb5 100644 --- a/laundry_status.Rmd +++ b/laundry_status.Rmd @@ -39,4 +39,7 @@ plot(plot_1day) plot(plot_1week) ``` -If you have any issues or questions, please email `admin@dendroalsia.net` +```{r plot_1week_days, echo=FALSE} +plot(plot_1week_days) +``` +If you have any issues or questions, please email `ben@dendroalsia.net`