Skip to content

Commit

Permalink
Merge pull request #157 from nsidc/sankey
Browse files Browse the repository at this point in the history
Sankey
  • Loading branch information
rmarow authored Oct 6, 2023
2 parents d473914 + 6167bd9 commit f6b9ee1
Show file tree
Hide file tree
Showing 18 changed files with 469 additions and 193 deletions.
16 changes: 16 additions & 0 deletions usaon_vta_survey/constants/rbac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Role: Literal['admin'] | Literal['respondent'] | Literal['analyst']

# ROLES: Role[list[str]] = [
# 'admin',
# 'respondent',
# 'analyst',
# ]

# roles_allowed = {
#
# }
ROLES: list[str] = [
'admin',
'respondent',
'analyst',
]
5 changes: 0 additions & 5 deletions usaon_vta_survey/constants/roles.py

This file was deleted.

1 change: 0 additions & 1 deletion usaon_vta_survey/routes/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def login():
assert resp.ok, resp.text

user = ensure_user_exists(resp.json())
# breakpoint()
login_user(user)

return redirect('/')
Expand Down
2 changes: 2 additions & 0 deletions usaon_vta_survey/routes/response/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from usaon_vta_survey import db
from usaon_vta_survey.models.tables import Response, Survey
from usaon_vta_survey.util.authorization import limit_response_editors
from usaon_vta_survey.util.full_sankey import sankey

response_bp = Blueprint('response', __name__, url_prefix='/response')

Expand All @@ -26,4 +27,5 @@ def view_response(survey_id: str):
'response/view.html',
survey=survey,
response=survey.response,
sankey=sankey(survey.response),
)
2 changes: 2 additions & 0 deletions usaon_vta_survey/routes/response/data_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from usaon_vta_survey.forms import FORMS_BY_MODEL
from usaon_vta_survey.models.tables import ResponseDataProduct, Survey
from usaon_vta_survey.util.authorization import limit_response_editors
from usaon_vta_survey.util.sankey import data_products_sankey

data_product_bp = Blueprint(
'data_product', __name__, url_prefix='/response/<string:survey_id>/data_products'
Expand Down Expand Up @@ -37,4 +38,5 @@ def view_response_data_products(survey_id: str):
survey=survey,
response=survey.response,
data_products=survey.response.data_products,
sankey_series=data_products_sankey(survey.response),
)
2 changes: 2 additions & 0 deletions usaon_vta_survey/routes/response/sbas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Survey,
)
from usaon_vta_survey.util.authorization import limit_response_editors
from usaon_vta_survey.util.sankey import societal_benefit_areas_sankey

societal_benefit_area_bp = Blueprint(
'sba', __name__, url_prefix='/response/<string:survey_id>/societal_benefit_areas'
Expand Down Expand Up @@ -44,4 +45,5 @@ def view_response_sbas(survey_id: str):
sbas=sbas,
response=survey.response,
societal_benefit_areas=survey.response.societal_benefit_areas,
sankey_series=societal_benefit_areas_sankey(survey.response),
)
84 changes: 53 additions & 31 deletions usaon_vta_survey/templates/response/applications.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ <h3>Applications</h3>
<div class="two-columns">
<div>
<table>
<tr>
<th rowspan="2">Name</th>
<th colspan="4">Data products related</th>
</tr>
<tr>
<th>Name</th>
<th>Data products related</th>
<th>Performance Rating</th>
<th>Criticality Rating</th>
<th>Action</th>
</tr>
{% for application in response.applications %}
<tr>
Expand All @@ -25,20 +31,34 @@ <h3>Applications</h3>
None
<br />
{% endif %}

{% for input_relationship in application.input_relationships %}
<ul>
<li>{{input_relationship.data_product.short_name}}: {{input_relationship.performance_rating}}</li>
</ul>
{% endfor %}

<ul>
{% for input_relationship in application.input_relationships %}
<li>{{input_relationship.data_product.short_name}}</li>
{% endfor %}
</ul>
<br/>
</td>
<td>
<ul>
{% for input_relationship in application.input_relationships %}
<li>{{input_relationship.performance_rating}}</li>
{% endfor %}
</ul>
</td>
<td>
<ul>
{% for input_relationship in application.input_relationships %}
<li>{{input_relationship.criticality_rating}}</li>
{% endfor %}
</ul>
</td>
<td>
<a href="{{url_for(
'data_product_application.view_response_data_product_application_relationships',
survey_id=survey.id,
application_id=application.id,
)}}">{{render_icon('plus-circle-fill')}}
</a>
<br/>
</td>
</tr>
{% endfor %}
Expand All @@ -54,31 +74,33 @@ <h3>Applications</h3>
{% endif %}
</div>

<h3>Add application</h3>
<form method="POST">
{{render_form(form, button_map={'submit_button': 'primary'}) }}
{% if not current_user.role_id not in ['admin', 'respondent'] %}
<h3>Add application</h3>
<form method="POST">
{{render_form(form, button_map={'submit_button': 'primary'}) }}

</form>
</form>
{% endif %}

<script>
Highcharts.chart('highcharts-container', {
chart: {
type: 'sankey',
},
title: {
text: 'U.S. AON Value Tree Analysis Diagram',
style: {fontSize: '20px'},
},
accessibility: {
description: 'Sankey plot fo U.S. AON Value Tree',
point: {
valueDescriptionFormat: '{index}. {point.from} to {point.to}, {point.weight}.'
}
},
series: [{
keys: ['from', 'to', 'weight'],
Highcharts.chart('highcharts-container', {
chart: {
type: 'sankey',
},
title: {
text: 'U.S. AON Value Tree Analysis Diagram',
style: {fontSize: '20px'},
},
accessibility: {
description: 'Sankey plot for U.S. AON Value Tree',
point: {
valueDescriptionFormat: '{index}. {point.from} to {point.to}, {point.weight}.'
}
},
series: [{
keys: ['from', 'to', 'weight'],
data: {{sankey_series | safe}},
}]
});
}]
});
</script>
{% endblock %}
4 changes: 2 additions & 2 deletions usaon_vta_survey/templates/response/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2>{% block title %}Response to: {{survey.title}}{% endblock %}</h1>

<li>
<a href="{{url_for('response.view_response', survey_id=survey.id)}}">
Response home
Response home (full sankey)
</a>
</li>

Expand Down Expand Up @@ -40,7 +40,7 @@ <h2>{% block title %}Response to: {{survey.title}}{% endblock %}</h1>

<li>
<a href="{{url_for('survey.view_survey', survey_id=survey.id)}}">
View survey config
View survey info
</a>
</li>

Expand Down
76 changes: 65 additions & 11 deletions usaon_vta_survey/templates/response/data_products.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% from 'bootstrap5/utils.html' import render_icon %}

{% block content %}
{% include 'includes/highcharts.html' %}

{{super()}}

Expand All @@ -11,9 +12,15 @@ <h3>Data products</h3>
<div class="two-columns">
<div>
<table>
<tr>
<th rowspan="2">Name</th>
<th colspan="4">Related Observing Systems</th>
</tr>
<tr>
<th>Name</th>
<th>Observing systems related</th>
<th>Performance Rating</th>
<th>Criticality Rating</th>
<th>Actions</th>
</tr>
{% for data_product in response.data_products %}
<tr>
Expand All @@ -23,12 +30,27 @@ <h3>Data products</h3>
None
<br />
{% endif %}
{% for input_relationship in data_product.input_relationships %}
<ul>
<li>{{input_relationship.observing_system.short_name}}: {{input_relationship.performace_rating}}</li>
</ul>
{% endfor %}

<ul>
{% for input_relationship in data_product.input_relationships %}
<li>{{input_relationship.observing_system.short_name}}</li>
{% endfor %}
</ul>
</td>
<td>
<ul>
{% for input_relationship in data_product.input_relationships %}
<li>{{input_relationship.performance_rating}}</li>
{% endfor %}
</ul>
</td>
<td>
<ul>
{% for input_relationship in data_product.input_relationships %}
<li>{{input_relationship.criticality_rating}}</li>
{% endfor %}
</ul>
</td>
<td>
<a href="{{url_for(
'observing_system_data_product.view_response_observing_system_data_product_relationships',
survey_id=survey.id,
Expand All @@ -41,12 +63,44 @@ <h3>Data products</h3>
{% endfor %}
</table>
</div>

{% if sankey_series == [] %}
<div>Please input at least one dataproduct-to-observing systems relationship to display diagram</div>
{% else %}
<figure class="highcharts-figure">
<div id="highcharts-container" />
</figure>
{% endif %}
</div>

<h3>Add data product</h3>
<form method="POST">
{{render_form(form, button_map={'submit_button': 'primary'}) }}

</form>
{% if not current_user.role_id not in ['admin', 'respondent'] %}
<h3>Add data product</h3>
<form method="POST">
{{render_form(form, button_map={'submit_button': 'primary'}) }}
</form>
{% endif %}

<script>
Highcharts.chart('highcharts-container', {
chart: {
type: 'sankey',
},
title: {
text: 'U.S. AON Value Tree Analysis Diagram',
style: {fontSize: '20px'},
},
accessibility: {
description: 'Sankey plot for U.S. AON Value Tree',
point: {
valueDescriptionFormat: '{index}. {point.from} to {point.to}, {point.weight}.'
}
},
series: [{
keys: ['from', 'to', 'weight'],
data: {{sankey_series | safe}},
}]
});
</script>

{% endblock %}
10 changes: 6 additions & 4 deletions usaon_vta_survey/templates/response/observing_systems.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ <h3>Observing systems</h3>
{% endfor %}
</table>

<h3>Add observing system</h3>
<form method="POST">
{{render_form(form, button_map={'submit_button': 'primary'}) }}

</form>
{% if not current_user.role_id not in ['admin', 'respondent'] %}
<h3>Add observing system</h3>
<form method="POST">
{{render_form(form, button_map={'submit_button': 'primary'}) }}

</form>
{% endif %}
{% endblock %}
Loading

0 comments on commit f6b9ee1

Please sign in to comment.