Skip to content

fix: omit the placeholder year from meter timeseries date labels - #147

Open
eastagiletracker wants to merge 1 commit into
CenterForTheBuiltEnvironment:mainfrom
eastagiletracker:agile-board/timeseries-date-format
Open

fix: omit the placeholder year from meter timeseries date labels#147
eastagiletracker wants to merge 1 commit into
CenterForTheBuiltEnvironment:mainfrom
eastagiletracker:agile-board/timeseries-date-format

Conversation

@eastagiletracker

Copy link
Copy Markdown

This PR proposes formatting the meter timeseries date labels so they show month and day instead of the placeholder year carried by the load profiles (Fixes #137). We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/217. You can sign in with your GitHub ID to claim ownership of the project.

What happens today

The library load profiles are typical-year data — the simulated rows in data/input/load_data_full.parquet are stamped 2001 — so the year on the Results page meter timeseries describes nothing about the results, and next to the emission scenario years it reads as if the simulation ran in 2001. plot_meter_timeseries sets no date format on the x axis, so Plotly falls back to its own date ticks, which include the year, and the hover template hard-codes Time: %{x|%Y-%m-%d %H:%M}.

Reproduced on main at 4fa67fb, driving the same function pages/results_page.py calls from the update_meter_plot callback:

import pandas as pd
import utils.plotly_theme  # registers the app template
from src import paths
from src.visuals import plot_meter_timeseries

raw = pd.read_parquet(paths.LOAD_DATA_PARQUET)
raw = raw[raw["building_id"] == raw["building_id"].iloc[0]].copy()
raw["timestamp"] = pd.to_datetime(raw["timestamp"])
raw = raw.set_index("timestamp")

df = pd.DataFrame(index=raw.index)
df["eq_scen_id"], df["em_scen_id"] = "eq_scen_1", "em_scen_1"
df["elec_awhp_h_Wh"] = raw["heating_W"] / 3.0
df["elec_chiller_Wh"] = raw["cooling_W"] / 4.0

fig = plot_meter_timeseries(df, "eq_scen_1", "em_scen_1", freq="D")
print("tickformatstops:", fig.layout.xaxis.tickformatstops)
print("hover:", fig.data[0].hovertemplate.split("<br>")[0])
tickformatstops: ()
hover: Time: %{x|%Y-%m-%d %H:%M}

Rendered, that is the axis from your report — Jan 2001 … Jan 2002:

before

The change

src/visuals.py gains one date-format table and applies it in plot_meter_timeseries. The x axis gets tickformatstops covering every zoom range — %b %d, %H:%M below daily ticks, %b %d from daily to monthly, %b above — so the year stays off the axis whether the user is looking at the whole year or has zoomed into a week. The hover format now follows the aggregation dropdown instead of being fixed: %b %d, %H:%M for hourly, %b %d for daily and weekly, %B for monthly. Nothing else moves — the underlying timestamps, the resampling and the plotted values are untouched, so downloads and every other chart are unaffected.

The same profile after the change, and zoomed to a week of hourly data:

after

after, zoomed

Verification

tests/test_visuals.py is new and covers both the line and stacked variants: the axis carries a format at every zoom level and none of them contains %Y, the zoom ranges are contiguous, the hover format matches each aggregation the dropdown offers, and — as controls — the daily sums, the x values and the gas toggle behave exactly as before. Six of the ten fail without the two behaviour lines in plot_meter_timeseries (revert them and keep the format table to see it), which is what pins the fix rather than the constant.

python -m pytest goes from 19 passing on main to 29 passing here, with no test failing that passed before. ruff check . and ruff format --check . report exactly what they report on main (one pre-existing RUF013 in utils/tooltips.py, 38 files formatted). The three images above are real renders of the figure this code returns, so the format strings are checked the way the browser reads them, not just as text.

One judgement call worth your review: the year is now dropped for user-uploaded measured data too. That follows the report, and within a plot the year is near-constant since measured data is limited to one year, but if you would rather keep it for uploads it is a one-line branch in the format table.

How this was managed

This work was tracked as Datetime shows irrelevant year on timeseries plots on the board at https://eastagiletracker.com/projects/217, which was built by importing this repository's issues and pull requests (146 stories, 11 labels).

board

If you'd rather not receive contributions like this, reply no-more-prs on this pull request and we won't open any further ones on your repositories.


Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com

Load profiles are typical-year data, so the year on the meter timeseries axis
and hover (2001 for the simulated library profiles) carries no meaning and is
easily read as the emission scenario year. Format date labels as month/day, with
time of day when the aggregation is hourly, and keep the year off the axis at
every zoom level via tickformatstops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Datetime shows irrelevant year on timeseries plots

1 participant