forked from rl-institut/cp_nigeria_app
-
Notifications
You must be signed in to change notification settings - Fork 0
multi-objective weights #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ddcee9e
multi-objective weights
c3a063b
Merge branch 'dev' into feature/moo_weights
40e4e14
Merge branch 'dev' into feature/moo_weights
c2e9324
Make form crispy and slightly adjust layout
paulapreuss a8e3892
moo weights: change to ModelForm
1aa59e6
Merge branch 'dev' into feature/moo_weights
a876ca9
multi-objective weights
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| .padding-1 { | ||
| padding: 1rem; | ||
| width: 35%; | ||
| align-self: center; | ||
| } | ||
|
|
||
| .center-text { | ||
| text-align: center; | ||
| } | ||
|
|
||
| .inp-default { | ||
| width: initial; | ||
| } | ||
|
|
||
| .no-bullet ul { | ||
| list-style-type: none; | ||
| } | ||
|
|
||
| .error { | ||
| color: red; | ||
| font-weight: bold; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| {% extends 'wefe/steps/step_progression.html' %} | ||
| {% load crispy_forms_tags %} | ||
| {% load i18n %} | ||
|
|
||
| {% block progression_content %} | ||
| <div class="padding-1"> | ||
| <div class="center-text"> | ||
| <input id="inp-moo" type="checkbox" class="inp-default" onchange="update_weights()" {% if custom_weights or form.errors %}checked{% endif %}> | ||
| <label for="inp-moo">{% translate 'Use Multi-Objective Optimization' %}</label> | ||
| </div> | ||
| <form id="form" method="post"> | ||
| {% csrf_token %} | ||
| <div> | ||
| {{ form | crispy }} | ||
| </div> | ||
| </form> | ||
| </div> | ||
| {% endblock progression_content %} | ||
|
|
||
| {% block next_btn %} | ||
| <button class="btn btn--medium" onclick="document.getElementById('form').submit()">{% translate "Next" %}</button> | ||
| {% endblock next_btn %} | ||
|
|
||
| {% block end_body_scripts %} | ||
| <script> | ||
| // init weights | ||
| var weights = {}; | ||
| for (let inp of $(':input[type="number"]')) | ||
| weights[inp.id] = inp.value; | ||
|
|
||
| function update_weights() { | ||
| let form = document.getElementById('form'); | ||
| let check = document.getElementById('inp-moo'); | ||
| let inputs = $(':input[type="number"]'); | ||
| form.style.display = check.checked ? '' : 'none'; | ||
| for (let inp of inputs) { | ||
| if (check.checked) { | ||
| // multi-objective: restore weight | ||
| inp.value = weights[inp.id]; | ||
| } else { | ||
| // single objective: reset weight | ||
| weights[inp.id] = inp.value; | ||
| inp.value = inp.getAttribute('default'); | ||
| } | ||
| } | ||
| } | ||
| // initialize state | ||
| update_weights(); | ||
|
|
||
| </script> | ||
| {% endblock end_body_scripts %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Generated by Django 5.1.3 on 2025-11-04 14:49 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("projects", "0027_alter_economicdata_currency"), | ||
| ("wefe", "0003_wefesimulation"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="MOOWeights", | ||
| fields=[ | ||
| ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
| ("total_cost", models.FloatField(default=1)), | ||
| ("co2_emissions", models.FloatField(default=0)), | ||
| ("land_requirements", models.FloatField(default=0)), | ||
| ("water_footprint", models.FloatField(default=0)), | ||
| ("scenario", models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to="projects.scenario")), | ||
| ], | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this works as it is, but I don't know about using a
except:for a condition that is very normal within the code like no MOO set yet (not an unexpected exception). Instead of waiting for an Exception to be raised I think it would be cleaner/less computationally expensive to formulate this as: