It returns a data frame with the power flow of a fluid, giving its temperature in, temperature out, and flow. Not that the caloric capacity of the water is expressed in kWh / m3
get_energy_flow <- function(df, t_in, t_out, flow, power_flow, cc_water = 1.161) {
relevant_variables <- c(t_in, t_out, flow)
df2 <- df %>%
filter(name %in% relevant_variables) %>%
spread(name, value)
df2[power_flow] <- (df2[t_in] - df2[t_out]) * df2[flow] * cc_water
df3 <- df2[,c("datetime", power_flow)]
return(df3)
}