added spanish translations
This commit is contained in:
parent
a90178925d
commit
eadd99c4cb
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,7 +1,5 @@
|
||||
data/*
|
||||
|
||||
figures/*
|
||||
html/*.html
|
||||
|
||||
html/index.html
|
||||
html/longterm_data.html
|
||||
.Rhistory
|
||||
|
@ -10,6 +10,8 @@ updated: `r format(Sys.time(), format = "%A %I:%M %p", tz = "America/Chicago")`
|
||||
|
||||
this site updates every day
|
||||
|
||||
En [español](https://laundry.dendroalsia.net/longterm_data_es.html)
|
||||
|
||||
---
|
||||
|
||||
```{r plot_all_week_days, echo=FALSE}
|
||||
|
29
laundry_longterm_data_es.Rmd
Normal file
29
laundry_longterm_data_es.Rmd
Normal file
@ -0,0 +1,29 @@
|
||||
---
|
||||
title: "Datos a Largo Plazo"
|
||||
output:
|
||||
html_document:
|
||||
includes:
|
||||
in_header: favicon_header.html
|
||||
---
|
||||
|
||||
Actualizado: `r format(Sys.time(), format = "%A %I:%M %p", tz = "America/Chicago")`
|
||||
|
||||
Este sitio se actualiza cada día
|
||||
|
||||
In [English](https://laundry.dendroalsia.net/longterm_data.html)
|
||||
|
||||
---
|
||||
|
||||
```{r plot_all_week_days_es, echo=FALSE}
|
||||
plot(plot_all_week_days_es)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## para conocer la situación actual, haga clic [aquí](https://laundry.dendroalsia.net/es.html)
|
||||
|
||||
---
|
||||
|
||||
Si tiene algún problema o pregunta, envíe un correo electrónico a [ben@dendroalsia.net](mailto:ben@dendroalsia.net)
|
||||
|
||||
El código que escribí para generar este sitio web está disponible bajo la licencia GPLv3 aquí: [https://git.dendroalsia.net/ben/laundry_status](https://git.dendroalsia.net/ben/laundry_status)
|
107
laundry_status.R
107
laundry_status.R
@ -24,7 +24,7 @@ power_threshold_wash_door <- 4
|
||||
power_threshold_dry_door <- 1.5
|
||||
|
||||
# ---- set variables
|
||||
entities <- data.frame(name = c("washing machine", "dryer"), entity_id = c("washing_machine_power", "dryer_power"))
|
||||
entities <- data.frame(name = c("washing machine", "dryer"), entity_id = c("washing_machine_power", "dryer_power"), name_es = c("lavadora", "secadora"))
|
||||
|
||||
colors <- data.frame(value = c("off", "on"), color = c("#bcbcbc", "#008080"))
|
||||
|
||||
@ -46,9 +46,27 @@ calculateTimeAgo <- function(eventTime) {
|
||||
|
||||
return(result)
|
||||
}
|
||||
calculateTimeAgo_es <- function(eventTime) {
|
||||
current <- Sys.time() # Get the current time
|
||||
timeDiff <- as.duration(current - eventTime) # Calculate the time difference
|
||||
|
||||
# Convert the time difference to appropriate units and format the result
|
||||
if (timeDiff >= hours(24)) {
|
||||
result <- paste("hace", round(timeDiff / dhours(24)), "dias")
|
||||
} else if (timeDiff >= hours(1)) {
|
||||
result <- paste("hace", round(timeDiff / dhours(1)), "horas")
|
||||
} else if (timeDiff >= minutes(1)) {
|
||||
result <- paste("hace", round(timeDiff / dminutes(1)), "minutos")
|
||||
} else {
|
||||
result <- "Ahora"
|
||||
}
|
||||
|
||||
return(result)
|
||||
}
|
||||
|
||||
# ---- update_data function
|
||||
update_data <- function(){
|
||||
Sys.setlocale("LC_TIME", "en_US.UTF-8")
|
||||
|
||||
run_time <- Sys.time()
|
||||
start_time <- floor_date(run_time - ddays(7), unit = "days")
|
||||
@ -91,7 +109,16 @@ update_data <- function(){
|
||||
for (entity in entities$entity_id){
|
||||
current_status[[entity]] <- ifelse(values %>% filter(entity_id %in% entity) %>% tail(1) %>% pull(value) > power_threshold_on, "on", "off")
|
||||
}
|
||||
current_status <- bind_rows(current_status)
|
||||
|
||||
## add spanish translations
|
||||
current_status <- current_status %>%
|
||||
mutate(dryer_power_es = ifelse(dryer_power == "on", "encendida", "apagada"),
|
||||
washing_machine_power_es = ifelse(washing_machine_power == "on", "encendida", "apagada"))
|
||||
|
||||
status_door <- status_door %>%
|
||||
mutate(dryer_power_es = ifelse(dryer_power == "open", "abierto", "cerado"),
|
||||
washing_machine_power_es = ifelse(washing_machine_power == "open", "abierto", "cerado"))
|
||||
# ---- 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),
|
||||
@ -133,9 +160,53 @@ update_data <- function(){
|
||||
output_dir = "html",
|
||||
output_file = "index.html")
|
||||
|
||||
Sys.setlocale("LC_TIME", "es_NI.UTF-8")
|
||||
|
||||
# ---- make plots (es)
|
||||
plot_1day_es <- ggplot(data = values %>% filter(time >= max(values$end_time) - hours(24)) %>%
|
||||
mutate(status = ifelse(status == "on", "encendida", "apagada"))) +
|
||||
geom_tile(aes(x = time + seconds(round(as.numeric(difftime(end_time, time, unit = "secs")))/2),
|
||||
y = entity_id,
|
||||
width = seconds(round(as.numeric(difftime(end_time, time, unit = "secs")))),
|
||||
height = 0.5,
|
||||
fill = status)) +
|
||||
scale_y_discrete(breaks = entities$entity_id, labels = entities$name_es) +
|
||||
scale_x_datetime(breaks = seq(round_date(max(values$end_time), "4 hours") - hours(24), round_date(max(values$end_time), "4 hours"), by = "4 hours"), date_labels = '%I:%M %p', date_minor_breaks = "1 hours") +
|
||||
scale_fill_manual(values = colors$color) +
|
||||
theme(axis.text.x = element_text(angle = 30, vjust = 0.5)) +
|
||||
labs(title = "Hace 24 horas",
|
||||
x = NULL,
|
||||
y = NULL,
|
||||
fill = NULL)
|
||||
|
||||
plot_1week_days_es <- 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_es, levels = c("lavadora", "secadora")))) +
|
||||
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) +
|
||||
scale_fill_manual(values = colors$color) +
|
||||
theme(axis.text.x = element_text(angle = 30, vjust = 0.5)) +
|
||||
labs(title = "La semana pasada",
|
||||
x = "Dia",
|
||||
y = "Tiempo",
|
||||
fill = NULL)
|
||||
|
||||
|
||||
render("laundry_status_es.Rmd",
|
||||
output_dir = "html",
|
||||
output_file = "es.html")
|
||||
}
|
||||
|
||||
update_longterm_data <- function(){
|
||||
Sys.setlocale("LC_TIME", "en_US.UTF-8")
|
||||
|
||||
run_time <- Sys.time()
|
||||
start_time <- floor_date(run_time - ddays(365), unit = "days")
|
||||
@ -192,6 +263,40 @@ update_longterm_data <- function(){
|
||||
render("laundry_longterm_data.Rmd",
|
||||
output_dir = "html",
|
||||
output_file = "longterm_data.html")
|
||||
|
||||
# ---- spanish translation
|
||||
|
||||
Sys.setlocale("LC_TIME", "es_NI.UTF-8")
|
||||
|
||||
values["weekday"] <- wday(values$time, label = TRUE)
|
||||
values["hourofday"] <- floor_date(ymd_hms(paste("2023_01_01",strftime(values$time, format="%H:%M:%S"))), unit = "hours")
|
||||
long_term <- values %>%
|
||||
filter(status =="on") %>%
|
||||
group_by(weekday, hourofday, entity_id, status) %>%
|
||||
summarise(count = n())
|
||||
# ---- make plots
|
||||
|
||||
plot_all_week_days_es <- ggplot(data = long_term %>%
|
||||
left_join(. , entities, by = join_by(entity_id)) %>%
|
||||
mutate(name = factor(name_es, levels = c("lavadora", "secadora")))) +
|
||||
geom_tile(aes(x = weekday,
|
||||
y = hourofday,
|
||||
alpha = count,
|
||||
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_discrete() +
|
||||
scale_fill_manual(values = colors$color[2], guide = NULL) +
|
||||
theme(axis.text.x = element_text(angle = 30, vjust = 0.5)) +
|
||||
labs(title = "Tendencias a largo plazo",
|
||||
subtitle = paste0("datos del ",strftime(min(values$time), format = "%B %d, %Y"), " al ", strftime(run_time, format = "%B %d, %Y")),
|
||||
x = "Día de la semana",
|
||||
y = "Tiempo",
|
||||
alpha = "Frecuencia")
|
||||
|
||||
render("laundry_longterm_data_es.Rmd",
|
||||
output_dir = "html",
|
||||
output_file = "longterm_data_es.html")
|
||||
}
|
||||
|
||||
continue <- TRUE
|
||||
|
@ -10,9 +10,11 @@ updated: `r format(Sys.time(), format = "%A %I:%M %p", tz = "America/Chicago")`
|
||||
|
||||
this site updates every `r update_interval` minutes
|
||||
|
||||
En [español](https://laundry.dendroalsia.net/es.html)
|
||||
|
||||
---
|
||||
|
||||
## The washing machine is currently: `r current_status[["washing_machine_power"]]`
|
||||
## The washing machine is currently: `r current_status$washing_machine_power`
|
||||
|
||||
|
||||
The washer `r ifelse(current_status$washing_machine_power=="on", "started", "ended")` its most recent cycle at `r ifelse(current_status$washing_machine_power=="on", strftime(last_change$washing_machine_power_off, format = "%A %I:%M %p", tz = "America/Chicago"), strftime(last_change$washing_machine_power_on, format = "%A %I:%M %p", tz = "America/Chicago"))`
|
||||
@ -23,7 +25,7 @@ The washer `r ifelse(current_status$washing_machine_power=="on", "started", "end
|
||||
|
||||
---
|
||||
|
||||
## The dryer is currently: `r current_status[["dryer_power"]]`
|
||||
## The dryer is currently: `r current_status$dryer_power`
|
||||
|
||||
|
||||
The dryer `r ifelse(current_status$dryer_power=="on", "started", "ended")` its most recent cycle at `r ifelse(current_status$dryer_power=="on", strftime(last_change$dryer_power_off, format = "%A %I:%M %p", tz = "America/Chicago"), strftime(last_change$dryer_power_on, format = "%A %I:%M %p", tz = "America/Chicago"))`
|
||||
|
62
laundry_status_es.Rmd
Normal file
62
laundry_status_es.Rmd
Normal file
@ -0,0 +1,62 @@
|
||||
---
|
||||
title: "Estado de la lavadería"
|
||||
output:
|
||||
html_document:
|
||||
includes:
|
||||
in_header: favicon_header.html
|
||||
---
|
||||
|
||||
Actualizado: `r format(Sys.time(), format = "%A %I:%M %p", tz = "America/Chicago")`
|
||||
|
||||
Este sitio se actualiza cada `r update_interval` minutos
|
||||
|
||||
In [English](https://laundry.dendroalsia.net/)
|
||||
|
||||
---
|
||||
|
||||
## la lavadora está `r current_status$washing_machine_power_es`
|
||||
|
||||
|
||||
la lavadora `r ifelse(current_status$washing_machine_power=="on", "inició", "terminó")` su último ciclo a las `r ifelse(current_status$washing_machine_power=="on", strftime(last_change$washing_machine_power_off, format = "%A %I:%M %p", tz = "America/Chicago"), strftime(last_change$washing_machine_power_on, format = "%A %I:%M %p", tz = "America/Chicago"))`
|
||||
:
|
||||
`r ifelse(current_status$washing_machine_power=="on", calculateTimeAgo_es(last_change$washing_machine_power_off), calculateTimeAgo_es(last_change$washing_machine_power_on))`
|
||||
|
||||
`r ifelse(current_status$washing_machine_power=="off", paste0("El puerto de la lavadora esta ", status_door$washing_machine_power_es), "")`
|
||||
|
||||
---
|
||||
|
||||
## La secadora está `r current_status$dryer_power_es`
|
||||
|
||||
|
||||
The dryer `r ifelse(current_status$dryer_power=="on", "inició", "terminó")` su último ciclo a las `r ifelse(current_status$dryer_power=="on", strftime(last_change$dryer_power_off, format = "%A %I:%M %p", tz = "America/Chicago"), strftime(last_change$dryer_power_on, format = "%A %I:%M %p", tz = "America/Chicago"))`
|
||||
:
|
||||
`r ifelse(current_status$dryer_power=="on", calculateTimeAgo_es(last_change$dryer_power_off), calculateTimeAgo_es(last_change$dryer_power_on))`
|
||||
|
||||
`r ifelse(current_status$dryer_power=="off", paste0("El puerto de la secadora esta ", status_door$dryer_power_es), "")`
|
||||
|
||||
|
||||
---
|
||||
```{r setup, include=FALSE}
|
||||
knitr::opts_chunk$set(echo = TRUE)
|
||||
```
|
||||
Este sitio hace un seguimiento de la lavadora y la secadora de nuestro edificio. Mi esperanza es que ayude a la gente a encontrar buenos momentos para hacer la colada.
|
||||
|
||||
```{r plot_1day_es, echo=FALSE}
|
||||
plot(plot_1day_es)
|
||||
```
|
||||
|
||||
```{r plot_1week_days_es, echo=FALSE}
|
||||
plot(plot_1week_days_es)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Para obtener datos a largo plazo, pulse [aquí](https://laundry.dendroalsia.net/longterm_data_es.html)
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
Si tiene algún problema o pregunta, envíe un correo electrónico a [ben@dendroalsia.net](mailto:ben@dendroalsia.net)
|
||||
|
||||
El código que escribí para generar este sitio web está disponible bajo la licencia GPLv3 aquí: [https://git.dendroalsia.net/ben/laundry_status](https://git.dendroalsia.net/ben/laundry_status)
|
Loading…
x
Reference in New Issue
Block a user