Skip to content

Commit

Permalink
Use UUID to accurately display enemy stats in modal
Browse files Browse the repository at this point in the history
- Modified populate_modal function to use UUID instead of name to fetch and display enemy data
- Adjusted callbacks to handle UUID data from the grid
- Updated column definitions to hide/exclude UUID from the user view
  • Loading branch information
perfectly-preserved-pie committed Oct 15, 2023
1 parent 400054d commit e2c5b5d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dash_ag_grid as dag
import dash_bootstrap_components as dbc
import pandas as pd
import uuid

external_stylesheets = [
dbc.icons.BOOTSTRAP,
Expand All @@ -19,6 +20,11 @@
ep2_df = pd.read_json('json/episode2.json')
ep3_df = pd.read_json('json/episode3.json')

# Generate a unique ID for each row
ep1_df['uuid'] = [str(uuid.uuid4()) for _ in range(len(ep1_df))]
ep2_df['uuid'] = [str(uuid.uuid4()) for _ in range(len(ep2_df))]
ep3_df['uuid'] = [str(uuid.uuid4()) for _ in range(len(ep3_df))]

app = Dash(
__name__,
external_stylesheets=external_stylesheets,
Expand Down Expand Up @@ -169,7 +175,7 @@ def get_value_getter(column_name):
]
# Add other columns except the "Name" column
for i in df.columns:
if i != "Name":
if i not in ["Name", "uuid"]:
column_def = {
"field": i,
"filter": "agNumberColumnFilter" if is_numeric_col(df, i) else "agTextColumnFilter",
Expand Down Expand Up @@ -264,8 +270,8 @@ def open_modal(cell_clicked_data, close_btn_clicks, modal_open, grid_data):

# Extract the name of the clicked enemy using rowId
row_id = cell_clicked_data['rowId']
clicked_name = grid_data[int(row_id)]['Name']
return True, {"name": clicked_name}
clicked_uuid = grid_data[int(row_id)]['uuid']
return True, {"uuid": clicked_uuid}

else:
raise PreventUpdate
Expand Down Expand Up @@ -295,15 +301,18 @@ def populate_modal(data, n1, n2, n3):
elif latest_button == 'btn-ep3':
df = ep3_df

# Check if the desired name exists in the dataset
selected_rows = df[df["Name"] == data["name"]]
# Check if the desired uuid exists in the dataset
selected_rows = df[df["uuid"] == data["uuid"]]
if selected_rows.empty:
logger.error(f"Name {data['name']} not found in dataset.")
logger.error(f"UUID {data['uuid']} not found in dataset.")
raise PreventUpdate

selected_row = selected_rows.iloc[0]
logger.debug(f"Selected Row Data: {selected_row}") # Log the complete row data

# Exclude the UUID from the displayed data
selected_row = selected_row.drop("uuid")

content = []
for key, value in selected_row.items():
if pd.api.types.is_numeric_dtype(value) and pd.notna(value): # Check if value is numeric and not NaN
Expand Down

0 comments on commit e2c5b5d

Please sign in to comment.