-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummary_ecm_content.R
382 lines (356 loc) · 15 KB
/
summary_ecm_content.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
library("DBI")
library("reshape2")
library("ggplot2")
library("dplyr")
library("readxl")
library("readr")
library("RColorBrewer")
library("stringr")
con <- dbConnect(RSQLite::SQLite(), "csv_FY/db/all.db")
alltables = dbListTables(con)
df_area = dbGetQuery(con, 'SELECT * FROM EUAS_area' ) %>%
as_data_frame() %>%
group_by(`Building_Number`) %>%
summarise(`Gross_Sq.Ft`=last(`Gross_Sq.Ft`)) %>%
dplyr::rename(`Building ID`=`Building_Number`) %>%
{.}
plot_fields_categorical = function(sourcefile, sheetid, skipn,
excludeCols, prefix) {
df_gb_factor = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::mutate(Region=factor(Region)) %>%
dplyr::mutate_if(is.character, as.factor) %>%
dplyr::select(which(sapply(.,is.factor))) %>%
dplyr::select(-one_of(excludeCols)) %>%
dplyr::select(which(sapply(., nlevels) > 1)) %>%
{.}
if ("Building Number" %in% names(df_gb_factor)) {
names(df_gb_factor)[names(df_gb_factor) == "Building Number"] <- "Building ID"
}
names(df_gb_factor) = gsub(" ", "", names(df_gb_factor))
names(df_gb_factor) = gsub("/", "or", names(df_gb_factor))
names(df_gb_factor) = gsub("-", "", names(df_gb_factor))
names(df_gb_factor) = gsub(",", "", names(df_gb_factor))
names(df_gb_factor) = gsub("#", "", names(df_gb_factor))
names(df_gb_factor) = gsub("(", "", names(df_gb_factor),
fixed=TRUE)
names(df_gb_factor) = gsub(")", "", names(df_gb_factor),
fixed=TRUE)
categorical_vars = names(df_gb_factor)
categorical_vars = categorical_vars[categorical_vars != "BuildingID"]
## how to replace na with something!!!!!!!
for (cat in categorical_vars) {
plot.df =
df_gb_factor %>%
dplyr::select(one_of(c(cat, "BuildingID"))) %>%
dplyr::group_by_at(vars(one_of(c(cat, "BuildingID")))) %>%
slice(1) %>%
{.}
print(plot.df)
plot.df %>%
ggplot() +
geom_bar(aes_string(x=cat)) +
geom_text(stat='count',
aes_string(x=cat, label="..count.."), vjust=-1) +
ylab("Attribute Count (for unique buildings)") +
ggtitle(paste0(prefix, "-- Attribute Count : ", cat, "\n(for unique buildings)")) +
scale_x_discrete(labels =
function(x) stringr::str_wrap(x, width = 40)) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
ylim(0, 300) +
coord_flip() +
theme()
ggsave(paste0("writeup/images/", prefix, "_", cat, "_count.png"))
}
}
excludeCols = c("Project Name", "id##Record ID", "Slope",
"Comments", "Other, Please Specify")
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/gBUILD Building Envelope Scope 11-23-16.xlsx"
sheetid = 2
skipn = 2
plot_fields_categorical(sourcefile, sheetid, skipn, excludeCols,
"gBUILD")
excludeCols = c("Project name", "Comments")
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 2
skipn = 3
plot_fields_categorical(sourcefile, sheetid, skipn, excludeCols,
"LED2")
excludeCols = c("Project name", "Comment")
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 3
skipn = 3
plot_fields_categorical(sourcefile, sheetid, skipn, excludeCols,
"LED3")
excludeCols = c("Project Name", "Building Name", "ASID",
"id##Record ID",
"isdeleted##Deleted",
"ScopeDetailsCount__c##Scope Details Count",
"Name##PBSgBUILDSS",
"RecordTypeId##Record Type ID",
"RecordType.DeveloperName",
"createddate##Created Date",
"createdbyid##Created By ID",
"CreatedBy.Name",
"lastmodifieddate##Last Modified Date",
"lastmodifiedbyid##Last Modified By ID",
"LastModifiedBy.Name",
"systemmodstamp##System Modstamp",
"Rahd_ProjectBldgParentId__c##RAHD_Project Building Parent ID",
"Rahd_ProjectBldgParentId__r.Name",
"ScopeSysCode2__c##Scope System Code L2",
"ScopeSysCodeL1__c##Scope System Code L1",
"ScopeSysCodeL2__c##Scope System Code L2",
"ScopeSysCodeL3__c##Scope System Code L3",
"ScopeDetailsMaxSeq__c##Scope Details Max Sequence",
"ScopeSystemDetailRecordType__c##Scope System Detail Record Type",
"Comments")
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/VRF etc -- Mike Sullivan Corrected Equipment Ad Hoc 6.12.17.xlsx"
sheetid = 1
skipn = 0
plot_fields_categorical(sourcefile, sheetid, skipn, excludeCols,
"VRF1")
# how many roof cases
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/gBUILD Building Envelope Scope 11-23-16.xlsx"
sheetid = 2
skipn = 2
read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::mutate_at(vars(`Scope Type`), recode,
"New/Replacement Roof" = "New_Roof",
"Repair/Replace Existing Windows" = "Repairs_Windows",
"Existing Facade Repair" = "Repairs_Facade",
"New/Replaced Facade" = "New_Facade",
"New Windows" = "New_Windows",
"Existing Roof R&A" = "RandA_Roof") %>%
dplyr::mutate(`Type`=gsub(".*_", "", `Scope Type`)) %>%
dplyr::group_by(`Scope Type`, `Building ID`)) %>%
slice(1) %>%
ggplot(aes(x=Type)) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
ggtitle(paste0("Roof Window Facade Project Count")) +
ylab("percentage") +
theme()
ggsave(paste0("writeup/images/roofWindowFacade", "_percent.png"))
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/gBUILD Building Envelope Scope 11-23-16.xlsx"
sheetid = 2
skipn = 2
read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::mutate_at(vars(`Scope Type`), recode,
"New/Replacement Roof" = "New_Roof",
"Repair/Replace Existing Windows" = "Repairs_Windows",
"Existing Facade Repair" = "Repairs_Facade",
"New/Replaced Facade" = "New_Facade",
"New Windows" = "New_Windows",
"Existing Roof R&A" = "RandA_Roof") %>%
dplyr::mutate(`Type`=gsub(".*_", "", `Scope Type`)) %>%
ggplot(aes(x=Type)) +
geom_bar(aes(y = ..count..)) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
geom_text(stat='count', aes(label=..count..)) +
ggtitle(paste0("Roof Window Facade Project Count")) +
theme()
ggsave(paste0("writeup/images/roofWindowFacade", "_count.png"))
## roof project area, didn't associate with area in the database
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/gBUILD Building Envelope Scope 11-23-16.xlsx"
sheetid = 2
skipn = 2
read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
## `id##Record ID` are distinct id for each row
dplyr::select(`id##Record ID`, `Total Roof Square Footage`,
`Square Footage of Application`) %>%
dplyr::rename(`Record ID`=`id##Record ID`) %>%
## dplyr::mutate(`Ratio`=`Square Footage of Application`/`Total Roof Square Footage`) %>%
melt(id.vars="Record ID", variable.name="Roof Area Attribute",
value.name="Square Footage") %>%
ggplot() +
geom_boxplot(aes(y = `Square Footage`, x = `Roof Area Attribute`)) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
ylim(0, 1e+05) +
scale_x_discrete(labels =
function(x) stringr::str_wrap(x, width = 15)) +
theme()
ggsave(paste0("writeup/images/roofarea", ".png"))
## roof project area ratio
read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
## `id##Record ID` are distinct id for each row
dplyr::select(`id##Record ID`, `Total Roof Square Footage`,
`Square Footage of Application`) %>%
dplyr::mutate(`Ratio`=`Square Footage of Application`/`Total Roof Square Footage`) %>%
ggplot() +
geom_histogram(aes(x = `Ratio`)) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
theme()
ggsave(paste0("writeup/images/roofarea_ratio", ".png"))
## LED area
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 2
skipn = 3
df1 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Project name`, `LED Square Footage Illuminated`,
`Whole Application Sq Ft`) %>%
## summarize(n_distinct(`Project name`))
melt(id.vars="Project name", variable.name="LED Area Attribute",
value.name="Square Footage") %>%
dplyr::mutate(`Type`="indoor") %>%
{.}
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 3
skipn = 3
df2 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Project name`, `LED Square Footage Illuminated`,
`Whole Application Sq Ft`) %>%
## summarize(n_distinct(`Project name`))
melt(id.vars="Project name", variable.name="LED Area Attribute",
value.name="Square Footage") %>%
dplyr::mutate(`Type`="outdoor") %>%
{.}
dplyr::bind_rows(df1, df2) %>%
ggplot() +
geom_boxplot(aes(y = `Square Footage`,
x = `LED Area Attribute`, fill=`Type`)) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
ylim(0, 1e+06) +
scale_x_discrete(labels =
function(x) stringr::str_wrap(x, width = 15)) +
theme()
ggsave(paste0("writeup/images/LEDarea", ".png"))
## LED cost
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 2
skipn = 3
plot_fields_categorical(sourcefile, sheetid, skipn, excludeCols,
"LED2")
df1 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Project name`, `System Cost ($)`) %>%
## summarize(n_distinct(`Project name`))
group_by(`Project name`, `System Cost ($)`) %>%
slice(1) %>%
dplyr::mutate(`Type`="indoor") %>%
{.}
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 3
skipn = 3
df2 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Project name`, `System Cost ($)`) %>%
## summarize(n_distinct(`Project name`))
group_by(`Project name`, `System Cost ($)`) %>%
slice(1) %>%
dplyr::mutate(`Type`="outdoor") %>%
{.}
dplyr::bind_rows(df1, df2) %>%
ggplot() +
geom_boxplot(aes(y = `System Cost ($)`, x=`Type`)) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
ylim(0, 1e+06) +
theme()
ggsave(paste0("writeup/images/LEDcost", ".png"))
## LED area ratio
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 2
skipn = 3
df1 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Building ID`, `Project name`,
`Whole Application Sq Ft`) %>%
left_join(df_area, by="Building ID") %>%
dplyr::mutate(`Application Sq Ft ratio`=`Whole Application Sq Ft`/`Gross_Sq.Ft`) %>%
dplyr::mutate(`Type`="indoor") %>%
{.}
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 3
skipn = 3
df2 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Building ID`, `Project name`,
`Whole Application Sq Ft`) %>%
left_join(df_area, by="Building ID") %>%
dplyr::mutate(`Application Sq Ft ratio`=`Whole Application Sq Ft`/`Gross_Sq.Ft`) %>%
dplyr::mutate(`Type`="outdoor") %>%
{.}
df1 %>%
ggplot() +
geom_boxplot(aes(x="", y = `Application Sq Ft ratio`)) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
xlab("indoor") +
theme()
ggsave(paste0("writeup/images/LEDarea_ratio", ".png"))
## LED time
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 2
skipn = 3
plot_fields_categorical(sourcefile, sheetid, skipn, excludeCols,
"LED2")
df1 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Building ID`, `Project name`,
`Substantial Completion Date`) %>%
dplyr::mutate(`Type`="indoor") %>%
{.}
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 3
skipn = 3
df2 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Building ID`, `Project name`,
`Substantial Completion Date`) %>%
dplyr::mutate(`Type`="outdoor") %>%
{.}
dplyr::bind_rows(df1, df2) %>%
ggplot() +
geom_boxplot(aes(y = `Substantial Completion Date`,
x = `Type`)) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
ggtitle("LED Project Substantial Completion Date") +
theme()
ggsave(paste0("writeup/images/LEDtime", ".png"))
## LED project count
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 2
skipn = 3
plot_fields_categorical(sourcefile, sheetid, skipn, excludeCols,
"LED2")
df1 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Building ID`, `Project name`,
`Substantial Completion Date`) %>%
dplyr::mutate(`Type`="indoor") %>%
{.}
sourcefile = "input/FY/ECM info/fwdgbuildoutputs/LED projects in gBUILD with SCDs 6-15-2017.xlsx"
sheetid = 3
skipn = 3
df2 = read_excel(sourcefile, sheetid, skip=skipn) %>%
as_data_frame() %>%
dplyr::select(`Building ID`, `Project name`,
`Substantial Completion Date`) %>%
dplyr::mutate(`Type`="outdoor") %>%
{.}
dplyr::bind_rows(df1, df2) %>%
group_by(`Project name`) %>%
slice(1) %>%
ggplot() +
geom_bar(aes(x=`Type`)) +
geom_text(stat='count', aes(x=`Type`, label=..count..),
vjust=-1) +
theme(axis.text.y = element_text(size=20)) +
theme(axis.text.x = element_text(size=20)) +
ggtitle("LED Project count") +
theme()
ggsave(paste0("writeup/images/LED_count", ".png"))