Skip to content

Conversation

@RemiLehe
Copy link
Contributor

@RemiLehe RemiLehe commented Jan 16, 2026

The database has an entry "date" for each data point. Data used to be stored in the form of a string (e.g. "2025-03-20 13:00:02"). However, in pymongo, it is more standard and efficient to store the date as a datetime object.

I recently updated the database to ensure that this is now the case.

Accordingly, the code in the dashboard that loads the database now needs to convert this datetime object to a string. (This string is displayed, for the experimental points, when hovering on a point.)

Screenshot 2026-01-16 at 11 27 40 AM

f"{col}=%{{customdata[{hover_data.index(col)}]:.4g}}"
for col in cols
]
for col in cols:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves a previously existing issue, where the hover box would show date=NaN, because the code attempted to format a string (e.g. 2026-01-16 12:00:00) with .4g which is for numerical values (displaying them with 4 significant digits).

Comment on lines +216 to +226
# Check if column is "date"
if col == "date":
# For string/date columns, use no format specifier (displays as-is)
section.append(
f"{col}=%{{customdata[{hover_data.index(col)}]}}"
)
else:
# Use numeric formatting for numeric columns
section.append(
f"{col}=%{{customdata[{hover_data.index(col)}]:.4g}}"
)
Copy link
Member

@EZoni EZoni Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be done with less code. Would this work?

Suggested change
# Check if column is "date"
if col == "date":
# For string/date columns, use no format specifier (displays as-is)
section.append(
f"{col}=%{{customdata[{hover_data.index(col)}]}}"
)
else:
# Use numeric formatting for numeric columns
section.append(
f"{col}=%{{customdata[{hover_data.index(col)}]:.4g}}"
)
# For string/date columns, use no format specifier (displays as-is)
format = "" if col == "date" else ".4g"
section.append(
f"{col}=%{{customdata[{hover_data.index(col)}]{format}}}"
)

This simpler example works for me, not sure if the %{} syntax above breaks it:

format = "" if col == "date" else ".4g"
value = 1.23456789
string = f"{value:{format}}"

It prints '1.23456789' if you set col = "date" and '1.235' otherwise.

Comment on lines +79 to +88
# Make sure that the _id is stored as a string (important for interactivity in plotly)
if "_id" in exp_data.columns:
exp_data["_id"] = exp_data["_id"].astype(str)
if "_id" in sim_data.columns:
sim_data["_id"] = sim_data["_id"].astype(str)
# Convert 'date' field from datetime object to string
if "date" in exp_data.columns:
exp_data["date"] = exp_data["date"].astype(str)
if "date" in sim_data.columns:
sim_data["date"] = sim_data["date"].astype(str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be done with less code. Would this be equivalent?

# Store '_id', 'date' as string
for key in ["_id", "date"]:
    if key in exp_data.columns:
        exp_data[key] = exp_data[key].astype(str)
    if key in sim_data.columns:
        sim_data[key] = sim_data[key].astype(str)

@EZoni EZoni added bug Something isn't working dashboard Changes related to the dashboard labels Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dashboard Changes related to the dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants