Spaces:
Runtime error
Runtime error
| # -*- coding: utf-8 -*- | |
| import streamlit as st | |
| import plotly.express as px | |
| from data_processing import load_data, process_data, get_monetary_dataframe, get_themes_per_year | |
| def _max_width_(): | |
| max_width_str = f"max-width: 1500px;" | |
| st.markdown( | |
| f""" | |
| <style> | |
| .reportview-container .main .block-container{{ | |
| {max_width_str} | |
| }} | |
| </style> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| # force screen width | |
| _max_width_() | |
| st.title("Data Analysis π π") | |
| st.write("by [Teolex](https://www.theolex.io/)") | |
| # load and process data | |
| data = load_data() | |
| decisions, organizations, authorities = process_data(data) | |
| st.sidebar.title("Parameters") | |
| authorities_country = st.sidebar.selectbox('Authority country', authorities.country.unique()) | |
| select_auth = authorities[authorities.country == authorities_country].name.sort_values() | |
| authority = st.sidebar.selectbox('Authority', ['All', *select_auth]) | |
| min_year, max_year = st.sidebar.slider('Decisions year', min_value=2001, max_value=2021, value=(2010, 2021)) | |
| # apply filters | |
| authority_filter = True | |
| if authority != 'All': | |
| authority_filter = decisions.authorities_name.apply(lambda a: authority in a) | |
| else: | |
| authority_filter = decisions.authorities_name.apply(lambda a: bool(set(select_auth) & set(a))) | |
| year_filter = (decisions.year >= min_year) & (decisions.year <= max_year) | |
| decision_scope = decisions[authority_filter & year_filter] | |
| # explore monetary sanctions | |
| monetary_decision = get_monetary_dataframe(decision_scope) | |
| ## | |
| # Plot Graphs | |
| ## | |
| st.subheader("The organizations' sectors targeted by the sanctions: ") | |
| st.markdown("The graph shows the cumulated monetary sanction for the current filters") | |
| fig = px.treemap(monetary_decision, | |
| path=['org_company_type'], | |
| color='org_revenues', | |
| color_continuous_scale='RdBu', | |
| template="simple_white", | |
| values='monetary_sanction', | |
| width=1000, height=600) | |
| st.plotly_chart(fig) | |
| st.subheader("The organizations' regions targeted by the sanctions: ") | |
| st.markdown("The graph shows the cumulated monetary sanction for the current filters") | |
| fig = px.treemap(monetary_decision[~monetary_decision.org_continent.isnull()], | |
| path=['org_continent', 'org_country'], | |
| color_continuous_scale='RdBu', | |
| template="simple_white", | |
| values='monetary_sanction', | |
| width=1000, height=600) | |
| st.plotly_chart(fig) | |
| st.subheader("Revenues vs monetary sanctions representation ") | |
| st.markdown("The graph shows the cumulated monetary sanction for the current filters") | |
| fig = px.scatter(monetary_decision, | |
| x="org_revenues", | |
| y="monetary_sanction", | |
| log_x=True, | |
| log_y=True, | |
| template="simple_white", | |
| color="same_country", | |
| color_continuous_scale='RdBu', | |
| hover_name="org_name", | |
| width=1000, height=600) | |
| st.plotly_chart(fig) | |
| st.subheader("Sum of monetary sanctions over time ") | |
| st.markdown("The graph shows the cumulated monetary sanction per year for each violation theme") | |
| chart_data = get_themes_per_year(monetary_decision) | |
| fig = px.area(chart_data, x="year", | |
| y="monetary_sanction", | |
| color="violation_theme", | |
| template="simple_white", | |
| # groupnorm="fraction", | |
| line_group="violation_theme", | |
| width=1000, height=600) | |
| st.plotly_chart(fig) | |