Add annual demand increase option to demand estimation#31
Conversation
paulapreuss
left a comment
There was a problem hiding this comment.
Thanks for getting started on this! We can have a look at the review comments together and discuss how to continue 🔨
| <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> | ||
|
|
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
| <!-- Collapsible Input Section --> | ||
| <div class="accordion-item" style="border-top: none; padding: 10px"> | ||
|
|
||
| <div id="collapseGrowth" | ||
| class="accordion-collapse collapse"> | ||
|
|
There was a problem hiding this comment.
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
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
| // Anual Demand Increase | ||
| const growthToggle = document.getElementById("growthToggle"); | ||
| const annualDemandGrowthInput = document.getElementById("annualDemandGrowth"); | ||
|
|
There was a problem hiding this comment.
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? :)
8d99238 to
c9deb51
Compare
paulapreuss
left a comment
There was a problem hiding this comment.
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 :)
| initial["annual_demand_increase"] = self.change_percentage_format( | ||
| instance.annual_demand_increase, | ||
| upper_limit=100 | ||
| ) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Here is where all the fields that should be served in a percentage format are handled within this form
| 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, | ||
| ) |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'%} |
There was a problem hiding this comment.
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
| {% 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 instancecd36dcc to
7b97bc0
Compare
paulapreuss
left a comment
There was a problem hiding this comment.
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.
fc4e185 to
c219c6a
Compare
# Conflicts: # offgridplanner/static/js/pages/demand_estimation.js
That way this option can also be selected if custom demand has been uploaded
085adc9 to
9e67d9d
Compare
This PR enhances the Demand Estimation page by adding an optional feature that allows users to apply an annual demand increase in percent.
Contributes to #1