-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.R
127 lines (103 loc) · 5.46 KB
/
server.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
function(input, output, session) {
# for easier debugging
if (islocal) source('modules/water_district_map.R')
# session state --------------------------------------------------------------
# handle selection of statewide vs utility view
vals <- reactiveValues(statewide = TRUE)
observeEvent(input$view_statewide, {vals$statewide <- TRUE})
observeEvent(input$view_utility, {vals$statewide <- FALSE})
# module ---------------------------------------------------------------------
util <- callModule(waterConservation, "water_districts",
water_monthly = water_byMonth,
statewide_monthly = statewide_byMonth,
map_data = water_districts,
id_field = 'pwsid',
name_field = 'pwsname',
statewide = reactive(vals$statewide))
# summary panels -------------------------------------------------------------
# total savings for current selection (util/state & time period)
savings <- reactive({
if (vals$statewide) {
ret <- util() %>%
filter(selected) %>%
summarise(MG_2013 = sum(MG_2013, na.rm = TRUE),
MG_cur = sum(MG_cur, na.rm = TRUE),
MG_saved = sum(MG_saved, na.rm = TRUE),
MWh_saved_all = sum(MWh_saved_all, na.rm = TRUE),
MWh_saved_iou = sum(MWh_saved_iou, na.rm = TRUE),
MT_CO2e_saved_all = sum(MT_CO2e_saved_all, na.rm = TRUE)) %>%
mutate(change_prop = MG_saved / MG_2013,
proportionChangeGoal = 0.25,
sav_diff = change_prop - proportionChangeGoal)
} else {
ret <- util() %>%
filter(selected) %>%
group_by(pwsid, out_all_kWh_mg, out_iou_kWh_mg) %>%
summarise(proportionChangeGoal = mean(ConservationStandard),
MG_2013 = sum(MG_2013),
MG_cur = sum(MG_cur)) %>%
mutate(MG_saved = MG_2013 - MG_cur,
change_prop = MG_saved / MG_2013,
sav_diff = change_prop - proportionChangeGoal,
MWh_saved_all = MG_saved * out_all_kWh_mg / 1e3,
MWh_saved_iou = MG_saved * out_iou_kWh_mg / 1e3,
MT_CO2e_saved_all = MWh_saved_all * ghg_factor_mt_mwh)
}
ret
})
output$savings <- reactive({
sprintf('%.1f%% (goal: %.f%%)', savings()$change_prop * 100, savings()$proportionChangeGoal * 100)
})
output$vs_std <- reactive({
sprintf('%+.1f%%', savings()$sav_diff * 100)
})
output$vs_std_label <- reactive({
switch(as.character(sign(savings()$sav_diff)), '-1' = '(Missed Target)', '0' = '(Met Target)', '1' = '(Savings Exceeding Target)', 'Vs Target')
})
output$energy_all <- reactive({
paste(format(round(savings()$MWh_saved_all), big.mark = ",", scientific = FALSE), 'MWh')
})
output$energy_iou <- reactive({
paste(format(round(savings()$MWh_saved_iou), big.mark = ",", scientific = FALSE), 'MWh')
})
output$ghg <- reactive({
paste(format(round(savings()$MT_CO2e_saved_all), big.mark = ",", scientific = FALSE), 'MT CO2e')
})
output$n_cars <- reactive({
format(round(savings()$MT_CO2e_saved_all / avg_car_mt_CO2), big.mark = ",", scientific = FALSE)
})
# summary charts -------------------------------------------------------------
output$energy_barchart <- renderHighchart({
eedata <- eedata_sav_summary %>% arrange(EndUse)
hchart(eedata, type = "column", hcaes(x = type, y = Gross_GWh, group = EndUse, color = col)) %>%
hc_title(text = "Electricity Savings from Statewide Water Conservation vs. Total First-Year Electricity Savings from Energy IOU Efficiency Programs<br/><b>(Jul 2015 - June 2016)</b>",
style = list(fontSize = '14px', useHTML = TRUE)) %>%
hc_xAxis(title = NULL
# categories = c('Energy Efficiency Programs<br/>by End Use Category',
# 'IOU Energy Savings Resulting<br>from Water Conservation',
# 'Total Energy Savings Resulting<br>from Water Conservation')
) %>%
hc_yAxis(title = list(text = "GWh Energy Saved"),
stackLabels = list(enabled = TRUE, style = list(fontWeight = 'bold', color = 'gray'),
formatter = JS('function() { return this.total.toFixed(1) + " GWh"; }'))) %>%
hc_plotOptions(column = list(stacking = 'normal', borderWidth = 0)) %>%
hc_colors(eedata$col) %>%
hc_tooltip(formatter = JS("function () { return this.point.series.name + '<br/>' + this.y.toFixed(1) + ' GWh'; }"))
})
output$cost_barchart <- renderHighchart({
elec_ce_data <- elec_ce_plot_data %>% arrange(-lcoe_dol2015_MWh_dr)
hchart(elec_ce_data, type = "bar", hcaes(x = program, y = lcoe_dol2015_MWh_dr, color = col)) %>%
hc_xAxis(title = NULL,
labels = list(formatter = JS('function() { return this.value.includes("Water") ? "<strong>" + this.value + "</strong>" : this.value; }'))) %>%
hc_yAxis(title = list(text = "Levelized Cost of Electricity Savings ($/MWh)"),
max = 275) %>%
hc_plotOptions(bar = list(
dataLabels = list(
enabled = TRUE,
style = list(fontWeight = 'bold', color = 'gray'),
formatter = JS('function() { return "$" + this.y.toFixed(0) + "/GWh"; }'))
)) %>%
hc_colors(elec_ce_data$col) %>%
hc_tooltip(formatter = JS("function () { return this.point.series.name + '<br/>' + '$' + this.y.toFixed(1) + '/MWh'; }"))
})
}