Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/scenarios-ui-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ env:

jobs:
deploy:
name: Testing
name: deploy
runs-on: ubuntu-latest
steps:
- name: Set inputs
Expand Down
16 changes: 15 additions & 1 deletion pages/components/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import pydeck as pdk
import plotly.express as px
import geopandas
from streamlit import column_config

from modules.logging import get_session_logger

logger = get_session_logger()

class View:
'''
Expand Down Expand Up @@ -46,7 +51,8 @@ class DataframeView(View):
display_cols : list[str]
The names of the columns to display. By default displays all the columns.
'''
def __init__(self, data=None, selectable=False, display_cols=None, hide_index=True):
def __init__(self, data=None, selectable=False, display_cols=None, hide_index=True,
column_config=None):
if data is None:
data = pd.DataFrame(columns=display_cols)
self.data = data
Expand All @@ -60,12 +66,19 @@ def __init__(self, data=None, selectable=False, display_cols=None, hide_index=Tr
self.display_cols = display_cols

self.column_config = {col_name: None for col_name in data.columns}

if column_config is not None:
self.column_config.update(column_config)

for c in display_cols:
if self.column_config.get(c, None) is not None:
continue
if 'TIV' in c:
self.column_config[c] = st.column_config.TextColumn(c)
else:
self.column_config[c] = st.column_config.TextColumn(self.format_column_heading(c))


def display(self, max_rows=1000, key=None):
'''
Show the dataframe.
Expand Down Expand Up @@ -119,6 +132,7 @@ def colour_status(status):
data_styled = data_styled.style.format(format_status, subset=['status'])
data_styled = data_styled.map(colour_status, subset=['status'])

logger.info(args)
ret = st.dataframe(data_styled, **args)

if n_rows > max_rows:
Expand Down
42 changes: 41 additions & 1 deletion pages/components/process.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from oasis_data_manager.errors import OasisException
import pandas as pd
from requests.models import HTTPError
import streamlit as st

from modules.client import ClientInterface
from modules.logging import get_session_logger

logger = get_session_logger()

def number_rows(portfolio_ids, client_interface, filename='location_file', col_name='number_rows'):
data = {'id': [], col_name: []}
Expand Down Expand Up @@ -51,7 +58,10 @@ def enrich_analyses_with_portfolios(analyses, portfolios):
return analyses

def enrich_analyses_with_models(analyses, models):
models = models[['id', 'model_id', 'supplier_id']].rename(columns={'supplier_id': 'model_supplier'})
cols = ['id', 'model_id', 'supplier_id']
if 'model_name' in models:
cols += ['model_name']
models = models[cols].rename(columns={'supplier_id': 'model_supplier'})
analyses = analyses.set_index('model').join(models.set_index('id')).reset_index(names='model')

return analyses
Expand All @@ -66,3 +76,33 @@ def enrich_analyses(analyses, portfolios=None, models=None):
analyses = enrich_analyses_with_models(analyses, models)

return analyses


@st.cache_data(ttl="1d", hash_funcs={ClientInterface: lambda ci: ci.client.api.tkn_access})
def add_model_names_to_models_cached(models: pd.DataFrame,
ci: ClientInterface,
col_name='model_name'):
return add_model_names_to_models(models, ci, col_name)


def add_model_names_to_models(models, ci, col_name='model_name'):
'''Add the model names to models. Note the model `id` should be the index of the models.

Args:
models (DataFrame): dataframe containing models endpoint output
ci (ClientInterface): intialised client interface
col_name (str) : column name for model names
'''
models[col_name] = ''
for model_id, _ in models.iterrows():
logger.info(model_id)
try:
models.at[model_id, col_name] = ci.models.settings.get(model_id).get('name', None)
except HTTPError as _:
models.at[model_id, col_name] = None
logger.warning(f'No settings for model_id: {model_id}')

models[col_name] = models[col_name].fillna(models['model_id'])

return models

32 changes: 23 additions & 9 deletions pages/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from requests.exceptions import HTTPError
import streamlit as st
from modules.logging import get_session_logger
from modules.nav import SidebarNav
from modules.config import retrieve_ui_config
from modules.rerun import RefreshHandler
Expand All @@ -17,13 +18,11 @@
import time
from json import JSONDecodeError
import json
from modules.client import ClientInterface
import logging

from pages.components.output import generate_eltcalc_fragment, generate_leccalc_fragment, generate_pltcalc_fragment, model_summary, summarise_inputs, generate_aalcalc_fragment
from pages.components.process import enrich_analyses, enrich_portfolios
from pages.components.process import add_model_names_to_models, add_model_names_to_models_cached, enrich_analyses, enrich_portfolios

logger = logging.getLogger(__name__)
logger = get_session_logger()

##########################################################################################
# Header
Expand Down Expand Up @@ -82,9 +81,15 @@
'Select an event scenarios by clicking the grey box on the left side of the table.'

models = client_interface.models.get(df=True)
display_cols = [ 'model_id', 'supplier_id' ]

model_view = DataframeView(models, selectable='single', display_cols=display_cols)
models = models.set_index('id', drop=False)
models = add_model_names_to_models_cached(models, client_interface)
display_cols = [ 'model_name', 'supplier_id' ]
column_config = {
'model_name': 'Scenarios Footprint',
'supplier_id': 'Supplier'
}

model_view = DataframeView(models, selectable='single', display_cols=display_cols, column_config=column_config)
selected_model = model_view.display()

'Currently, it is not possible to add your own scenarios directly; please describe any scenario you would like to add as a Github issue [here](https://github.com/OasisLMF/OasisPythonUI/issues).'
Expand Down Expand Up @@ -203,6 +208,8 @@ def analysis_fragment():
analyses = client_interface.analyses.get(df=True)
portfolios = client_interface.portfolios.get(df=True)
models = client_interface.models.get(df=True)
models = models.set_index('id', drop=False)
models = add_model_names_to_models_cached(models, client_interface)

completed_statuses = ['RUN_COMPLETED', 'RUN_CANCELLED', 'RUN_ERROR']
running_statuses = ['RUN_QUEUED', 'RUN_STARTED']
Expand All @@ -216,9 +223,16 @@ def analysis_fragment():
analyses = analyses[analyses['status'].isin(valid_statuses)]
analyses = enrich_analyses(analyses, portfolios, models).sort_values('id', ascending=False)

display_cols = ['name', 'portfolio_name', 'model_id', 'model_supplier', 'status']
display_cols = ['name', 'status', 'portfolio_name', 'model_name', 'model_supplier']


analyses_view = DataframeView(analyses, display_cols=display_cols, selectable='single')
column_config = {
'name': 'Analysis Name',
'model_name': 'Scenarios Footprint',
'supplier_id': 'Supplier'
}
analyses_view = DataframeView(analyses, display_cols=display_cols, selectable='single',
column_config=column_config)
selected = analyses_view.display()

oed_group = st.pills("Group output by:",
Expand Down
6 changes: 3 additions & 3 deletions scenarios/deploy_scenarios_ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ echo "UPDATE_SCENARIOS: $UPDATE_SCENARIOS"
echo "MODELS_PATH: $MODELS_PATH"

# clear up space on device
docker system prune --volumes
docker system prune --volumes -f

if [[ "$WIPE" = 'true' ]] && [[ "$DEPLOY_ALL" = 'false' ]]; then
echo "WIPE without DEPLOY_ALL not allowed."
Expand All @@ -25,7 +25,7 @@ fi
if [[ "$DEPLOY_UI" = 'true' ]] && [[ "$DEPLOY_ALL" != 'true' ]]; then
git -C "$UI_PATH" pull
docker image pull coreoasis/oasis_scenarios
docker compose -f "$UI_PATH/oasis-scenarios-ui.yml" up -d
docker compose -f "$UI_PATH/oasis-scenarios-ui.yml" up -d --no-build
fi

if [[ "$DEPLOY_ALL" = 'true' ]]; then
Expand All @@ -47,4 +47,4 @@ if [[ "$DEPLOY_ALL" = 'true' ]]; then
fi

# run cleanup
docker system prune --volumes
docker system prune --volumes -f