Commit 4160361e authored by Matteo DE FELICE's avatar Matteo DE FELICE

Polishing and bug fixing.

- Introduction of the yearly generation aggregates
- Bug fixing
parent 555069b7
......@@ -8,13 +8,13 @@ shinyServer(function(input, output, session) {
output$main_plot <- renderPlot({
# TODO Date is variable -> especially length out
res = readxl::read_xlsx(paste0('xls/', input$result_xls), sheet = 'Reservoirs') %>%
mutate(date = seq(as_datetime('2016-01-01'), as_datetime('2016-12-31'), length.out = 731))
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n()))
hrgen = readxl::read_xlsx(paste0('xls/', input$result_xls), sheet = 'Hydro power generation') %>%
mutate(date = seq(as_datetime('2016-01-01'), as_datetime('2016-12-31'), length.out = 731))
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n()))
gen = readxl::read_xlsx(paste0('xls/', input$result_xls), sheet = 'Generation') %>%
mutate(date = seq(as_datetime('2016-01-01'), as_datetime('2016-12-31'), length.out = 731))
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n()))
wv = readxl::read_xlsx(paste0('xls/', input$result_xls), sheet = 'Water value') %>%
mutate(date = seq(as_datetime('2016-01-01'), as_datetime('2016-12-31'), length.out = 731))
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n()))
# Load ENTSOE Data
entsoe_storage = read_rds('data/ENTSOE-Storage-2015-2018.rds')
# Average water value ---------------------------------------------------------------------
......@@ -44,14 +44,13 @@ shinyServer(function(input, output, session) {
select(-X__1 ) %>%
gather(source, value, -date) %>%
group_by(source) %>%
mutate(avg_cost = mean(value)) %>%
filter(avg_cost < 100)
mutate(avg_cost = mean(value))
g = ggplot(sel,
aes(x = date, y = fct_reorder(source, avg_cost),
fill = cut(value, right = FALSE, breaks = c(0, seq(10, 50, 5))))) +
aes(x = date, y = source, #y = fct_reorder(source, avg_cost),
fill = cut(value, right = FALSE, breaks = seq(0, max(sel$value)+0.1, length.out = 10)))) +
geom_tile() +
scale_fill_brewer(palette = 'YlOrRd', name = 'water value') +
scale_fill_brewer(palette = 'YlOrRd', name = 'water value', drop = FALSE) +
ylab('Zone') +
theme_minimal()
print(g)
......@@ -63,15 +62,16 @@ shinyServer(function(input, output, session) {
print(names(sel_zone))
color_palette = c('HPHS' = 'blue4',
'HDAM' = 'blue3',
'HROR' = 'blue2',
'PHOT' = 'yellow',
'SUN' = 'yellow',
'STUR' = 'brown4',
'GTUR' = 'brown2',
'WTON' = 'chartreuse2',
'WTOF' = 'chartreuse3',
'GAS' = 'brown2',
'WIN' = 'chartreuse2',
'BIO' = 'darkolivegreen1',
'COMC' = 'brown',
'OIL' = 'brown',
'HRD' = 'black')
g = sel_zone %>%
gather(source, generation, -date) %>%
mutate(source_type = str_split(source, '_', simplify = TRUE)[,2]) %>%
......@@ -87,6 +87,43 @@ shinyServer(function(input, output, session) {
geom_area()
print(g)
}
# Generation yearly ----------------------------------------------------------------------------
else if (input$plot_type == 'gen_year') {
gen_y = gen %>%
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n())) %>%
select(-X__1) %>%
gather(zone, generation, -date) %>%
mutate(country = str_split(zone, '_', simplify = TRUE)[,1],
type = str_split(zone, '_', simplify = TRUE)[,2],
year = lubridate::year(date)) %>%
group_by(year, country, type) %>%
summarise(generation = sum(generation))
color_palette = c('HPHS' = 'blue4',
'HDAM' = 'blue3',
'HROR' = 'blue2',
'SUN' = 'yellow',
'PHOT' = 'yellow',
'GTUR' = 'brown3',
'STUR' = 'brown4',
'GAS' = 'brown2',
'COMC' = 'brown2',
'WIN' = 'chartreuse2',
'WTOF' = 'chartreuse2',
'WTON' = 'chartreuse2',
'BIO' = 'darkolivegreen1',
'OIL' = 'brown',
'ICEN' = 'grey66',
'HRD' = 'black')
g = ggplot(gen_y, aes(x = country, y = generation, fill = type)) +
geom_bar(stat = 'identity') +
scale_fill_manual(values = color_palette) +
facet_wrap(~year, ncol = 1)
print(g)
}
# Reservoir levels single ------------------------------------------------------------------
else if (input$plot_type == 'res_single') {
......@@ -100,7 +137,7 @@ shinyServer(function(input, output, session) {
g = ggplot(res_zone, aes(x = day_of_the_year, y = value)) +
geom_line(size = 2) +
ylab('GWh/day') +
# ylab('GWh/day') +
theme(axis.text.x = element_text(size = 4, angle = 45, hjust = 1))
if (nrow(entsoe_data) > 0) {
g = g +
......@@ -111,13 +148,15 @@ shinyServer(function(input, output, session) {
} else if (input$plot_type == 'res_all') {
res_data = res %>% gather(zone, reservoir, -date, -X__1) %>%
select(-X__1)
select(-X__1) %>%
filter(!str_detect(zone, 'HROR'))
g = ggplot(res_data, aes(x = date, y = reservoir, color = zone, group = zone)) +
geom_line(size = 0.5) +
geom_line(size = 1) +
scale_y_log10() +
ylab('GWh/day') +
theme(axis.text.x = element_text(size = 4, angle = 45, hjust = 1))
# ylab('GWh/day') +
theme(axis.text.x = element_text(size = 6, angle = 45, hjust = 1),
legend.position = 'bottom')
print(g)
}
})
......
......@@ -17,9 +17,10 @@ shinyUI( fluidPage(
'heatmap water value' = 'hwv',
'reservoir levels (all)' = 'res_all',
'reservoir levels (single)' = 'res_single',
'generation mix' = 'gen_mix')),
'generation mix' = 'gen_mix',
'generation yearly' = 'gen_year')),
conditionalPanel(
condition = "input.plot_type == 'gen_mix'",
condition = "input.plot_type == 'gen_mix' || input.plot_type == 'res_single'",
uiOutput("zone_selection")
),
conditionalPanel(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment