Add properties attribute to sources - #13
Conversation
823d0f7 to
92d10f0
Compare
92d10f0 to
433f4c5
Compare
433f4c5 to
c568f47
Compare
| # --------------------------------------------------------------------------- | ||
| # 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 | ||
| ); | ||
| """ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'd like to keep them the same if possible, it would keep things simple. Fewer tables to maintain.
Allows the request to filter sources by frequency and by median_flux in
lightserve's AllSkyMap component.