Use Data DF2
library(data.table)
#library(lubridate)
library(tidyverse)
library(knitr)
library(readr)
Upload data
df21 <- read_csv("D:/FREELANCE-USA/Additional resources for project/dataset/DF21.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## .default = col_double()
## )
## i Use `spec()` for the full column specifications.
dt <- na.omit(df21)
Data preparation
dt$Cool.Demand.Status <- NULL
dt$SurfaceAzimuthAngle_south <- NULL
dt$SurfaceAzimuthAngle_north <- NULL
dt$SurfaceAzimuthAngle_west <- NULL
dt$SurfaceAzimuthAngle_east <- NULL
dim(dt)
## [1] 14125 28
dt$solar_incidence_angle_north<- NULL
dt$solar_incidence_angle_south<- NULL
dt$solar_incidence_angle_east<- NULL
dt$beam_solar_radiation_south<- NULL
dt$beam_solar_radiation_east<- NULL
dt$beam_solar_radiation_north<- NULL
dt$diffuse_solar_radiation_south<- NULL
dt$diffuse_solar_radiation_north<- NULL
dt$diffuse_solar_radiation_east<- NULL
#str(dt)
#> summary(dt$Humidity)
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 44.00 52.00 57.00 56.19 60.00 77.00
# hummidity/100 from Mean humidity=56.19/100=0.56
Convert date in one colum
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:data.table':
##
## hour, isoweek, mday, minute, month, quarter, second, wday, week,
## yday, year
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
date <- with(dt, ymd_hm(paste(Year, Month, Day, Hour, Minutes, sep= ' ')))
date <- data.frame(date)
dn <- cbind(dt,date)
dnn <- dn %>% select("date","Temp","Cool.Setpoint")
LongFormatReadings <- function(building){
#building <- dcast(building,date ~ Temp,value.var=c("Cool.Setpoint"))
#building <- building[,c("date","4","3"),with=FALSE]
#building <- building[complete.cases(building)]
colnames(building) <- c("date","temp","relh")
return(building)
}
west <- LongFormatReadings(dnn)
head(west,3)
## date temp relh
## 1 2018-06-05 14:40:00 72.5 73
## 2 2018-06-05 14:42:00 72.5 72
## 3 2018-06-05 14:44:00 72.5 72
AddOtherVariableAssumptions <- function(building){
building$radtemp <- building$temp
building$vel <- 2
building$met <- 1
building$clo <- 0.2
building$hum <- 0.56 # hummidity/100, from Mean humidity=56.19/100=0.56
return(building)
}
west <- AddOtherVariableAssumptions(west)
head(west,3)
## date temp relh radtemp vel met clo hum
## 1 2018-06-05 14:40:00 72.5 73 72.5 2 1 0.2 0.56
## 2 2018-06-05 14:42:00 72.5 72 72.5 2 1 0.2 0.56
## 3 2018-06-05 14:44:00 72.5 72 72.5 2 1 0.2 0.56
TCA Termal Comfort analysis
#Load Google's Javscript Engine V8 (See https://cran.r-project.org/web/packages/V8/vignettes/v8_intro.html)
library(V8)
## Using V8 engine 6.2.414.50
#Create a new context
ct <- v8()
#Load Javascript Library for forEach function
ct$source(system.file("js/underscore.js", package="V8"))
#Load local comfortModel javscript library (only modified the path of the libraries)
#ct$source("comfortmodels.js")
ct$source("D:/PMV/thermal_comfort-master/pmv/comfortmodels.js")
## [1] "function (ta, tr, runningMean, vel) {\n var to = (ta + tr) / 2;\n var coolingEffect = 0;\n if (vel >= 0.2 && to > 25) {\n // calculate cooling effect of elevated air speed\n // when top > 25 degC.\n var coolingEffect = 1.7856 * Math.log(vel) + 2.9835;\n }\n var tComf = 0.33 * runningMean + 18.8;\n if(runningMean > 15){\n var tComfILower = tComf - 2;\n var tComfIUpper = tComf + 2 + coolingEffect;\n var tComfIILower = tComf - 3;\n var tComfIIUpper = tComf + 3 + coolingEffect;\n var tComfIIILower = tComf - 4;\n var tComfIIIUpper = tComf + 4 + coolingEffect;\n } else if (12.73 < runningMean && runningMean < 15){\n var tComfLow = 0.33 * 15 + 18.8;\n var tComfILower = tComfLow - 2;\n var tComfIUpper = tComf + 2 + coolingEffect;\n var tComfIILower = tComfLow - 3;\n var tComfIIUpper = tComf + 3 + coolingEffect;\n var tComfIIILower = tComfLow - 4;\n var tComfIIIUpper = tComf + 4 + coolingEffect;\n } else {\n var tComfLow = 0.33 * 15 + 18.8;\n var tComfILower = tComfLow - 2;\n var tComfIUpper = tComf + 2;\n var tComfIILower = tComfLow - 3;\n var tComfIIUpper = tComf + 3 + coolingEffect;\n var tComfIIILower = tComfLow - 4;\n var tComfIIIUpper = tComf + 4 + coolingEffect;\n }\n var acceptabilityI, acceptabilityII, acceptabilityIII;\n\n if (comf.between(to, tComfILower, tComfIUpper)) {\n // compliance at all levels\n acceptabilityI = acceptabilityII = acceptabilityIII = true;\n } else if (comf.between(to, tComfIILower, tComfIIUpper)) {\n // compliance at II and III only\n acceptabilityII = acceptabilityIII = true;\n acceptabilityI = false;\n } else if (comf.between(to, tComfIIILower, tComfIIIUpper)) {\n // compliance at III only\n acceptabilityIII = true;\n acceptabilityI = acceptabilityII = false;\n } else {\n // neither\n acceptabilityI = acceptabilityII = acceptabilityIII = false;\n }\n r = {}\n r.acceptabilityI = acceptabilityI\n r.acceptabilityII = acceptabilityII\n r.acceptabilityIII = acceptabilityIII\n r.tComfILower = tComfILower\n r.tComfIILower = tComfIILower\n r.tComfIIILower = tComfIIILower\n r.tComfIUpper = tComfIUpper\n r.tComfIIUpper = tComfIIUpper\n r.tComfIIIUpper = tComfIIIUpper\n return r\n return [[acceptabilityIII, tComfIIILower, tComfIIIUpper],\n [acceptabilityII, tComfIILower, tComfIIUpper],\n [acceptabilityI, tComfILower, tComfIUpper]];\n}"
ct$source("D:/PMV/thermal_comfort-master/pmv/util.js")
## [1] "function (x) {\n return (x - 32) * 5 / 9;\n}"
ct$source("D:/PMV/thermal_comfort-master/pmv/psychrometrics.js")
## [1] "function (ta, vel, tglobe, diameter, emissivity) {\n pow = Math.pow;\n return pow(pow(tglobe + 273, 4) + (1.1 * pow(10, 8) * pow(vel, 0.6)) / (emissivity * pow(diameter, 0.4)) * (tglobe - ta), 0.25) - 273;\n}"
Apply the function over all the table for pmvElevatedAirspeed
west.elevated.air.pmv <- data.table(ct$call("_.map",
west, JS("function(x){return(comf.pmvElevatedAirspeed(util.FtoC(x.temp),
util.FtoC(x.radtemp),x.vel/196.85,x.relh,x.clo,x.met,x.hum))}")))
west.pmv<- data.table(ct$call("_.map", west, JS("function(x)
{return(comf.pmv(util.FtoC(x.temp),util.FtoC(x.radtemp),x.vel/196.85,x.relh,x.clo,x.met,x.hum))}")))
west.pmv
## pmv ppd
## 1: -19.48752 100
## 2: -19.50764 100
## 3: -19.50764 100
## 4: -19.50764 100
## 5: -19.50764 100
## ---
## 14121: -18.96922 100
## 14122: -18.96922 100
## 14123: -18.96922 100
## 14124: -19.23859 100
## 14125: -19.23859 100
Comfort threshold
west.elevated.air.pmv$iscomfortable <- ifelse(west.elevated.air.pmv$pmv > -2 &
west.elevated.air.pmv$pmv < 2,"comfortable","uncomfortable")
kable(west.elevated.air.pmv[,.(frequency=length(pmv)),by="iscomfortable"])
Plot confort zone
library(dygraphs)
west.elevated.air.pmv$date <- west$date
dygraph(west.elevated.air.pmv[,.(date,pmv)], main = "Comfort Level") %>% dyRangeSelector()