Skip to content

Add properties attribute to sources - #13

Open
jernestmyers wants to merge 4 commits into
mainfrom
add-properties-attr-to-sources
Open

Add properties attribute to sources#13
jernestmyers wants to merge 4 commits into
mainfrom
add-properties-attr-to-sources

Conversation

@jernestmyers

Copy link
Copy Markdown

Allows the request to filter sources by frequency and by median_flux in lightserve's AllSkyMap component.

@jernestmyers
jernestmyers force-pushed the add-properties-attr-to-sources branch from 433f4c5 to c568f47 Compare August 28, 2026 19:51
Comment on lines +201 to +236
# ---------------------------------------------------------------------------
# Continuous aggregate backing Source.properties.median_flux.
#
# Deliberately a separate view from flux_monthly rather than an added column
# on it. It is only ever read for the current bucket (see
# TimescaleAnalysisProvider.get_median_flux_for_all_sources), so it doesn't
# need flux_monthly's long retention, and keeping it separate means it can be
# introduced without dropping/rebuilding a view that lightcurve binning
# already depends on.
#
# start_offset is 65 days, not flux_monthly's 90; TimescaleDB requires a
# continuous aggregate's refresh window to span at least 2 bucket widths (60
# days here), so this is that floor plus a few days of buffer.
# ---------------------------------------------------------------------------

CONTINUOUS_AGGREGATE_MEDIAN_MONTHLY = """
CREATE MATERIALIZED VIEW IF NOT EXISTS flux_median_monthly
WITH (timescaledb.continuous, timescaledb.materialized_only = false) AS
SELECT
time_bucket('30 days', time) AS bucket,
source_id,
frequency,
percentile_cont(0.5) WITHIN GROUP (ORDER BY flux) AS median_flux
FROM flux_measurements
GROUP BY bucket, source_id, frequency
WITH NO DATA;
"""

CONTINUOUS_AGGREGATE_MEDIAN_MONTHLY_REFRESH_POLICY = """
SELECT add_continuous_aggregate_policy('flux_median_monthly',
start_offset => INTERVAL '65 days',
end_offset => INTERVAL '1 hour',
schedule_interval => INTERVAL '1 day',
if_not_exists => true
);
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a bit confused here as to why we don't just add these to the original table? It would be adding a median to the monthly table which is fine and only would use a little more storage.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

My initial reasoning was more to do with thinking that I'd be messing with pre-existing binning, so I thought it made sense to separate them out. When I realized that TimescaleDB is not yet in use but is intended to be deployed with the initial release, I didn't necessarily rethink the pros/cons of combining/separating the binning. I can combine them if that's preferred, though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like to keep them the same if possible, it would keep things simple. Fewer tables to maintain.

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.

2 participants