#============================== Loading Short Term file: user input one file
data_ST <- reactive({
if(input$Load1 == 0){return()}
inFile1 <- input$file1
if (is.null(inFile1)){return(NULL)}
isolate({
input$Load1
my_data_ST <- read.table(inFile1$datapath, header = FALSE, sep = ";", dec = ".", skip = 6)
my_data_ST <- my_data_ST[,c("V2","V3","V4")]
my_data_ST$V2 <- as.POSIXct(strptime(my_data_ST$V2, format ="%Y-%m-%d %H:%M"), tz = "GMT")
colnames(my_data_ST) <- c("date", "ws", "wd")
my_data_ST$month <- NULL
my_data_ST$month <- format(my_data_ST$date, '%m')
my_data_ST$month <- as.factor(my_data_ST$month)
means_st <- NULL
means_st <- tapply(my_data_ST$ws, my_data_ST$month, mean) # calculate means
print(means_st) #first verification - print to see if its ok...
})
my_data_ST
})
#============================== Loading Long Term file: user insert another file
data_LT <- reactive({
if(input$Load2 == 0){return()}
inFile2 <- input$file2
if (is.null(inFile2)){return(NULL)}
isolate({
input$Load2
my_data_LT <- read.table(inFile2$datapath, header = FALSE, sep = ";", dec = ".", skip = 6)
my_data_LT <- my_data_LT[,c("V2","V3","V4")]
my_data_LT$V2 <- as.POSIXct(strptime(my_data_LT$V2, format ="%Y-%m-%d %H:%M"), tz = "GMT")
colnames(my_data_LT) <- c("date", "ws", "wd")
my_data_LT$month <- NULL
my_data_LT$month <- format(my_data_LT$date, '%m')
my_data_LT$month <- as.factor(my_data_LT$month)
# generating matrix for heatmap plot:
d_m_h <- NULL
d_m_h <- aggregate(my_data_LT["ws"], format(my_data_LT["date"],"%m-%H"), mean, na.rm=TRUE)
d_m_h$date <- paste(d_m_h$date, "-2000-25", sep="")
d_m_h$date <- as.POSIXct(strptime(d_m_h$date, format ="%m-%H-%Y-%d"), tz = "GMT")
d_m_h$month <- format.Date(d_m_h$date, "%m")
d_m_h$hour <- format.Date(d_m_h$date, "%H")
d_m_h$month <- as.numeric(d_m_h$month)
d_m_h$hour <- as.numeric(d_m_h$hour)
print(d_m_h) # second verification - print to see if its ok...
# generating a matrix to plot later
mat <- matrix(NA, ncol=12, nrow=24)
for(imonth in 1:12){
for(ihour in 1:24) {
flag <- d_m_h$month == imonth & d_m_h$hour == (ihour-1)
mat[ihour,imonth] <- d_m_h[flag,2]
}
}
horas <- seq(from = 0, to = 23, by=1)
meses <- seq(from = 1, to = 12, by=1)
row.names(mat) <- horas
colnames(mat) <- meses
print(mat) # third verification - print to see if its ok...
})
list(my_data_LT, d_m_h, mat)
})