Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/static/debug_results.json

Large diffs are not rendered by default.

27 changes: 26 additions & 1 deletion app/static/scss/components/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,29 @@ table.table {
&>:not(caption)>*>* {
padding: $dashboard-table-cell-padding;
}
}
}

#table-results {
align-self:center;
padding-bottom: 1rem;

th, td {
border: 1px solid gray;
}

th {
text-align: center;
}

td:nth-child(1) {
text-align: left;
}

td:nth-child(2) {
text-align: right;
}

td:nth-child(3) {
text-align: right;
}
}
45 changes: 45 additions & 0 deletions app/static/units.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"drinking-water-storage": "[m³]",
"total_annual_cost_moo": "[USD/a]",
"rainwater-harvesting": "[m²]",
"service-water-storage": "[m³]",
"sw-ro": "[m³/h]",
"seawater-reverse-osmosis": "[m³/h]",
"electricity-grid": "[kWh]",
"seawater": "[m³]",
"seawater-source": "[m³]",
"water-truck": "[m³]",
"battery-storage": "[kWh]",
"inverter": "[kW]",
"water-filtration": "[m³/h]",
"water-filtration-system": "[m³/h]",
"water-pump": "[m³/h]",
"river-water-uptake": "[m³/h]",
"crop": "[m²]",
"banana": "[m²]",
"banana-production": "[kg/a]",
"groundwater": "[m³]",
"bottled-water": "[m³]",
"diesel-generator": "[kW]",
"photovoltaics": "[kWp]",
"wind-turbine": "[kW]",
"hydropower": "[kW]",
"pv-panel": "[kW]",
"water-storage": "[m³]",
"mimo": "[m³/h]",
"annuity_total": "[USD/a]",
"variable_costs_total": "[USD/a]",
"ghg_emission_total": "[kgCO2e/a]",
"ghg_emissions_total": "[kgCO2e/a]",
"system_cost_total": "[USD/a]",
"land_requirement_additional": "[m²]",
"total_upfront_investments": "[USD]",
"land_requirement_total": "[m²]",
"total_water_footprint": "[m³]",
"system_opex_total": "[USD/a]",
"total_variable_cost_moo": "[USD/a]",
"total_water_consumption": "[m³/a]",
"total_indirect_water_consumption": "[m³/a]",
"ac-elec": "[kWh]",
"water_scarcity_footprint": "[m³]"
}
76 changes: 76 additions & 0 deletions app/templates/wefe/steps/result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% extends 'wefe/steps/step_progression.html' %}
{% load static %}
{% load i18n %}

{% block start_body_scripts %}
<script src="{% static 'node_modules/chartjs-sankey/chart.js' %}"></script>
<script src="{% static 'node_modules/chartjs-sankey/chartjs-sankey.js' %}"></script>
{% endblock %}

{% block progression_content %}
<table id="table-results" style="display:none">
<thead>
<th>KPI</th>
<th>Value</th>
<th>Unit</th>
</thead>
<tbody>
</tbody>
</table>
<div>
<canvas id="chart"></canvas>
</div>
<button class="btn btn--medium" style="width:fit-content; align-self:center" onclick="getDebugData()">Load debug</button>
{% endblock %}

{% block end_body_scripts %}
<script>
var chart = null;
function getDebugData() {
fetch('{% url "get_wefesim_results" %}').then(resp => resp.json()).then(data => {
if (!data)
return;

if (data.kpi) {
// fill results table
let table = document.getElementById('table-results');
for (let kpi of data.kpi) {
let row = table.tBodies[0].insertRow();
row.insertCell().innerText = kpi.key;
row.insertCell().innerText = kpi.value? kpi.value.toFixed(2) : kpi.value;
row.insertCell().innerText = kpi.unit;
}
// show table
table.style.display = 'block';
}

if (data.energy_flows) {
// generate sankey diagram
const colors = {
'electricity': 'gold',
'biogas': 'cyan',
'energy': 'orange',
'default': 'gray',
};
var ctx = document.getElementById("chart").getContext("2d");
if (chart)
chart.destroy();
chart = new Chart(ctx, {
type: "sankey",
data: {
datasets: [
{
data: data.energy_flows,
colorFrom: c => colors[c.raw.type || 'default'],
colorTo: c => colors[c.raw.type || 'default'],
}
]
}
});
}
}).catch(error => {
console.error(error);
});
}
</script>
{% endblock end_body_scripts%}
1 change: 1 addition & 0 deletions app/wefe/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
path("ajax/wefesim-simulation", request_wefesim_simulation, name="request_wefesim_simulation"),
path("ajax/wefesim-simulation/<int:proj_id>", request_wefesim_simulation, name="request_wefesim_simulation"),
path("ajax/get-wefesim-data/<int:proj_id>", get_wefesim_data, name="get_wefesim_data"),
path("ajax/get-dummy-results/", get_wefesim_results, name="get_wefesim_results"),
# energy-system survey
path("<int:proj_id>/survey", wefe_system_layout, name="view_survey_questions"),
path("<int:proj_id>/submit/survey", wefe_system_layout, name="submit_survey"),
Expand Down
83 changes: 76 additions & 7 deletions app/wefe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from wefe.survey import SURVEY_CATEGORIES, SURVEY_QUESTIONS_CATEGORIES, get_survey_question_by_id

import logging

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -676,7 +677,7 @@ def wefe_simulation(request, proj_id, step_id=STEP_MAPPING["simulation"]):


@login_required
@require_http_methods(["GET", "POST"])
@require_http_methods(["GET"])
def wefe_results(request, proj_id, step_id=STEP_MAPPING["results"]):
project = get_object_or_404(Project, id=proj_id)

Expand All @@ -687,21 +688,89 @@ def wefe_results(request, proj_id, step_id=STEP_MAPPING["results"]):

scenario = project.scenario

page_information = "Results page with report option"
context = {
"proj_id": proj_id,
"proj_name": project.name,
"step_id": step_id,
"step_list": WEFE_STEP_VERBOSE,
"page_information": page_information,
}

if request.method == "GET":
return render(request, "wefe/steps/step_progression.html", context)
return render(request, "wefe/steps/result.html", context)

if request.method == "POST":
# TODO
return HttpResponseRedirect(reverse("wefe_steps", args=[proj_id, step_id + 1]))

@require_http_methods(["GET"])
def get_wefesim_results(request):
# read example sim results from static file
# get units from file
units_file = settings.STATIC_ROOT / "units.json"
units = dict()
if units_file.exists():
with units_file.open() as f:
units = json.load(f)
# get results from file
results_file = settings.STATIC_ROOT / "debug_results.json"
kpi = None
energy_flows = None
if results_file.exists():
# get general information
with results_file.open() as f:
results = json.load(f)

def aggregate(key):
try:
return sum([v for v in results[key].values() if v is not None])
except KeyError:
return None

kpi_lut = {
# name in table -> name in results
"total_annual_cost_moo": "annual_cost_moo",
"total_variable_cost_moo": "variable_cost_moo",
"total_upfront_investments": "upfront_investment_costs",
"land_requirement_additional": "land_requirement_additional",
"land_requirement_total": "land_requirement_total",
"total_water_consumption": "water_consumption",
"total_indirect_water_consumption": "indirect_water_consumption",
"water_scarcity_footprint": "???",
"ghg_emissions_total": "ghg_emissions",
"system_opex_total": "opex_fix_costs_total",
}
kpi = [
{
"key": kpi_name,
"value": aggregate(result_name),
"unit": units.get(kpi_name),
}
for kpi_name, result_name in kpi_lut.items()
]

# get energy flows
energy_flows = list()
for k, flow in results["aggregated_flow"].items():
# parse flow name
# make flow name json parseable
# flow name format: ('busname', 'direction', 'component', 'bustype', 'componenttype')
k2 = "[" + k.replace("'", '"')[1:-1] + "]"
bus_name, direction, component_name, carrier, component_type = json.loads(k2)
if direction == "in":
# from bus to component
flow_from = bus_name
flow_to = component_name
else:
# from component to bus
flow_from = component_name
flow_to = bus_name
energy_flows.append(
{
"from": flow_from,
"to": flow_to,
"flow": flow,
"type": carrier,
}
)

return JsonResponse({"kpi": kpi, "energy_flows": energy_flows})


WEFE_STEPS = {
Expand Down