Skip to content

Commit

Permalink
Adicionando contador aos resultados
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamaia committed Nov 8, 2024
1 parent 1075f71 commit c0372cd
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions curadoria_coletiva/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def _create_layout(df):
style={"margin-top": "30px"},
children=[
html.H2(
"Resultados",
id="results-section-title",
children="Resultados",
style={
"color": "#8B008B",
"margin-bottom": "20px",
Expand Down Expand Up @@ -355,7 +356,7 @@ def _generate_collapsible_comments(row):

def _register_callbacks(app, df):
@app.callback(
Output("results", "children"),
[Output("results", "children"), Output("results-section-title", "children")],
Input("search-box", "value"),
Input("subject-dropdown", "value"),
Input("format-dropdown", "value"),
Expand All @@ -375,9 +376,10 @@ def update_table(
free_filter,
sort_column,
):
"""Atualiza a tabela com base nos filtros de busca, assunto, formato, estilo de aprendizagem e ordenação."""
"""Atualiza a tabela e o título com a contagem de resultados com base nos filtros."""
filtered_df = df

# Aplicar os filtros
if search_term:
filtered_df = filtered_df[
filtered_df.apply(
Expand All @@ -399,34 +401,29 @@ def update_table(
filtered_df = filtered_df[filtered_df["formato"].isin(selected_format)]

if selected_learning_style:
filtered_df = filtered_df[
filtered_df["estilo_aprendizagem"].isin(selected_learning_style)
]
filtered_df = filtered_df[filtered_df["estilo_aprendizagem"].isin(selected_learning_style)]

if selected_language:
filtered_df = filtered_df[
filtered_df["idioma"].isin(selected_language)
]
filtered_df = filtered_df[filtered_df["idioma"].isin(selected_language)]

if selected_level:
filtered_df = filtered_df[
filtered_df["nivel_dificuldade"].isin(selected_level)
]
filtered_df = filtered_df[filtered_df["nivel_dificuldade"].isin(selected_level)]

if free_filter:
filtered_df = filtered_df[filtered_df["eh_gratuito"] == True]

# Aplicar ordenação se selecionada
if sort_column:
filtered_df = filtered_df.sort_values(by=sort_column)

if free_filter:
filtered_df = filtered_df[filtered_df["eh_gratuito"] == True]
# Contagem de resultados
result_count = len(filtered_df)
result_title = f"Resultados ({result_count})"

if not filtered_df.empty:
return generate_result_layout(filtered_df)
else:
return html.Div(
"Nenhum resultado encontrado.",
style={"color": "red", "text-align": "center", "margin-top": "20px"},
)
# Layout dos resultados
result_layout = generate_result_layout(filtered_df)

return result_layout, result_title

data = _load_yaml_data(yaml_file_path)
df = _create_dataframe(data)
Expand Down

0 comments on commit c0372cd

Please sign in to comment.