Skip to content
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

Dash update #189

Merged
merged 8 commits into from
Dec 19, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,4 @@ dmypy.json
.github/desktop.ini
*.ini

configs/configuraciones_generales.yaml
21 changes: 21 additions & 0 deletions run_all_urbantrips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from urbantrips import initialize_environment
from urbantrips import process_transactions
from urbantrips import run_postprocessing
from urbantrips import create_viz
from urbantrips import run_dashboard

import warnings

# Filter and suppress specific warnings
warnings.filterwarnings("ignore")

def main():

initialize_environment.main()
process_transactions.main()
run_postprocessing.main()
create_viz.main()
run_dashboard.main()

if __name__ == "__main__":
main()
19 changes: 15 additions & 4 deletions urbantrips/dashboard/dash_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from shapely import wkt
from matplotlib import colors as mcolors
from folium import Figure
from shapely.geometry import LineString, Point, Polygon
from shapely.geometry import LineString, Point, Polygon, shape, mapping
import h3


def leer_configs_generales():
Expand Down Expand Up @@ -127,12 +128,16 @@ def calculate_weighted_means(df,

def normalize_vars(tabla):
if 'dia' in tabla.columns:
tabla.loc[tabla.dia == 'weekday', 'dia'] = 'Día hábil'
tabla.loc[tabla.dia == 'weekday', 'dia'] = 'Hábil'
tabla.loc[tabla.dia == 'weekend', 'dia'] = 'Fin de semana'
if 'day_type' in tabla.columns:
tabla.loc[tabla.day_type == 'weekday', 'day_type'] = 'Día hábil'
tabla.loc[tabla.day_type == 'weekday', 'day_type'] = 'Hábil'
tabla.loc[tabla.day_type == 'weekend', 'day_type'] = 'Fin de semana'
if 'tipo_dia' in tabla.columns:
tabla.loc[tabla.tipo_dia == 'Dia habil', 'tipo_dia'] = 'Hábil'
# tabla.loc[tabla.tipo_dia == 'weekend', 'tipo_dia'] = 'Fin de semana'


if 'nombre_linea' in tabla.columns:
tabla['nombre_linea'] = tabla['nombre_linea'].str.replace(' -', '')
if 'Modo' in tabla.columns:
Expand Down Expand Up @@ -624,4 +629,10 @@ def traigo_zonas_values(tipo = 'etapas'):
(zonas_values.inicio_norm.notna())&
(zonas_values.inicio_norm!=' (cuenca)')].sort_values(['zona', 'inicio_norm']).rename(columns={'inicio_norm':'Nombre'})

return zonas_values
return zonas_values

# Convert geometry to H3 indices
def get_h3_indices_in_geometry(geometry, resolution):
geojson = mapping(geometry)
h3_indices = list(h3.polyfill(geojson, resolution, geo_json_conformant=True))
return h3_indices
44 changes: 30 additions & 14 deletions urbantrips/dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from folium import Figure
from shapely.geometry import LineString

from dash_utils import levanto_tabla_sql, get_logo
from dash_utils import levanto_tabla_sql, get_logo, traigo_indicadores


st.set_page_config(layout="wide")
Expand Down Expand Up @@ -79,26 +79,24 @@

# Inject CSS with Markdown
col3.markdown(hide_table_row_index, unsafe_allow_html=True)


col3.table(df)

df = indicadores.loc[indicadores.orden == 3, ['Indicador', 'Valor']].copy()
titulo = indicadores.loc[indicadores.orden == 3].Titulo.unique()[0]

col2.text(titulo)
# CSS to inject contained in a string
hide_table_row_index = """
<style>
thead tr th:first-child {display:none}
tbody th {display:none}
</style>
"""
# col2.text(titulo)
# # CSS to inject contained in a string
# hide_table_row_index = """
# <style>
# thead tr th:first-child {display:none}
# tbody th {display:none}
# </style>
# """

# Inject CSS with Markdown
col2.markdown(hide_table_row_index, unsafe_allow_html=True)
# # Inject CSS with Markdown
# col2.markdown(hide_table_row_index, unsafe_allow_html=True)

col2.table(df)
# col2.table(df)
else:

# Usar HTML para personalizar el estilo del texto
Expand Down Expand Up @@ -127,3 +125,21 @@
"""
col2.markdown(texto_html, unsafe_allow_html=True)

with st.expander('Indicadores', True):
col1, col2, col3 = st.columns([2, 2, 2])

general, modal, distancias = traigo_indicadores('all')

st.session_state.general_ = general.loc[general.mes==desc_dia_i, ['Tipo', 'Indicador', 'Valor']].set_index('Tipo')
st.session_state.modal_ = modal.loc[modal.mes==desc_dia_i, ['Tipo', 'Indicador', 'Valor']].set_index('Tipo')
st.session_state.distancias_ = distancias.loc[distancias.mes==desc_dia_i, ['Tipo', 'Indicador', 'Valor']].set_index('Tipo')


st.session_state.general_ = st.session_state.general_[~st.session_state.general_.Indicador.isin(['Cantidad de Usuarios', 'Cantidad de Viajes'])]
if len(st.session_state.general_) > 0:
col1.write(f'Periodo: {desc_dia_i}')
col1.table(st.session_state.general_)
# col2.write('')
# col2.table(st.session_state.modal_)
col3.write('')
col3.table(st.session_state.distancias_)
Loading
Loading