Skip to content

Add annual demand increase option to demand estimation#31

Merged
paulapreuss merged 17 commits into
mainfrom
feature/demand-increase
Jun 11, 2026
Merged

Add annual demand increase option to demand estimation#31
paulapreuss merged 17 commits into
mainfrom
feature/demand-increase

Conversation

@CelinaKellinghaus

Copy link
Copy Markdown
Collaborator

This PR enhances the Demand Estimation page by adding an optional feature that allows users to apply an annual demand increase in percent.

  • Added a toggle: "Apply annual demand increase"
  • When enabled, display an input field for annual demand increase
  • Accepts decimal values (Default value: 0%)
  • No changes to calculations yet

Contributes to #1

@paulapreuss paulapreuss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting started on this! We can have a look at the review comments together and discuss how to continue 🔨

Comment on lines +307 to +316
<div class="input-group" style="max-width: 200px">
<input type="number"
id="annualDemandGrowth"
class="form-control"
value="0"
step="0.1"
min="0">
<span class="input-group-text">%</span>
</div>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even though we have not settled on the calculation yet, we can already add the field to the CustomDemand model instead of a hard-coded form field in the html. The field should then also be defined in form_parameters.csv with the default and help text, so we don't have these things within the template.

id="annualDemandGrowth"
class="form-control"
value="0"
step="0.1"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a nitpick, but I think If the field takes inputs in %, the step value should be 1 to be less confusing, as it is with the demand tier values.

Comment on lines +291 to +296
<!-- Collapsible Input Section -->
<div class="accordion-item" style="border-top: none; padding: 10px">

<div id="collapseGrowth"
class="accordion-collapse collapse">

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it fits within the current layout to do this with an accordion, but here there is a part of the accordion that still looks a bit off, probably because of the container order or one div too many... html is a bit finnicky like that

Image

We will also have to watch the collapse logic of the accordions, e.g. when I select custom demand timeseries the other options should be hidden, but currently it is showing

Image

Comment on lines 32 to 35
// Anual Demand Increase
const growthToggle = document.getElementById("growthToggle");
const annualDemandGrowthInput = document.getElementById("annualDemandGrowth");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you are not on the most current state of main, because Josi did a big refactoring of demand_estimation.js that I merged last week and it does not show here yet. I am a bit surprised that your branch is not showing any merge conflicts. Can you pull the latest changes from main and rebase this branch on top of it? :)

Comment thread offgridplanner/templates/pages/demand_estimation.html Outdated
@CelinaKellinghaus
CelinaKellinghaus force-pushed the feature/demand-increase branch 2 times, most recently from 8d99238 to c9deb51 Compare March 17, 2026 08:34

@paulapreuss paulapreuss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not have time to check the template functionality, but you're also still working on it so I think that's alright. I left some comments on the rest of the code. Looking correct and clean so far :)

Comment thread offgridplanner/steps/forms.py Outdated
Comment on lines +76 to +79
initial["annual_demand_increase"] = self.change_percentage_format(
instance.annual_demand_increase,
upper_limit=100
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having this check here, you can just add the field to self.percentage_fields a couple lines above, so that it will be changed within the respective loop

Comment thread offgridplanner/steps/forms.py Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where all the fields that should be served in a percentage format are handled within this form

Comment thread offgridplanner/steps/forms.py Outdated
Comment on lines +105 to +109
if cleaned_data.get("annual_demand_increase") is not None:
cleaned_data["annual_demand_increase"] = self.change_percentage_format(
cleaned_data["annual_demand_increase"],
upper_limit=1,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, if you include the field in the respective list once it will just be handled with the rest, no need to clean it separately :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, one thing you could do if you wanted to custom clean this field, would be to set it to None if the input value is 0 (that would help you with the functionality of the accordeon in the template rendering as closed when the user returns to the page). If so, you could look at clean_<fieldname> instead of doing it in the general clean method.

https://docs.djangoproject.com/en/6.0/ref/forms/validation/
https://sayari3.com/articles/12-understand-clean-and-clean_fieldname-in-django/

def change_percentage_format(value, upper_limit=1):
if value is None:
return None
# Changes the value from a percentage range 0-1 to 0-100 and viceversa

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I should have already included this check earlier

<div class="shares-container">
{% for field in form %}
{% if field.name != 'annual_total_consumption' and field.name != 'annual_peak_consumption' %}
{% if field.name != 'annual_total_consumption' and field.name != 'annual_peak_consumption' and field.name != 'annual_demand_increase'%}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a style thought: I feel like this is getting a bit convoluted. I would rather pass a list of the other fields ["low", "medium", "high"] to the context and change this to something like

Suggested change
{% if field.name != 'annual_total_consumption' and field.name != 'annual_peak_consumption' and field.name != 'annual_demand_increase'%}
{% if field.name in shares_tiers %}

Actually, you can just call this list directly from the custom demand object in the view

shares_tiers = custom_demand.shares_tiers #custom_demand being the CustomDemand model instance

@CelinaKellinghaus
CelinaKellinghaus force-pushed the feature/demand-increase branch 2 times, most recently from cd36dcc to 7b97bc0 Compare March 25, 2026 10:53
@paulapreuss
paulapreuss self-requested a review March 25, 2026 13:47

@paulapreuss paulapreuss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you! ⭐ I pushed one commit moving the slider a bit in the html - I think it would be better to have it outside of the big accordion, so that it can still be selected if uploading a demand file. Otherwise it looks and works well, the issues with the slider being in the wrong position when reloading the page are very normal cacheing properties that also apply to the other sliders. I think we can keep it as is for now and finetune down the line if it ends up being necessary.

I think we shouldn't quite merge this yet, but keep it on hold and continue working on it once we decide how the demand increase will actually influence the demand.

@CelinaKellinghaus
CelinaKellinghaus force-pushed the feature/demand-increase branch from fc4e185 to c219c6a Compare May 20, 2026 09:00
@paulapreuss
paulapreuss force-pushed the feature/demand-increase branch from 085adc9 to 9e67d9d Compare June 11, 2026 08:53
@paulapreuss paulapreuss linked an issue Jun 11, 2026 that may be closed by this pull request
@paulapreuss
paulapreuss marked this pull request as ready for review June 11, 2026 13:57
@paulapreuss
paulapreuss merged commit aff13c1 into main Jun 11, 2026
2 checks passed
@paulapreuss
paulapreuss deleted the feature/demand-increase branch June 11, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add demand increase function into "demand estimation" page

2 participants