From 129c3d5f5dc6f9291f3c2b281448f9146837c321 Mon Sep 17 00:00:00 2001 From: Iury Date: Thu, 21 Sep 2023 16:54:30 -0300 Subject: [PATCH 1/4] - Scenarios reading update --- optgen/optgen-dashboard.lua | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/optgen/optgen-dashboard.lua b/optgen/optgen-dashboard.lua index c067d9c..5148e92 100644 --- a/optgen/optgen-dashboard.lua +++ b/optgen/optgen-dashboard.lua @@ -387,23 +387,6 @@ local has_network = identify_if_has_network(); --=================================================-- -- Utils --=================================================-- -local function load_dathisc(case) -- vai deixar de existir - local scenarios = study[case]:scenarios(); - local dathisc = generic[case]:load_table_without_header("dathisc.csv"); - - if dathisc then - local aux_table = {}; - for scn = 1, scenarios do - local data = generic[case]:create("SCN_" .. scn, "pu", { tonumber(dathisc[1 + scn][3]) }); - table.insert(aux_table, data); - end - - return concatenate_scenarios(aux_table); - end - - return nil; -end - local function by_day(data) -- vai deixar de existir if data:loaded() then local block_base = 24; @@ -439,7 +422,7 @@ local function by_day(data) -- vai deixar de existir data, data, data, data, data, data, data, data, data, data, data, data, data, data, data - } + }; end local function read_opt2_optgcoped(case) -- vai deixar de existir @@ -957,7 +940,7 @@ local function chart_defict_risk(case) :aggregate_stages(BY_SUM(), Profile.PER_YEAR) :remove_zeros(); - local dathisc = load_dathisc(case); + local dathisc = generic[case]:load("opt2_optgscen"); if dathisc then defict = ifelse(defict:gt(0), dathisc, 0):aggregate_scenarios(BY_SUM()):convert("%"):round(0); else @@ -999,7 +982,7 @@ local function chart_generation_in_season(case) local defict = generic[case]:load("opt2_deficitmw"):aggregate_blocks(BY_AVERAGE()) :aggregate_blocks(BY_SUM()):round(0); - local dathisc = load_dathisc(case); + local dathisc = generic[case]:load("opt2_optgscen"); if dathisc then thermal_gen = (thermal_gen * dathisc):aggregate_scenarios(BY_SUM()); hidro_gen = (hidro_gen * dathisc):aggregate_scenarios(BY_SUM()); @@ -1062,7 +1045,7 @@ local function chart_hourly_generation_typical_day(case) local defict = generic[case]:load("opt2_deficitmw") -- com problema :aggregate_agents(BY_SUM(),dictionary.deficit[language]); - local dathisc = load_dathisc(case); + local dathisc = generic[case]:load("opt2_optgscen"); if dathisc then thermal_gen = (thermal_gen * dathisc):aggregate_scenarios(BY_SUM()); hidro_gen = (hidro_gen * dathisc):aggregate_scenarios(BY_SUM()); From b5976ec14d4b1011dec4b7fd6d4ecd64cc5d60fb Mon Sep 17 00:00:00 2001 From: Iury Date: Fri, 22 Sep 2023 18:05:22 -0300 Subject: [PATCH 2/4] Update Optgen script --- optgen/optgen-dashboard.lua | 380 ++++++++++++++++++++---------------- 1 file changed, 209 insertions(+), 171 deletions(-) diff --git a/optgen/optgen-dashboard.lua b/optgen/optgen-dashboard.lua index 5148e92..48f2872 100644 --- a/optgen/optgen-dashboard.lua +++ b/optgen/optgen-dashboard.lua @@ -1,4 +1,4 @@ --- C:\Users\iury\Desktop\PSRio_Atual\psrio.exe --model OPTGEN -r "D:\SDDP_1\sddp\psrio-scripts\sddp\sddp-dashlib.lua,D:\PSRIO-scripts\optgen\optgen-dashboard.lua" "D:\Dropbox (PSR)\PSR_main\OPTGEN\DASHBOARD\caso_timing" +-- C:\Users\iury\Desktop\PSRio_Atual\psrio.exe --model OPTGEN -r "D:\SDDP_1\sddp\psrio-scripts\sddp\sddp-dashlib.lua,D:\PSRIO-scripts\optgen\optgen-dashboard.lua" "D:\Dropbox (PSR)\PSR_main\OPTGEN\DASHBOARD\caso_teste_new" --=================================================-- -- Create Vectors of collections --=================================================-- @@ -314,6 +314,21 @@ local dictionary = { en = "Objective function", es = "Función objetivo", pt = "Função objetivo" + }, + data_not_exist = { + en = "None data to graph", + es = "Ningún dato para graficar", + pt = "Nenhum dado para graficar" + }, + GAP = { + en = "GAP", + es = "GAP", + pt = "GAP" + }, + convergence = { + en = "Convergence", + es = "Convergencia", + pt = "Convergência" } }; @@ -336,7 +351,8 @@ local plot = { generation_in_each_season = true, hourly_generation_typical = true, objective_function = true, - risk_curve = true + risk_curve = true, + convergence = true }; --=================================================-- -- Get parameters Functions @@ -356,7 +372,7 @@ end local function identify_if_opt2() for case = 1, cases do - if not study[case]:get_parameter("Keywords", "OPTG", -1) == 2 then + if study[case]:get_parameter("Keywords", "OPTG", -1) ~= 2 then return false; end end @@ -381,7 +397,6 @@ end local language = load_language(); local is_opt2 = identify_if_opt2(); - local has_network = identify_if_has_network(); --=================================================-- @@ -422,14 +437,14 @@ local function by_day(data) -- vai deixar de existir data, data, data, data, data, data, data, data, data, data, data, data, data, data, data - }; + } end local function read_opt2_optgcoped(case) -- vai deixar de existir local opt2_optgcoped = generic[case]:load_table_without_header("opt2_optgcoped.csv"); - + local N_col = #opt2_optgcoped[3]; local aux_table = {}; - for col = 2, 15 do + for col = 2, N_col do local data = generic[case]:create(opt2_optgcoped[3][col], "M$", { tonumber(opt2_optgcoped[4][col]) }); table.insert(aux_table, data); end @@ -493,29 +508,21 @@ end -- Create Charts Functions --=================================================-- local function chart_accumulated_capacity(case) - local thermal_agents = thermal[case]:labels(); - local hydro_agents = hydro[case]:labels(); - local battery_agents = battery[case]:labels(); - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - - local outidec = generic[case]:load("outidec"); + local outidec = expansionproject[case]:load("outidec"); - local thermal_cap = outidec:select_agents(thermal_agents) + local thermal_cap = outidec:select_agents(Collection.THERMAL) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); - local hydro_cap = outidec:select_agents(hydro_agents) + local hydro_cap = outidec:select_agents(Collection.HYDRO) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); - local renewable_cap = outidec:select_agents(others_agents) + local renewable_cap = outidec:select_agents(Collection.RENEWABLE):select_agents(renewable[case].tech_type:ne(1 | 2 | 5)) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); - local solar_cap = outidec:select_agents(solar_agents) + local solar_cap = outidec:select_agents(Collection.RENEWABLE):select_agents(renewable[case].tech_type:eq(2)) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); - local wind_cap = outidec:select_agents(wind_agents) + local wind_cap = outidec:select_agents(Collection.RENEWABLE):select_agents(renewable[case].tech_type:eq(1)) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); - local csp_cap = outidec:select_agents(csp_agents) + local csp_cap = outidec:select_agents(Collection.RENEWABLE):select_agents(renewable[case].tech_type:eq(5)) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); - local battery_cap = outidec:select_agents(battery_agents) + local battery_cap = outidec:select_agents(Collection.BATTERY) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); @@ -528,49 +535,36 @@ local function chart_accumulated_capacity(case) chart:add_column_stacking(csp_cap:aggregate_agents(BY_SUM(), dictionary.total_csp[language]), { color = colors.total_generation.csp }); chart:add_column_stacking(battery_cap:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); - if #chart == 0 then - plot.accumulated_capacity = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; end local function chart_circuit_accumulated_capacity(case) - local circuit_agents = circuit[case]:labels(); - local dclink_agents = dclink[case]:labels(); + local outidec = expansionproject[case]:load("outidec"); - local outidec = generic[case]:load("outidec"); - - local ac_cap = outidec:select_agents(circuit_agents) + local ac_cap = outidec:select_agents(Collection.CIRCUIT) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR); - local dc_cap = outidec:select_agents(dclink_agents) + local dc_cap = outidec:select_agents(Collection.DCLINK) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR); local chart = create_chart("", case); chart:add_column_stacking(ac_cap:aggregate_agents(BY_SUM(), dictionary.total_ac_circuit[language]):round(0), { color = colors.total_circuit.ac }); chart:add_column_stacking(dc_cap:aggregate_agents(BY_SUM(), dictionary.total_hydro[language]):round(0), { color = colors.total_circuit.dc }); - if #chart == 0 then - plot.circuit_accumulated_capacity = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; end local function chart_total_cost(case) - local thermal_agents = thermal[case]:labels(); - local hydro_agents = hydro[case]:labels(); - local battery_agents = battery[case]:labels(); - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - local circuit_agents = circuit[case]:labels(); - local dclink_agents = dclink[case]:labels(); - local objcop = generic[case]:load("objcop"):aggregate_blocks(BY_SUM()):aggregate_scenarios(BY_AVERAGE()); local outdfact = generic[case]:load("outdfact"); - local outdisbu = generic[case]:load("outdisbu"):aggregate_blocks(BY_SUM()):aggregate_scenarios(BY_AVERAGE()) * outdfact; + local outdisbu = expansionproject[case]:load("outdisbu"):aggregate_blocks(BY_SUM()):aggregate_scenarios(BY_AVERAGE()) * outdfact; local costs; if study[case]:is_hourly() then @@ -580,15 +574,23 @@ local function chart_total_cost(case) end local inv_total = outdisbu:aggregate_stages(BY_SUM()):round(0); - local inv_therm = outdisbu:select_agents(thermal_agents):aggregate_stages(BY_SUM()):round(0); - local inv_hydro = outdisbu:select_agents(hydro_agents ):aggregate_stages(BY_SUM()):round(0); - local inv_batte = outdisbu:select_agents(battery_agents):aggregate_stages(BY_SUM()):round(0); - local inv_solar = outdisbu:select_agents(solar_agents ):aggregate_stages(BY_SUM()):round(0); - local inv_wind = outdisbu:select_agents(wind_agents ):aggregate_stages(BY_SUM()):round(0); - local inv_csp = outdisbu:select_agents(csp_agents ):aggregate_stages(BY_SUM()):round(0); - local inv_other = outdisbu:select_agents(others_agents ):aggregate_stages(BY_SUM()):round(0); - local inv_ac = outdisbu:select_agents(circuit_agents):aggregate_stages(BY_SUM()):round(0); - local inv_dc = outdisbu:select_agents(dclink_agents ):aggregate_stages(BY_SUM()):round(0); + local inv_therm = outdisbu:select_agents(Collection.THERMAL):aggregate_stages(BY_SUM()):round(0); + local inv_hydro = outdisbu:select_agents(Collection.HYDRO ):aggregate_stages(BY_SUM()):round(0); + local inv_batte = outdisbu:select_agents(Collection.BATTERY):aggregate_stages(BY_SUM()):round(0); + local inv_solar = outdisbu:select_agents(Collection.RENEWABLE) + :select_agents(renewable[case].tech_type:eq(2) ) + :aggregate_stages(BY_SUM()):round(0); + local inv_wind = outdisbu:select_agents(Collection.RENEWABLE) + :select_agents(renewable[case].tech_type:eq(1) ) + :aggregate_stages(BY_SUM()):round(0); + local inv_csp = outdisbu:select_agents(Collection.RENEWABLE) + :select_agents(renewable[case].tech_type:eq(5) ) + :aggregate_stages(BY_SUM()):round(0); + local inv_other = outdisbu:select_agents(Collection.RENEWABLE) + :select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) + :aggregate_stages(BY_SUM()):round(0); + local inv_ac = outdisbu:select_agents(Collection.CIRCUIT):aggregate_stages(BY_SUM()):round(0); + local inv_dc = outdisbu:select_agents(Collection.DCLINK ):aggregate_stages(BY_SUM()):round(0); local chart_a = create_chart("", case); chart_a:add_pie(costs:aggregate_agents(BY_SUM(), dictionary.total_operational_costs[language]), { color = colors.total_costs.operational }); @@ -606,28 +608,27 @@ local function chart_total_cost(case) chart_b:add_pie(inv_dc:aggregate_agents(BY_SUM(), dictionary.total_dc_circuit[language]), { color = colors.total_costs.dc }); if #chart_a == 0 or #chart_b == 0 then - plot.total_cost = false; + return dictionary.data_not_exist[language]; end - + return { chart_a, chart_b }; end local function chart_total_installed_capacity(case) - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - local renewable_cap_ind = renewable[case]:load("pnomnd"); local thermal_cap = thermal[case]:load("pnomtr"):round(0); local hydro_cap = hydro[case]:load("pnomhd"):round(0); local batte_cap = battery[case]:load("pnombat"):round(0); - local renewable_cap = renewable_cap_ind:select_agents(others_agents):aggregate_scenarios(BY_AVERAGE()):round(0); - local solar_cap = renewable_cap_ind:select_agents(solar_agents):aggregate_scenarios(BY_AVERAGE()):round(0); - local wind_cap = renewable_cap_ind:select_agents(wind_agents):aggregate_scenarios(BY_AVERAGE()):round(0); - local csp_cap = renewable_cap_ind:select_agents(csp_agents):aggregate_scenarios(BY_AVERAGE()):round(0); - local bat_cap = batte_cap:select_agents(batte_cap):aggregate_scenarios(BY_AVERAGE()):round(0); + local renewable_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) + :aggregate_scenarios(BY_AVERAGE()):round(0); + local solar_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(2) ) + :aggregate_scenarios(BY_AVERAGE()):round(0); + local wind_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(1) ) + :aggregate_scenarios(BY_AVERAGE()):round(0); + local csp_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(5) ) + :aggregate_scenarios(BY_AVERAGE()):round(0); + local bat_cap = batte_cap:aggregate_scenarios(BY_AVERAGE()):round(0); local chart = create_chart("", case); chart:add_area_spline_stacking(thermal_cap:aggregate_agents(BY_SUM(), dictionary.total_thermal[language]), { color = colors.total_generation.thermal }); @@ -638,33 +639,32 @@ local function chart_total_installed_capacity(case) chart:add_area_spline_stacking(csp_cap:aggregate_agents(BY_SUM(), dictionary.total_csp[language]), { color = colors.total_generation.csp }); chart:add_area_spline_stacking(bat_cap:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); - if #chart == 0 then - plot.total_installed_capacity = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; end local function chart_total_installed_capacity_mix(case) - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - local renewable_cap_ind = renewable[case]:load("pnomnd"):aggregate_stages(BY_MAX()); local thermal_cap = thermal[case]:load("pnomtr"):aggregate_stages(BY_MAX()):round(0); local hydro_cap = hydro[case]:load("pnomhd"):aggregate_stages(BY_MAX()):round(0); local batte_cap = battery[case]:load("pnombat"):aggregate_stages(BY_MAX()):round(0); - local renewable_cap = renewable_cap_ind:select_agents(others_agents):aggregate_scenarios(BY_AVERAGE()):round(0); - local solar_cap = renewable_cap_ind:select_agents(solar_agents):aggregate_scenarios(BY_AVERAGE()):round(0); - local wind_cap = renewable_cap_ind:select_agents(wind_agents):aggregate_scenarios(BY_AVERAGE()):round(0); - local csp_cap = renewable_cap_ind:select_agents(csp_agents):aggregate_scenarios(BY_AVERAGE()):round(0); - local bat_cap = batte_cap:select_agents(batte_cap):aggregate_stages(BY_MAX()):aggregate_scenarios(BY_AVERAGE()):round(0); + local renewable_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) + :aggregate_scenarios(BY_AVERAGE()):round(0); + local solar_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(2) ) + :aggregate_scenarios(BY_AVERAGE()):round(0); + local wind_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(1) ) + :aggregate_scenarios(BY_AVERAGE()):round(0); + local csp_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(5) ) + :aggregate_scenarios(BY_AVERAGE()):round(0); + local bat_cap = batte_cap:aggregate_scenarios(BY_AVERAGE()):round(0); local vector_of_charts = {}; local initial_year = study[case]:initial_year(); - local final_year = thermal_cap:final_year(); + local final_year = study[case]:final_year(); -- for year = initial_year,final_year do for _, year in ipairs({ initial_year, final_year }) do local chart = create_chart("Year - "..year, case); @@ -684,8 +684,8 @@ local function chart_total_installed_capacity_mix(case) chart:add_pie(csp_cap_annual:aggregate_agents(BY_SUM(), dictionary.total_csp[language]), { color = colors.total_generation.csp }); chart:add_pie(bat_cap_annual:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); - if #chart == 0 then - plot.accumulated_capacity = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end table.insert(vector_of_charts, chart); @@ -694,20 +694,19 @@ local function chart_total_installed_capacity_mix(case) end local function chart_firm_capacity(case) - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - local firm_capacity_renew = renewable[case]:load("outrpa"):round(0); local firm_capacity_hydro = hydro[case]:load("outhpa"):round(0); local firm_capacity_therm = thermal[case]:load("outtpa"):round(0); local firm_capacity_batte = battery[case]:load("outbpa"):round(0); - local firm_capacity_solar = firm_capacity_renew:select_agents(solar_agents):aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); - local firm_capacity_wind = firm_capacity_renew:select_agents(wind_agents):aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); - local firm_capacity_csp = firm_capacity_renew:select_agents(csp_agents):aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); - local firm_capacity_renew = firm_capacity_renew:select_agents(others_agents):aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); - + local firm_capacity_renew = firm_capacity_renew:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) + :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); + local firm_capacity_solar = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(2) ) + :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); + local firm_capacity_wind = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(1) ) + :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); + local firm_capacity_csp = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(5) ) + :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); + local chart = create_chart("", case); chart:add_area_spline_stacking(firm_capacity_therm:aggregate_agents(BY_SUM(), dictionary.total_thermal[language]), { color = colors.total_generation.thermal }); chart:add_area_spline_stacking(firm_capacity_hydro:aggregate_agents(BY_SUM(), dictionary.total_hydro[language]), { color = colors.total_generation.hydro }); @@ -717,31 +716,30 @@ local function chart_firm_capacity(case) chart:add_area_spline_stacking(firm_capacity_csp:aggregate_agents(BY_SUM(), dictionary.total_csp[language]), { color = colors.total_generation.csp }); chart:add_area_spline_stacking(firm_capacity_batte:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); - if #chart == 0 then - plot.firm_capacity = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; end local function chart_firm_capacity_mix(case) - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - local firm_capacity_renew = renewable[case]:load("outrpa"):round(0); local firm_capacity_hydro = hydro[case]:load("outhpa"):round(0); local firm_capacity_therm = thermal[case]:load("outtpa"):round(0); local firm_capacity_batte = battery[case]:load("outbpa"):round(0); - local firm_capacity_solar = firm_capacity_renew:select_agents(solar_agents):aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); - local firm_capacity_wind = firm_capacity_renew:select_agents(wind_agents):aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); - local firm_capacity_csp = firm_capacity_renew:select_agents(csp_agents):aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); - local firm_capacity_renew = firm_capacity_renew:select_agents(others_agents):aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); + local firm_capacity_solar = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(2) ) + :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); + local firm_capacity_wind = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(1) ) + :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); + local firm_capacity_csp = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(5) ) + :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); + local firm_capacity_renew = firm_capacity_renew:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) + :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); local vector_of_charts = {}; local initial_year = study[case]:initial_year(); - local final_year = firm_capacity_therm:final_year(); -- mudar + local final_year = firm_capacity_therm:final_year(); -- for year = initial_year,final_year do for _, year in ipairs({ initial_year, final_year }) do @@ -762,8 +760,8 @@ local function chart_firm_capacity_mix(case) chart:add_pie(csp_cap_annual:aggregate_agents(BY_SUM(), dictionary.total_csp[language]), { color = colors.total_generation.csp }); chart:add_pie(bat_cap_annual:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); - if #chart == 0 then - plot.firm_capacity_mix = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end table.insert(vector_of_charts, chart); @@ -773,19 +771,18 @@ local function chart_firm_capacity_mix(case) end local function chart_firm_energy(case) - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - local firm_energy_renew = renewable[case]:load("outrea"):round(0); local firm_energy_hydro = hydro[case]:load("outhea"):round(0); local firm_energy_therm = thermal[case]:load("outtea"):round(0); local firm_energy_batte = battery[case]:load("outbea"):round(0); - local firm_energy_solar = firm_energy_renew:select_agents(solar_agents):aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); - local firm_energy_wind = firm_energy_renew:select_agents(wind_agents):aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); - local firm_energy_csp = firm_energy_renew:select_agents(csp_agents):aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); - local firm_energy_renew = firm_energy_renew:select_agents(others_agents):aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); + local firm_energy_solar = firm_energy_renew:select_agents(renewable[case].tech_type:eq(2) ) + :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); + local firm_energy_wind = firm_energy_renew:select_agents(renewable[case].tech_type:eq(1) ) + :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); + local firm_energy_csp = firm_energy_renew:select_agents(renewable[case].tech_type:eq(5) ) + :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); + local firm_energy_renew = firm_energy_renew:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) + :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); local chart = create_chart("", case); chart:add_area_spline_stacking(firm_energy_therm:aggregate_agents(BY_SUM(), dictionary.total_thermal[language]), { color = colors.total_generation.thermal }); @@ -796,27 +793,26 @@ local function chart_firm_energy(case) chart:add_area_spline_stacking(firm_energy_csp:aggregate_agents(BY_SUM(), dictionary.total_csp[language]), { color = colors.total_generation.csp }); chart:add_area_spline_stacking(firm_energy_batte:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); - if #chart == 0 then - plot.firm_energy = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; end local function chart_firm_energy_mix(case) - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - local firm_energy_renew = renewable[case]:load("outrea"):round(0); local firm_energy_hydro = hydro[case]:load("outhea"):round(0); local firm_energy_therm = thermal[case]:load("outtea"):round(0); local firm_energy_batte = battery[case]:load("outbea"):round(0); - local firm_energy_solar = firm_energy_renew:select_agents(solar_agents):aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); - local firm_energy_wind = firm_energy_renew:select_agents(wind_agents):aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); - local firm_energy_csp = firm_energy_renew:select_agents(csp_agents):aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); - local firm_energy_renew = firm_energy_renew:select_agents(others_agents):aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); + local firm_energy_solar = firm_energy_renew:select_agents(renewable[case].tech_type:eq(2) ) + :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); + local firm_energy_wind = firm_energy_renew:select_agents(renewable[case].tech_type:eq(1) ) + :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); + local firm_energy_csp = firm_energy_renew:select_agents(renewable[case].tech_type:eq(5) ) + :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); + local firm_energy_renew = firm_energy_renew:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) + :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); local vector_of_charts = {}; local initial_year = study[case]:initial_year(); @@ -842,8 +838,8 @@ local function chart_firm_energy_mix(case) chart:add_pie(csp_cap_annual:aggregate_agents(BY_SUM(), dictionary.total_csp[language]), { color = colors.total_generation.csp }); chart:add_pie(bat_cap_annual:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); - if #chart == 0 then - plot.firm_capacitymix = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end table.insert(vector_of_charts, chart); @@ -868,8 +864,8 @@ local function chart_annual_marginal_cost(case) local chart = create_chart("", case); chart:add_line(cmgdem, { color = colors.generic }); - if #chart == 0 then - plot.annual_marginal_cost = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; @@ -890,8 +886,8 @@ local function chart_monthly_marginal_cost(case) local chart = create_chart("", case); chart:add_line(cmgdem, { color = colors.generic }); - if #chart == 0 then - plot.monthly_marginal_cost = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; @@ -920,8 +916,8 @@ local function chart_hourly_marginal_cost_per_typical_day(case) chart:add_line(day_data:select_stage(month), { color = colors.generic }); table.insert(vector_of_charts, chart); - if #chart == 0 then - plot.hourly_generation_typical = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end end @@ -940,7 +936,13 @@ local function chart_defict_risk(case) :aggregate_stages(BY_SUM(), Profile.PER_YEAR) :remove_zeros(); - local dathisc = generic[case]:load("opt2_optgscen"); + local stage_type; + if defict:loaded() then + stage_type = defict:stage_type(); + else + stage_type = 1; + end + local dathisc = generic[case]:load("opt2_optgscen"):select_stage(1):set_stage_type(stage_type); if dathisc then defict = ifelse(defict:gt(0), dathisc, 0):aggregate_scenarios(BY_SUM()):convert("%"):round(0); else @@ -950,39 +952,40 @@ local function chart_defict_risk(case) local chart = create_chart("", case); chart:add_line(defict, { color = colors.risk.deficit }); - if #chart == 0 then - plot.deficit_risk = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; end -local function chart_generation_in_season(case) - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - +local function chart_generation_in_season(case) local renewable_gen_ind = renewable[case]:load("opt2_gergndmw"):aggregate_blocks(BY_AVERAGE()) local thermal_gen = generic[case]:load("opt2_gertermw"):aggregate_blocks(BY_AVERAGE()) -- problemas :aggregate_blocks(BY_SUM()):round(0); local hidro_gen = hydro[case]:load("opt2_gerhidmw"):aggregate_blocks(BY_AVERAGE()) :aggregate_blocks(BY_SUM()):round(0); - local renewable_gen = renewable_gen_ind:select_agents(others_agents) + local renewable_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) :aggregate_blocks(BY_SUM()):round(0); - local solar_gen = renewable_gen_ind:select_agents(solar_agents) + local solar_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:eq(2)) :aggregate_blocks(BY_SUM()):round(0); - local wind_gen = renewable_gen_ind:select_agents(wind_agents) + local wind_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:eq(1)) :aggregate_blocks(BY_SUM()):round(0); - local csp_gen = renewable_gen_ind:select_agents(csp_agents) + local csp_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:eq(5)) :aggregate_blocks(BY_SUM()):round(0); local battery = battery[case]:load("opt2_gerbatmw"):aggregate_blocks(BY_AVERAGE()) :aggregate_blocks(BY_SUM()):round(0); local defict = generic[case]:load("opt2_deficitmw"):aggregate_blocks(BY_AVERAGE()) :aggregate_blocks(BY_SUM()):round(0); - local dathisc = generic[case]:load("opt2_optgscen"); + local stage_type; + if defict:loaded() then + stage_type = defict:stage_type(); + else + stage_type = 1; + end + local dathisc = generic[case]:load("opt2_optgscen"):select_stage(1):set_stage_type(stage_type); if dathisc then thermal_gen = (thermal_gen * dathisc):aggregate_scenarios(BY_SUM()); hidro_gen = (hidro_gen * dathisc):aggregate_scenarios(BY_SUM()); @@ -1013,39 +1016,40 @@ local function chart_generation_in_season(case) chart:add_area_spline_stacking(battery:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); chart:add_area_spline_stacking(defict:aggregate_agents(BY_SUM(), dictionary.deficit[language]), { color = colors.total_generation.defict }); - if #chart == 0 then - plot.generation_in_each_season = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; end local function chart_hourly_generation_typical_day(case) - local solar_agents = renewable[case].tech_type:eq(1):remove_zeros():agents(); - local wind_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(2)):agents(); - local csp_agents = renewable[case].state:select_agents(renewable[case].tech_type:eq(5)):agents(); - local others_agents = renewable[case].state:remove_agents(solar_agents):remove_agents(wind_agents):remove_agents(csp_agents):agents(); - local renewable_gen_ind = renewable[case]:load("opt2_gergndmw") - local thermal_gen = generic[case]:load("opt2_gertermw") -- com problema + local thermal_gen = thermal[case]:load("opt2_gertermw") :aggregate_agents(BY_SUM(),dictionary.total_thermal[language]); local hidro_gen = hydro[case]:load("opt2_gerhidmw") :aggregate_agents(BY_SUM(),dictionary.total_hydro[language]); - local renewable_gen = renewable_gen_ind:select_agents(others_agents) + local renewable_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) :aggregate_agents(BY_SUM(),dictionary.total_renewable[language]); - local solar_gen = renewable_gen_ind:select_agents(solar_agents) + local solar_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:eq(2) ) :aggregate_agents(BY_SUM(),dictionary.total_solar[language]); - local wind_gen = renewable_gen_ind:select_agents(wind_agents) + local wind_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:eq(1) ) :aggregate_agents(BY_SUM(),dictionary.total_wind[language]); - local csp_gen = renewable_gen_ind:select_agents(csp_agents) + local csp_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:eq(5) ) :aggregate_agents(BY_SUM(),dictionary.total_csp[language]); local battery = battery[case]:load("opt2_gerbat") :aggregate_agents(BY_SUM(),dictionary.total_battery[language]); local defict = generic[case]:load("opt2_deficitmw") -- com problema :aggregate_agents(BY_SUM(),dictionary.deficit[language]); - local dathisc = generic[case]:load("opt2_optgscen"); + local stage_type; + if defict:loaded() then + stage_type = defict:stage_type(); + else + stage_type = 1; + end + local dathisc = generic[case]:load("opt2_optgscen"):select_stage(1):set_stage_type(stage_type); if dathisc then thermal_gen = (thermal_gen * dathisc):aggregate_scenarios(BY_SUM()); hidro_gen = (hidro_gen * dathisc):aggregate_scenarios(BY_SUM()); @@ -1067,22 +1071,21 @@ local function chart_hourly_generation_typical_day(case) end local vector_of_chart = {}; - local N_typical_day,day_thermal_gen = by_day(thermal_gen ); + local _,day_thermal_gen = by_day(thermal_gen ); local _ ,day_hidro_gen = by_day(hidro_gen ); local _ ,day_renewable_gen = by_day(renewable_gen); local _ ,day_solar_gen = by_day(solar_gen ); local _ ,day_wind_gen = by_day(wind_gen ); local _ ,day_csp_gen = by_day(csp_gen ); local _ ,day_battery = by_day(battery ); - local _ ,day_defict = by_day(defict ); - + local N_typical_day,day_defict = by_day(defict ); if not N_typical_day then -- mudar error("N_typical_day nil"); end local initial_year = study[case]:initial_year(); - local final_year = thermal_gen:final_year(); + local final_year = defict:final_year(); for year = initial_year,initial_year do -- mudar local first_stg = 1; local final_stga = study[case]:stages_per_year(); @@ -1119,8 +1122,8 @@ local function chart_hourly_generation_typical_day(case) chart:add_area_spline_stacking(year_day_battery , { color = colors.total_generation.battery }); chart:add_area_spline_stacking(year_day_defict , { color = colors.total_generation.defict }); - if #chart == 0 then - plot.hourly_generation_typical = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end table.insert(vector_of_chart, chart); @@ -1137,8 +1140,8 @@ local function chart_objective_value(case) local chart = create_chart("", case); chart:add_pie(opt2_optgcoped, { color = colors.generic }); - if #chart == 0 then - plot.objective_function = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; @@ -1162,8 +1165,22 @@ local function chart_risk_curve(case) opt2_format_to_chart_scatterplot(year, { LHS, FObj }, { "LHS", "FObj" }, chart, "K$", case); end - if #chart == 0 then - plot.risk_curve = false; + if #chart <= 0 then + return dictionary.data_not_exist[language]; + end + + return chart; +end + +local function chart_convergence(case) + local chart = create_chart("", case); + + local gap = generic[case]:load("opt2_optgconv"):select_agent("Gap"):rename_agents({dictionary.GAP[language]}); + + chart:add_line(gap); + + if #chart <= 0 then + return dictionary.data_not_exist[language]; end return chart; @@ -1298,6 +1315,7 @@ local function tab_optgen2_reports() for case = 1, cases do local chart = chart_hourly_generation_typical_day(case); tab:push(chart); + end end @@ -1306,6 +1324,15 @@ local function tab_optgen2_reports() for case = 1, cases do local chart = chart_objective_value(case); tab:push(chart); + + end + end + + if plot.convergence then + tab:push("### " .. dictionary.convergence[language]); + for case = 1, cases do + local chart = chart_convergence(case); + tab:push(chart); end end @@ -1320,6 +1347,7 @@ local function tab_risk_result() for case = 1, cases do local chart = chart_risk_curve(case); tab:push(chart); + end end @@ -1348,6 +1376,9 @@ local function tab_sddp() local info_struct = {}; for i = 1, cases do + if not Study(i):file_exists("sddp.info") then + return + end generic_collections[i] = Generic(i); end @@ -1357,8 +1388,15 @@ local function tab_sddp() return tab end --- Create SDDP Tab +--=================================================-- +-- Create Dashboard +--=================================================-- local dashboard = Dashboard(); dashboard:push(tab_expansion_result()); -dashboard:push(tab_sddp()); + +local sddp_tab = tab_sddp(); +if sddp_tab then + dashboard:push(sddp_tab); +end + dashboard:save("dashboard"); From fafe0051aeae96df085e0cd5e6059976b2057c7e Mon Sep 17 00:00:00 2001 From: Iury Date: Mon, 25 Sep 2023 09:30:36 -0300 Subject: [PATCH 3/4] - Script corrections --- optgen/optgen-dashboard.lua | 181 ++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 90 deletions(-) diff --git a/optgen/optgen-dashboard.lua b/optgen/optgen-dashboard.lua index 48f2872..f070821 100644 --- a/optgen/optgen-dashboard.lua +++ b/optgen/optgen-dashboard.lua @@ -177,8 +177,8 @@ local dictionary = { }, total_hydro = { en = "Total hydro", - es = "Total hydro", - pt = "Total hydro" + es = "Total hidro", + pt = "Total hidro" }, total_renewable = { en = "Total others renewable", @@ -344,6 +344,7 @@ local plot = { firm_capacity = true, firm_capacity_mix = true, firm_energy = true, + firm_energy_mix = true, annual_marginal_cost = true, monthly_marginal_cost = true, hourly_marginal_cost_typical = true, @@ -511,19 +512,19 @@ local function chart_accumulated_capacity(case) local outidec = expansionproject[case]:load("outidec"); local thermal_cap = outidec:select_agents(Collection.THERMAL) - :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); + :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):remove_zeros():round(0); local hydro_cap = outidec:select_agents(Collection.HYDRO) - :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); + :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):remove_zeros():round(0); local renewable_cap = outidec:select_agents(Collection.RENEWABLE):select_agents(renewable[case].tech_type:ne(1 | 2 | 5)) - :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); + :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):remove_zeros():round(0); local solar_cap = outidec:select_agents(Collection.RENEWABLE):select_agents(renewable[case].tech_type:eq(2)) - :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); + :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):remove_zeros():round(0); local wind_cap = outidec:select_agents(Collection.RENEWABLE):select_agents(renewable[case].tech_type:eq(1)) - :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); + :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):remove_zeros():round(0); local csp_cap = outidec:select_agents(Collection.RENEWABLE):select_agents(renewable[case].tech_type:eq(5)) - :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); + :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):remove_zeros():round(0); local battery_cap = outidec:select_agents(Collection.BATTERY) - :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):round(0); + :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR):remove_zeros():round(0); local chart = create_chart("", case); @@ -551,8 +552,8 @@ local function chart_circuit_accumulated_capacity(case) :aggregate_stages(BY_LAST_VALUE(),Profile.PER_YEAR); local chart = create_chart("", case); - chart:add_column_stacking(ac_cap:aggregate_agents(BY_SUM(), dictionary.total_ac_circuit[language]):round(0), { color = colors.total_circuit.ac }); - chart:add_column_stacking(dc_cap:aggregate_agents(BY_SUM(), dictionary.total_hydro[language]):round(0), { color = colors.total_circuit.dc }); + chart:add_column_stacking(ac_cap:aggregate_agents(BY_SUM(), dictionary.total_ac_circuit[language]):remove_zeros():round(0), { color = colors.total_circuit.ac }); + chart:add_column_stacking(dc_cap:aggregate_agents(BY_SUM(), dictionary.total_hydro[language]):remove_zeros():round(0), { color = colors.total_circuit.dc }); if #chart <= 0 then return dictionary.data_not_exist[language]; @@ -573,24 +574,24 @@ local function chart_total_cost(case) costs = (objcop:remove_agents({1}):remove_agents({-1}) * outdfact):aggregate_stages(BY_SUM()); -- remove total cost -- remove future cost end - local inv_total = outdisbu:aggregate_stages(BY_SUM()):round(0); - local inv_therm = outdisbu:select_agents(Collection.THERMAL):aggregate_stages(BY_SUM()):round(0); - local inv_hydro = outdisbu:select_agents(Collection.HYDRO ):aggregate_stages(BY_SUM()):round(0); - local inv_batte = outdisbu:select_agents(Collection.BATTERY):aggregate_stages(BY_SUM()):round(0); + local inv_total = outdisbu:aggregate_stages(BY_SUM()):remove_zeros():round(0); + local inv_therm = outdisbu:select_agents(Collection.THERMAL):aggregate_stages(BY_SUM()):remove_zeros():round(0); + local inv_hydro = outdisbu:select_agents(Collection.HYDRO ):aggregate_stages(BY_SUM()):remove_zeros():round(0); + local inv_batte = outdisbu:select_agents(Collection.BATTERY):aggregate_stages(BY_SUM()):remove_zeros():round(0); local inv_solar = outdisbu:select_agents(Collection.RENEWABLE) :select_agents(renewable[case].tech_type:eq(2) ) - :aggregate_stages(BY_SUM()):round(0); + :aggregate_stages(BY_SUM()):remove_zeros():round(0); local inv_wind = outdisbu:select_agents(Collection.RENEWABLE) :select_agents(renewable[case].tech_type:eq(1) ) - :aggregate_stages(BY_SUM()):round(0); + :aggregate_stages(BY_SUM()):remove_zeros():round(0); local inv_csp = outdisbu:select_agents(Collection.RENEWABLE) :select_agents(renewable[case].tech_type:eq(5) ) - :aggregate_stages(BY_SUM()):round(0); + :aggregate_stages(BY_SUM()):remove_zeros():round(0); local inv_other = outdisbu:select_agents(Collection.RENEWABLE) :select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) - :aggregate_stages(BY_SUM()):round(0); - local inv_ac = outdisbu:select_agents(Collection.CIRCUIT):aggregate_stages(BY_SUM()):round(0); - local inv_dc = outdisbu:select_agents(Collection.DCLINK ):aggregate_stages(BY_SUM()):round(0); + :aggregate_stages(BY_SUM()):remove_zeros():round(0); + local inv_ac = outdisbu:select_agents(Collection.CIRCUIT):aggregate_stages(BY_SUM()):remove_zeros():round(0); + local inv_dc = outdisbu:select_agents(Collection.DCLINK ):aggregate_stages(BY_SUM()):remove_zeros():round(0); local chart_a = create_chart("", case); chart_a:add_pie(costs:aggregate_agents(BY_SUM(), dictionary.total_operational_costs[language]), { color = colors.total_costs.operational }); @@ -617,18 +618,18 @@ end local function chart_total_installed_capacity(case) local renewable_cap_ind = renewable[case]:load("pnomnd"); - local thermal_cap = thermal[case]:load("pnomtr"):round(0); - local hydro_cap = hydro[case]:load("pnomhd"):round(0); - local batte_cap = battery[case]:load("pnombat"):round(0); + local thermal_cap = thermal[case]:load("pnomtr"):remove_zeros():round(0); + local hydro_cap = hydro[case]:load("pnomhd"):remove_zeros():round(0); + local batte_cap = battery[case]:load("pnombat"):remove_zeros():round(0); local renewable_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) - :aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local solar_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(2) ) - :aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local wind_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(1) ) - :aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local csp_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(5) ) - :aggregate_scenarios(BY_AVERAGE()):round(0); - local bat_cap = batte_cap:aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); + local bat_cap = batte_cap:aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local chart = create_chart("", case); chart:add_area_spline_stacking(thermal_cap:aggregate_agents(BY_SUM(), dictionary.total_thermal[language]), { color = colors.total_generation.thermal }); @@ -649,18 +650,18 @@ end local function chart_total_installed_capacity_mix(case) local renewable_cap_ind = renewable[case]:load("pnomnd"):aggregate_stages(BY_MAX()); - local thermal_cap = thermal[case]:load("pnomtr"):aggregate_stages(BY_MAX()):round(0); - local hydro_cap = hydro[case]:load("pnomhd"):aggregate_stages(BY_MAX()):round(0); - local batte_cap = battery[case]:load("pnombat"):aggregate_stages(BY_MAX()):round(0); + local thermal_cap = thermal[case]:load("pnomtr"):aggregate_stages(BY_MAX()):remove_zeros():round(0); + local hydro_cap = hydro[case]:load("pnomhd"):aggregate_stages(BY_MAX()):remove_zeros():round(0); + local batte_cap = battery[case]:load("pnombat"):aggregate_stages(BY_MAX()):remove_zeros():round(0); local renewable_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) - :aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local solar_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(2) ) - :aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local wind_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(1) ) - :aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local csp_cap = renewable_cap_ind:select_agents(renewable[case].tech_type:eq(5) ) - :aggregate_scenarios(BY_AVERAGE()):round(0); - local bat_cap = batte_cap:aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); + local bat_cap = batte_cap:aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local vector_of_charts = {}; local initial_year = study[case]:initial_year(); @@ -694,18 +695,18 @@ local function chart_total_installed_capacity_mix(case) end local function chart_firm_capacity(case) - local firm_capacity_renew = renewable[case]:load("outrpa"):round(0); - local firm_capacity_hydro = hydro[case]:load("outhpa"):round(0); - local firm_capacity_therm = thermal[case]:load("outtpa"):round(0); - local firm_capacity_batte = battery[case]:load("outbpa"):round(0); + local firm_capacity_renew = renewable[case]:load("outrpa"):remove_zeros():round(0); + local firm_capacity_hydro = hydro[case]:load("outhpa"):remove_zeros():round(0); + local firm_capacity_therm = thermal[case]:load("outtpa"):remove_zeros():round(0); + local firm_capacity_batte = battery[case]:load("outbpa"):remove_zeros():round(0); local firm_capacity_renew = firm_capacity_renew:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) - :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):remove_zeros():round(0); local firm_capacity_solar = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(2) ) - :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):remove_zeros():round(0); local firm_capacity_wind = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(1) ) - :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):remove_zeros():round(0); local firm_capacity_csp = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(5) ) - :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):remove_zeros():round(0); local chart = create_chart("", case); chart:add_area_spline_stacking(firm_capacity_therm:aggregate_agents(BY_SUM(), dictionary.total_thermal[language]), { color = colors.total_generation.thermal }); @@ -724,18 +725,18 @@ local function chart_firm_capacity(case) end local function chart_firm_capacity_mix(case) - local firm_capacity_renew = renewable[case]:load("outrpa"):round(0); - local firm_capacity_hydro = hydro[case]:load("outhpa"):round(0); - local firm_capacity_therm = thermal[case]:load("outtpa"):round(0); - local firm_capacity_batte = battery[case]:load("outbpa"):round(0); + local firm_capacity_renew = renewable[case]:load("outrpa"):remove_zeros():round(0); + local firm_capacity_hydro = hydro[case]:load("outhpa"):remove_zeros():round(0); + local firm_capacity_therm = thermal[case]:load("outtpa"):remove_zeros():round(0); + local firm_capacity_batte = battery[case]:load("outbpa"):remove_zeros():round(0); local firm_capacity_solar = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(2) ) - :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):remove_zeros():round(0); local firm_capacity_wind = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(1) ) - :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):remove_zeros():round(0); local firm_capacity_csp = firm_capacity_renew:select_agents(renewable[case].tech_type:eq(5) ) - :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):remove_zeros():round(0); local firm_capacity_renew = firm_capacity_renew:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) - :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):remove_zeros():round(0); local vector_of_charts = {}; local initial_year = study[case]:initial_year(); @@ -771,18 +772,18 @@ local function chart_firm_capacity_mix(case) end local function chart_firm_energy(case) - local firm_energy_renew = renewable[case]:load("outrea"):round(0); - local firm_energy_hydro = hydro[case]:load("outhea"):round(0); - local firm_energy_therm = thermal[case]:load("outtea"):round(0); - local firm_energy_batte = battery[case]:load("outbea"):round(0); + local firm_energy_renew = renewable[case]:load("outrea"):remove_zeros():round(0); + local firm_energy_hydro = hydro[case]:load("outhea"):remove_zeros():round(0); + local firm_energy_therm = thermal[case]:load("outtea"):remove_zeros():round(0); + local firm_energy_batte = battery[case]:load("outbea"):remove_zeros():round(0); local firm_energy_solar = firm_energy_renew:select_agents(renewable[case].tech_type:eq(2) ) - :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):remove_zeros():round(0); local firm_energy_wind = firm_energy_renew:select_agents(renewable[case].tech_type:eq(1) ) - :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):remove_zeros():round(0); local firm_energy_csp = firm_energy_renew:select_agents(renewable[case].tech_type:eq(5) ) - :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):remove_zeros():round(0); local firm_energy_renew = firm_energy_renew:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) - :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):remove_zeros():round(0); local chart = create_chart("", case); chart:add_area_spline_stacking(firm_energy_therm:aggregate_agents(BY_SUM(), dictionary.total_thermal[language]), { color = colors.total_generation.thermal }); @@ -801,18 +802,18 @@ local function chart_firm_energy(case) end local function chart_firm_energy_mix(case) - local firm_energy_renew = renewable[case]:load("outrea"):round(0); - local firm_energy_hydro = hydro[case]:load("outhea"):round(0); - local firm_energy_therm = thermal[case]:load("outtea"):round(0); - local firm_energy_batte = battery[case]:load("outbea"):round(0); + local firm_energy_renew = renewable[case]:load("outrea"):remove_zeros():round(0); + local firm_energy_hydro = hydro[case]:load("outhea"):remove_zeros():round(0); + local firm_energy_therm = thermal[case]:load("outtea"):remove_zeros():round(0); + local firm_energy_batte = battery[case]:load("outbea"):remove_zeros():round(0); local firm_energy_solar = firm_energy_renew:select_agents(renewable[case].tech_type:eq(2) ) - :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_solar[language]):remove_zeros():round(0); local firm_energy_wind = firm_energy_renew:select_agents(renewable[case].tech_type:eq(1) ) - :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_wind[language]):remove_zeros():round(0); local firm_energy_csp = firm_energy_renew:select_agents(renewable[case].tech_type:eq(5) ) - :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_csp[language]):remove_zeros():round(0); local firm_energy_renew = firm_energy_renew:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) - :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):round(0); + :aggregate_agents(BY_SUM(), dictionary.total_renewable[language]):remove_zeros():round(0); local vector_of_charts = {}; local initial_year = study[case]:initial_year(); @@ -859,7 +860,7 @@ local function chart_annual_marginal_cost(case) cmgdem = cmgdem:aggregate_agents(BY_AVERAGE(),Collection.SYSTEM) :aggregate_blocks(BY_AVERAGE()) :aggregate_stages(BY_AVERAGE(),Profile.PER_YEAR) - :aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local chart = create_chart("", case); chart:add_line(cmgdem, { color = colors.generic }); @@ -881,7 +882,7 @@ local function chart_monthly_marginal_cost(case) cmgdem = cmgdem:aggregate_agents(BY_AVERAGE(),Collection.SYSTEM) :aggregate_blocks(BY_AVERAGE()) - :aggregate_scenarios(BY_AVERAGE()):round(0); + :aggregate_scenarios(BY_AVERAGE()):remove_zeros():round(0); local chart = create_chart("", case); chart:add_line(cmgdem, { color = colors.generic }); @@ -903,7 +904,7 @@ local function chart_hourly_marginal_cost_per_typical_day(case) local cmgdem2 = cmgdem:aggregate_agents(BY_AVERAGE(),Collection.SYSTEM) :aggregate_scenarios(BY_AVERAGE()) - :aggregate_agents(BY_AVERAGE(),dictionary.omc[language]):round(0); + :aggregate_agents(BY_AVERAGE(),dictionary.omc[language]):remove_zeros():round(0); local vector_of_charts = {}; local _, day_data = by_day(cmgdem2); @@ -944,9 +945,9 @@ local function chart_defict_risk(case) end local dathisc = generic[case]:load("opt2_optgscen"):select_stage(1):set_stage_type(stage_type); if dathisc then - defict = ifelse(defict:gt(0), dathisc, 0):aggregate_scenarios(BY_SUM()):convert("%"):round(0); + defict = ifelse(defict:gt(0), dathisc, 0):aggregate_scenarios(BY_SUM()):convert("%"):remove_zeros():round(0); else - defict = ifelse(defict:gt(0), 1, 0):aggregate_scenarios(BY_AVERAGE()):convert("%"):round(0); + defict = ifelse(defict:gt(0), 1, 0):aggregate_scenarios(BY_AVERAGE()):convert("%"):remove_zeros():round(0); end local chart = create_chart("", case); @@ -963,21 +964,21 @@ local function chart_generation_in_season(case) local renewable_gen_ind = renewable[case]:load("opt2_gergndmw"):aggregate_blocks(BY_AVERAGE()) local thermal_gen = generic[case]:load("opt2_gertermw"):aggregate_blocks(BY_AVERAGE()) -- problemas - :aggregate_blocks(BY_SUM()):round(0); + :aggregate_blocks(BY_SUM()):remove_zeros():round(0); local hidro_gen = hydro[case]:load("opt2_gerhidmw"):aggregate_blocks(BY_AVERAGE()) - :aggregate_blocks(BY_SUM()):round(0); + :aggregate_blocks(BY_SUM()):remove_zeros():round(0); local renewable_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:ne(1 | 2 | 5) ) - :aggregate_blocks(BY_SUM()):round(0); + :aggregate_blocks(BY_SUM()):remove_zeros():round(0); local solar_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:eq(2)) - :aggregate_blocks(BY_SUM()):round(0); + :aggregate_blocks(BY_SUM()):remove_zeros():round(0); local wind_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:eq(1)) - :aggregate_blocks(BY_SUM()):round(0); + :aggregate_blocks(BY_SUM()):remove_zeros():round(0); local csp_gen = renewable_gen_ind:select_agents(renewable[case].tech_type:eq(5)) - :aggregate_blocks(BY_SUM()):round(0); + :aggregate_blocks(BY_SUM()):remove_zeros():round(0); local battery = battery[case]:load("opt2_gerbatmw"):aggregate_blocks(BY_AVERAGE()) - :aggregate_blocks(BY_SUM()):round(0); + :aggregate_blocks(BY_SUM()):remove_zeros():round(0); local defict = generic[case]:load("opt2_deficitmw"):aggregate_blocks(BY_AVERAGE()) - :aggregate_blocks(BY_SUM()):round(0); + :aggregate_blocks(BY_SUM()):remove_zeros():round(0); local stage_type; if defict:loaded() then @@ -1101,14 +1102,14 @@ local function chart_hourly_generation_typical_day(case) for stg = first_stg, first_stg do for t_day = 1, 1 do -- mudar - local year_day_thermal_gen = day_thermal_gen [t_day]:select_stages_by_year(year):select_stage(stg):round(0); - local year_day_hidro_gen = day_hidro_gen [t_day]:select_stages_by_year(year):select_stage(stg):round(0); - local year_day_renewable_gen = day_renewable_gen[t_day]:select_stages_by_year(year):select_stage(stg):round(0); - local year_day_solar_gen = day_solar_gen [t_day]:select_stages_by_year(year):select_stage(stg):round(0); - local year_day_wind_gen = day_wind_gen [t_day]:select_stages_by_year(year):select_stage(stg):round(0); - local year_day_csp_gen = day_csp_gen [t_day]:select_stages_by_year(year):select_stage(stg):round(0); - local year_day_battery = day_battery [t_day]:select_stages_by_year(year):select_stage(stg):round(0); - local year_day_defict = day_defict [t_day]:select_stages_by_year(year):select_stage(stg):round(0); + local year_day_thermal_gen = day_thermal_gen [t_day]:select_stages_by_year(year):select_stage(stg):remove_zeros():round(0); + local year_day_hidro_gen = day_hidro_gen [t_day]:select_stages_by_year(year):select_stage(stg):remove_zeros():round(0); + local year_day_renewable_gen = day_renewable_gen[t_day]:select_stages_by_year(year):select_stage(stg):remove_zeros():round(0); + local year_day_solar_gen = day_solar_gen [t_day]:select_stages_by_year(year):select_stage(stg):remove_zeros():round(0); + local year_day_wind_gen = day_wind_gen [t_day]:select_stages_by_year(year):select_stage(stg):remove_zeros():round(0); + local year_day_csp_gen = day_csp_gen [t_day]:select_stages_by_year(year):select_stage(stg):remove_zeros():round(0); + local year_day_battery = day_battery [t_day]:select_stages_by_year(year):select_stage(stg):remove_zeros():round(0); + local year_day_defict = day_defict [t_day]:select_stages_by_year(year):select_stage(stg):remove_zeros():round(0); local chart = create_chart(dictionary.season[language] .. " - " .. stg .." | ".. dictionary.year[language] .. " - " .. year .. " | " .. From 7e9f8dbfb7591da204e78419c74ead7e9212dde5 Mon Sep 17 00:00:00 2001 From: Iury Date: Thu, 28 Sep 2023 16:09:04 -0300 Subject: [PATCH 4/4] script corrections and updates --- optgen/optgen-dashboard.lua | 224 +++++++++++++++++++++++------------- 1 file changed, 145 insertions(+), 79 deletions(-) diff --git a/optgen/optgen-dashboard.lua b/optgen/optgen-dashboard.lua index f070821..3d352c3 100644 --- a/optgen/optgen-dashboard.lua +++ b/optgen/optgen-dashboard.lua @@ -1,4 +1,4 @@ --- C:\Users\iury\Desktop\PSRio_Atual\psrio.exe --model OPTGEN -r "D:\SDDP_1\sddp\psrio-scripts\sddp\sddp-dashlib.lua,D:\PSRIO-scripts\optgen\optgen-dashboard.lua" "D:\Dropbox (PSR)\PSR_main\OPTGEN\DASHBOARD\caso_teste_new" +-- C:\PSR\GraphModule\Oper\psrplot\psrio\psrio.exe --model OPTGEN -r "D:\SDDP_1\sddp\psrio-scripts\sddp\sddp-dashlib.lua,D:\PSRIO-scripts\optgen\optgen-dashboard.lua" "C:\PSR\Optgen8.1\Example\Typical_Day\3_typday" --=================================================-- -- Create Vectors of collections --=================================================-- @@ -152,8 +152,8 @@ local dictionary = { }, circuit_accumulated_capacity = { en = "Circuit accumulated capacity", - es = "Capacidad acumulada de circuitos", - pt = "Capacidade acumulada de circuitos" + es = "Capacidad acumulada de circuitos", + pt = "Capacidade acumulada de circuitos" }, total_costs = { en = "Total costs", @@ -398,6 +398,7 @@ end local language = load_language(); local is_opt2 = identify_if_opt2(); +local risk_results = true; local has_network = identify_if_has_network(); --=================================================-- @@ -441,18 +442,6 @@ local function by_day(data) -- vai deixar de existir } end -local function read_opt2_optgcoped(case) -- vai deixar de existir - local opt2_optgcoped = generic[case]:load_table_without_header("opt2_optgcoped.csv"); - local N_col = #opt2_optgcoped[3]; - local aux_table = {}; - for col = 2, N_col do - local data = generic[case]:create(opt2_optgcoped[3][col], "M$", { tonumber(opt2_optgcoped[4][col]) }); - table.insert(aux_table, data); - end - - return concatenate(aux_table); -end - local function opt2_format_to_chart_scatterplot(year_vec, data_vec, col_name_vec, chart, unit, case) -- vai deixar de existir if #col_name_vec ~= #data_vec then warn("Vector Column name and Vector Data has not the same size in opt2_format function"); @@ -467,11 +456,11 @@ local function opt2_format_to_chart_scatterplot(year_vec, data_vec, col_name_vec end end - local intial_year = year_vec[1]; + local initial_year = year_vec[1]; local final_year = year_vec[#year_vec] local data_x_aux = {}; local data_y_aux = {}; - for year = intial_year, final_year do + for year = initial_year, final_year do for i, data_year in ipairs(year_vec) do if tonumber(year) == tonumber(data_year) then table.insert(data_x_aux, tonumber(data_vec[1][i])); @@ -537,7 +526,7 @@ local function chart_accumulated_capacity(case) chart:add_column_stacking(battery_cap:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -556,7 +545,7 @@ local function chart_circuit_accumulated_capacity(case) chart:add_column_stacking(dc_cap:aggregate_agents(BY_SUM(), dictionary.total_hydro[language]):remove_zeros():round(0), { color = colors.total_circuit.dc }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -609,7 +598,7 @@ local function chart_total_cost(case) chart_b:add_pie(inv_dc:aggregate_agents(BY_SUM(), dictionary.total_dc_circuit[language]), { color = colors.total_costs.dc }); if #chart_a == 0 or #chart_b == 0 then - return dictionary.data_not_exist[language]; + return end return { chart_a, chart_b }; @@ -641,7 +630,7 @@ local function chart_total_installed_capacity(case) chart:add_area_spline_stacking(bat_cap:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -686,7 +675,7 @@ local function chart_total_installed_capacity_mix(case) chart:add_pie(bat_cap_annual:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end table.insert(vector_of_charts, chart); @@ -718,7 +707,7 @@ local function chart_firm_capacity(case) chart:add_area_spline_stacking(firm_capacity_batte:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -762,7 +751,7 @@ local function chart_firm_capacity_mix(case) chart:add_pie(bat_cap_annual:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end table.insert(vector_of_charts, chart); @@ -795,7 +784,7 @@ local function chart_firm_energy(case) chart:add_area_spline_stacking(firm_energy_batte:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -840,7 +829,7 @@ local function chart_firm_energy_mix(case) chart:add_pie(bat_cap_annual:aggregate_agents(BY_SUM(), dictionary.total_battery[language]), { color = colors.total_generation.battery }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end table.insert(vector_of_charts, chart); @@ -866,7 +855,7 @@ local function chart_annual_marginal_cost(case) chart:add_line(cmgdem, { color = colors.generic }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -888,7 +877,7 @@ local function chart_monthly_marginal_cost(case) chart:add_line(cmgdem, { color = colors.generic }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -918,7 +907,7 @@ local function chart_hourly_marginal_cost_per_typical_day(case) table.insert(vector_of_charts, chart); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end end @@ -932,10 +921,8 @@ local function chart_defict_risk(case) else defict = system[case]:load("opt2_deficitmw"); end - defict = defict:aggregate_blocks(BY_AVERAGE()) - :aggregate_stages(BY_SUM(), Profile.PER_YEAR) - :remove_zeros(); + :aggregate_stages(BY_SUM(), Profile.PER_YEAR); local stage_type; if defict:loaded() then @@ -944,17 +931,18 @@ local function chart_defict_risk(case) stage_type = 1; end local dathisc = generic[case]:load("opt2_optgscen"):select_stage(1):set_stage_type(stage_type); + if dathisc then - defict = ifelse(defict:gt(0), dathisc, 0):aggregate_scenarios(BY_SUM()):convert("%"):remove_zeros():round(0); + defict = ifelse(defict:gt(0), dathisc, 0):aggregate_scenarios(BY_SUM()):convert("%"):round(0); else - defict = ifelse(defict:gt(0), 1, 0):aggregate_scenarios(BY_AVERAGE()):convert("%"):remove_zeros():round(0); + defict = ifelse(defict:gt(0), 1, 0):aggregate_scenarios(BY_AVERAGE()):convert("%"):round(0); end local chart = create_chart("", case); chart:add_line(defict, { color = colors.risk.deficit }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -1018,7 +1006,7 @@ local function chart_generation_in_season(case) chart:add_area_spline_stacking(defict:aggregate_agents(BY_SUM(), dictionary.deficit[language]), { color = colors.total_generation.defict }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -1097,7 +1085,7 @@ local function chart_hourly_generation_typical_day(case) end if year == final_year then - final_stga = (study[case]:stages() - study[case]:intial_stage())%study[case]:stages_per_year(); + final_stga = (study[case]:stages() - study[case]:initial_stage())%study[case]:stages_per_year(); end for stg = first_stg, first_stg do @@ -1124,7 +1112,7 @@ local function chart_hourly_generation_typical_day(case) chart:add_area_spline_stacking(year_day_defict , { color = colors.total_generation.defict }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end table.insert(vector_of_chart, chart); @@ -1136,13 +1124,15 @@ local function chart_hourly_generation_typical_day(case) end local function chart_objective_value(case) - local opt2_optgcoped = read_opt2_optgcoped(case); + local interest = (1 + study[case].discount_rate) ^ ((study[case].stage_in_year - 1) / study[case]:stages_per_year()); + local dathisc = generic[case]:load("opt2_optgscen"):select_stage(1); + local opt2_optgcoped = (generic[case]:load("opt2_optgcope") * interest * dathisc):aggregate_stages(BY_SUM()); local chart = create_chart("", case); chart:add_pie(opt2_optgcoped, { color = colors.generic }); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -1167,7 +1157,8 @@ local function chart_risk_curve(case) end if #chart <= 0 then - return dictionary.data_not_exist[language]; + risk_results = false; + return end return chart; @@ -1181,7 +1172,7 @@ local function chart_convergence(case) chart:add_line(gap); if #chart <= 0 then - return dictionary.data_not_exist[language]; + return end return chart; @@ -1194,74 +1185,110 @@ local function tab_investiment_report() local tab = create_tab(dictionary.investment_report[language], "arrow-right"); if plot.accumulated_capacity then - tab:push("### " .. dictionary.accumulated_capacity[language]); for case = 1, cases do local chart = chart_accumulated_capacity(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.accumulated_capacity[language]); + end + tab:push(chart); + end end end if plot.circuit_accumulated_capacity then - tab:push("### " .. dictionary.circuit_accumulated_capacity[language]); for case = 1, cases do local chart = chart_circuit_accumulated_capacity(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.circuit_accumulated_capacity[language]); + end + tab:push(chart); + end end end if plot.total_cost then - tab:push("### " .. dictionary.total_costs[language]); for case = 1, cases do local chart = chart_total_cost(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.total_costs[language]); + end + tab:push(chart); + end end end if plot.total_installed_capacity then - tab:push("### " .. dictionary.total_installed_capacity[language]); for case = 1, cases do local chart = chart_total_installed_capacity(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.total_installed_capacity[language]); + end + tab:push(chart); + end end end if plot.total_installed_capacity_mix then - tab:push("### " .. dictionary.total_installed_capacity_mix[language]); for case = 1, cases do local chart = chart_total_installed_capacity_mix(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.total_installed_capacity_mix[language]); + end + tab:push(chart); + end end end if plot.firm_capacity then - tab:push("### " .. dictionary.firm_capacity[language]); for case = 1, cases do local chart = chart_firm_capacity(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.firm_capacity[language]); + end + tab:push(chart); + end end end if plot.firm_capacity_mix then - tab:push("### " .. dictionary.firm_capacity_mix[language]); for case = 1, cases do local chart = chart_firm_capacity_mix(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.firm_capacity_mix[language]); + end + tab:push(chart); + end end end if plot.firm_energy then - tab:push("### " .. dictionary.firm_energy[language]); for case = 1, cases do local chart = chart_firm_energy(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.firm_energy[language]); + end + tab:push(chart); + end end end if plot.firm_energy_mix then - tab:push("### " .. dictionary.firm_capacity_mix[language]); for case = 1, cases do local chart = chart_firm_energy_mix(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.firm_capacity_mix[language]); + end + tab:push(chart); + end end end @@ -1272,68 +1299,100 @@ local function tab_optgen2_reports() local tab = create_tab(dictionary.optgen_2_reports[language], "arrow-right"); if plot.annual_marginal_cost then - tab:push("### " .. dictionary.annual_marginal_cost[language]); for case = 1, cases do local chart = chart_annual_marginal_cost(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.annual_marginal_cost[language]); + end + tab:push(chart); + end end end if plot.monthly_marginal_cost then - tab:push("### " .. dictionary.monthly_marginal_cost[language]); for case = 1, cases do local chart = chart_monthly_marginal_cost(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.monthly_marginal_cost[language]); + end + tab:push(chart); + end end end if plot.hourly_generation_typical then - tab:push("### " .. dictionary.hourly_marginal_cost_typical[language]); for case = 1, cases do local chart = chart_hourly_marginal_cost_per_typical_day(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.hourly_marginal_cost_typical[language]); + end + tab:push(chart); + end end end if plot.deficit_risk then - tab:push("### " .. dictionary.deficit_risk[language]); for case = 1, cases do local chart = chart_defict_risk(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.deficit_risk[language]); + end + tab:push(chart); + end end end if plot.generation_in_each_season then - tab:push("### " .. dictionary.generation_in_season[language]); for case = 1, cases do local chart = chart_generation_in_season(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.generation_in_season[language]); + end + tab:push(chart); + end end end if plot.hourly_generation_typical then - tab:push("### " .. dictionary.generation_per_typical_day[language]); for case = 1, cases do local chart = chart_hourly_generation_typical_day(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.generation_per_typical_day[language]); + end + tab:push(chart); + end end end if plot.objective_function then - tab:push("### " .. dictionary.objective_functions[language]); for case = 1, cases do local chart = chart_objective_value(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.objective_functions[language]); + end + tab:push(chart); + end end end if plot.convergence then - tab:push("### " .. dictionary.convergence[language]); for case = 1, cases do local chart = chart_convergence(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.convergence[language]); + end + tab:push(chart); + end end end @@ -1344,10 +1403,14 @@ local function tab_risk_result() local tab = create_tab(dictionary.optgen_risk[language], "arrow-right"); if plot.risk_curve then - tab:push("### " .. dictionary.optgen_risk[language]); for case = 1, cases do local chart = chart_risk_curve(case); - tab:push(chart); + if chart then + if case == 1 then + tab:push("### " .. dictionary.optgen_risk[language]); + end + tab:push(chart); + end end end @@ -1365,7 +1428,10 @@ local function tab_expansion_result() tab:push(tab_optgen2_reports()); end - tab:push(tab_risk_result()); + local risk_tab = tab_risk_result(); + if risk_results then + tab:push(risk_tab); + end return tab; end