library(ggplot2)
library(deSolve)

#df <- read.csv("dataWEEK.csv",col.names=c("DateTime", "DB", "RH","DP","P","WIND","WIND-DIR","SUN","RAIN","START"))
#df=df[complete.cases(df), ]
#df$DateTime=as.Date(df$DateTime)
#df$DB=(df$DB/10)
#
#head(df)

parms = c(qv = 54, pa = 1.204, Ca = 1006, V = 3000)

model <- function(time, Tr,Text, parms) {
df <- read.csv("dataWEEK.csv",col.names=c("DateTime", "DB", "RH","DP","P","WIND","WIND-DIR","SUN","RAIN","START"))
df=df[complete.cases(df), ]
df$DateTime=as.Date(df$DateTime)
df$DB=(df$DB/10)


#Text=parms[5]
dTr <- -(parms[1] * parms[2] * parms[3] * (Tr - Text)) / (parms[4] * parms[2] * parms[3])
dText = df$DB
list(dTr,Text)
}

solution <- ode(y = 20, times =as.numeric(rownames(df)), func = model, parms = parms)
print(solution)

solution=as.data.frame(solution)
names(solution) <- c("time", "Tr","Text")
head(solution)

gg_plot <- ggplot(data = solution, aes(x = time, y = Tr)) +
  geom_line() +
  geom_line(aes(x = time, y = Text), color = "blue")+
  labs(x = "Time Steps", y = "Room Temperature (Tr)") +
  ggtitle("Room Temperature Over Time")

ggsave(filename = "room_temperature_plot.pdf", plot = gg_plot)