Browse Source

Combined and shiny documentation

Petra Lamborn 5 years ago
parent
commit
2dad2bfc08
2 changed files with 26 additions and 12 deletions
  1. 8
    10
      R/combmodels.R
  2. 18
    2
      README.md

+ 8
- 10
R/combmodels.R View File

@@ -81,12 +81,10 @@ cmdf <- data.frame(x = clusdf$read_time, y = clusdf$kwh, f = fitted(charmmod), r
81 81
 cmplot <-ggplot(cmdf, aes(x = x, y = y)) + geom_line(aes(y = f), color = "blue", size = 2) + geom_point() +
82 82
     geom_point(aes(y = r), color = "darkgreen")
83 83
 
84
-cmplot
84
+# cmplot
85 85
 
86
-cmplot + coord_cartesian(xlim = c(as.POSIXct("2017-03-01", tz = "UTC"), as.POSIXct("2017-04-01", tz = "UTC")))
86
+# cmplot + coord_cartesian(xlim = c(as.POSIXct("2017-03-01", tz = "UTC"), as.POSIXct("2017-04-01", tz = "UTC")))
87 87
 
88
-# sres <- stepAIC(charmmod, scope = list(upper = nform.full, lower = nform.min),
89
-#                 direction = "both", steps = 300)
90 88
 
91 89
 
92 90
 newagg <- p$read_pickle("../data/1617-agg.pkl")
@@ -117,19 +115,19 @@ predf <- data.frame(x = pclusdf$read_time, y = pclusdf$kwh, f = predvals, r = pc
117 115
 predplot <-ggplot(predf, aes(x = x, y = y)) + geom_line(aes(y = f), color = "blue", size = 2) + geom_point() +
118 116
     geom_point(aes(y = r), color = "darkgreen")
119 117
 
120
-predplot
118
+# predplot
121 119
 
122
-predplot + coord_cartesian(xlim = c(as.POSIXct("2017-03-01", tz = "UTC"), as.POSIXct("2017-04-01", tz = "UTC")))
120
+# predplot + coord_cartesian(xlim = c(as.POSIXct("2017-03-01", tz = "UTC"), as.POSIXct("2017-04-01", tz = "UTC")))
123 121
 
124 122
 mean(abs(predf$r))
125 123
 sd(predf$r)
126 124
 
127 125
 
128 126
 # number of icps per cluster
129
-ocdf <- p$read_pickle('../data/9-clusters-sample-table.pkl')
130
-ncdf <- p$read_pickle('../data/1617-asgn-table.pkl')
131
-table(ocdf$cluster)
132
-table(ncdf$cluster)
127
+# ocdf <- p$read_pickle('../data/9-clusters-sample-table.pkl')
128
+# ncdf <- p$read_pickle('../data/1617-asgn-table.pkl')
129
+# table(ocdf$cluster)
130
+# table(ncdf$cluster)
133 131
 
134 132
 
135 133
 allmods <- list()

+ 18
- 2
README.md View File

@@ -229,7 +229,7 @@ This is a now-redundant script testing fitting repeating patterns with Fourier t
229 229
 
230 230
 ### `weathmod.R`
231 231
 
232
-This script takes the downloaded weather data, (hard-coded path: `../data/2016-18-weather.pkl`) and calculates running last-24-hour minimum and maximum temperatures. It then fits harmonic regressions using the first and second harmonic to de-trend the yearly pattern of each series, saving the resulting dataset at `../data/weatherharm.csv` and stores the models in `../models/weatherMinharmonic.rds` and `../models/weatherMaxharmonic.rds`. These paths can be changed in the source, but there are no command line options.
232
+This script takes the downloaded weather data, (hard-coded path: `../data/2016-18-weather.pkl`) and calculates running last-24-hour minimum and maximum temperatures. It then fits harmonic regressions using the first and second harmonic to de-trend the yearly pattern of each series, saving the resulting dataset at `../data/weatherharm.csv` and stores the models in `../models/weatherMinharmonic.rds` and `../models/weatherMaxharmonic.rds`. These paths can be changed in the source (and will likely need to be as the data files are not included in the repository), but there are no command line options.
233 233
 
234 234
 Commented out in the source are a number of potentially informative plots showing this process. For example:
235 235
 
@@ -241,4 +241,20 @@ The justification for this is that we want to include the deviation from typical
241 241
 
242 242
 ### `combmodels.R`
243 243
 
244
-This script takes the 
244
+Taking `../data/9-clusters.agg.pkl` and `../data/weatherharm.csv` as inputs, this script first fits a harmonic model to cluster 1 and tests it with the assigned clusters in `../data/1617-agg.pkl`. It then fits models to all clusters and saves them collectively in `../models/1kmods.rds`.
245
+
246
+Similar to the previous, some plots are again commented out.
247
+
248
+## Shiny App
249
+
250
+The [R Shiny](https://shiny.rstudio.com/) app is located in `shiny/app.R`. It requires the outputs from `weathmod.R` and `combmodels.R`, along with a couple of extra packages, installed with:
251
+
252
+```R
253
+install.packages(c("shiny", "shinycssloaders"))
254
+```
255
+
256
+Explaining Shiny and how to properly install it on a server in order to have a nice web app on a domain behind https _etc_ would take more time than I have (email me!) but for an example of a simple, self-hosted app in action see [this project](https://shiny.petras.space/Emissions/) I made awhile ago ([source](https://git.petras.space/petra/Emissions)).
257
+
258
+The app in this project can be run with `Rscript app.R`; this will (after several seconds of start-up) launch the app at a random port (e.g. 5576). Navigating to this location in your browser (firewall permitting) should display the app.
259
+
260
+The "data and model" tab allows exploration of the data along with the model projection; plots can be saved by right-clicking. The "prediction" tab allows, after specification of the number of icps in each of nine clusters, the temperature range, and the month and day of the week, the projected demand pattern. The month is approximate because it models a "typical" day in the approximate middle of that month, without a specific date.