Skip to content

Commit

Permalink
Disallow downloading curves when Merit is disabled
Browse files Browse the repository at this point in the history
It no longer makes sense to do a "real" Merit run even on scenarios with
the Merit Order disabled due to interactions with Fever (particularly
when P2H is present in the scenario). Fever will not be available if
Merit was not enable in the scenario.

Closes ETENGINE-7
  • Loading branch information
antw committed Oct 26, 2018
1 parent eb52747 commit 0a012f6
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/controllers/api/v3/curves_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class CurvesController < BaseController
render json: { errors: ['Scenario not found'] }, status: 404
end

before_action :merit_required

# Downloads the load on each participant in the merit order as a CSV.
#
# GET /api/v3/scenarios/:scenario_id/merit/loads.csv
Expand Down Expand Up @@ -53,6 +55,12 @@ def household_heat_curves

private

def merit_required
unless Qernel::Plugins::MeritOrder.enabled?(scenario.gql.future_graph)
render :merit_required, format: :html, layout: false
end
end

def send_csv(name)
send_data(
CSV.generate { |csv| yield csv },
Expand All @@ -62,9 +70,7 @@ def send_csv(name)
end

def merit_order
@mo ||= Qernel::Plugins::MeritOrder.new(
scenario.gql.future_graph
).order.calculate
scenario.gql.future_graph.plugin(:merit).order
end

def scenario
Expand Down
72 changes: 72 additions & 0 deletions app/views/api/v3/curves/merit_required.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
!!!
%html
%head
%title Merit and time-resolved calculations are not enabled
%meta{:content => "width=device-width,initial-scale=1", :name => "viewport"}/
:css
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Droid Sans, Arial, sans-serif;
margin: 0;
}

div.dialog {
width: 95%;
max-width: 43em;
margin: 4em auto 0;
}

div.dialog > div {
border: 1px solid #bbb;
border-top: #B00100 solid 4px;
background-color: white;
padding: 2em;
}

h1 {
font-size: 150%;
color: #9C0100;
line-height: 1.5em;
}

p {
line-height: 1.5;
padding: 0 40px;
}

p.back {
margin-top: 1.1em;
}

a {
color: #1975ca;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

.back a {
margin-left: -1em;
padding: 10px 15px;
}

.back a:hover {
background: #1975ca;
color: white;
text-decoration: none;
}
%body
.dialog
%div
%h1 Merit and time-resolved calculations are not enabled
%p
To download curves you must first enable the Merit Order in your
scenario. You can find this option in the settings menu or by
navigating to "Electricity balance" → "Merit order".
%p.back
%a(href="//pro.energytransitionmodel.com" onclick="window.history.back(); return false;" title="Go back")
← Go back

0 comments on commit 0a012f6

Please sign in to comment.