-
Notifications
You must be signed in to change notification settings - Fork 4
Update dashboard for new date format in database #363
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
base: main
Are you sure you want to change the base?
Conversation
| f"{col}=%{{customdata[{hover_data.index(col)}]:.4g}}" | ||
| for col in cols | ||
| ] | ||
| for col in cols: |
There was a problem hiding this comment.
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).
| # 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}}" | ||
| ) |
There was a problem hiding this comment.
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?
| # 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.
| # 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) |
There was a problem hiding this comment.
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)
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, inpymongo, it is more standard and efficient to store the date as adatetimeobject.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.)