From 1cf97d7b41be8002b1126c4010ad40483f6b7628 Mon Sep 17 00:00:00 2001 From: johndonor3 Date: Wed, 18 Sep 2024 08:39:05 -0600 Subject: [PATCH] model classes for CartonToSdssID and RSRunRoSdssID --- python/sdssdb/peewee/sdss5db/sandbox.py | 44 +++++++++++++++++++ .../load_table/metrics/created_views.sql | 43 +++++++----------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/python/sdssdb/peewee/sdss5db/sandbox.py b/python/sdssdb/peewee/sdss5db/sandbox.py index 6276fb31..32004021 100644 --- a/python/sdssdb/peewee/sdss5db/sandbox.py +++ b/python/sdssdb/peewee/sdss5db/sandbox.py @@ -361,3 +361,47 @@ class Epoch(TargetdbBase): class Meta: table_name = 'epoch' + + +class RsRunToSdssID(TargetdbBase): + assignment_pk = IntegerField() + mjd = FloatField() + catalogid = ForeignKeyField(column_name='catalogid', + field='catalogid', + model=catalogdb.Catalog, + null=False) + program = TextField() + carton = TextField() + label = TextField() # FIX! To instrument in net table load + default_lambda_eff = FloatField() + sdss_id = ForeignKeyField(column_name='sdss_id', + field='sdss_id', + model=catalogdb.SDSS_ID_flat, + null=False) + observatory = TextField() + done = IntegerField() + field_id = IntegerField() + + class Meta: + table_name = 'rs_run_to_sdssid' + + +class CartonToSdssID(TargetdbBase): + assignment_pk = IntegerField() + mjd = FloatField() + catalogid = ForeignKeyField(column_name='catalogid', + field='catalogid', + model=catalogdb.Catalog, + null=False) + program = TextField() + carton = TextField() + label = TextField() # FIX! To instrument in net table load + default_lambda_eff = FloatField() + sdss_id = ForeignKeyField(column_name='sdss_id', + field='sdss_id', + model=catalogdb.SDSS_ID_flat, + null=False) + nexp = IntegerField() + + class Meta: + table_name = 'carton_to_sdssid' diff --git a/schema/sdss5db/targetdb/load_table/metrics/created_views.sql b/schema/sdss5db/targetdb/load_table/metrics/created_views.sql index 9ba20393..d2608009 100644 --- a/schema/sdss5db/targetdb/load_table/metrics/created_views.sql +++ b/schema/sdss5db/targetdb/load_table/metrics/created_views.sql @@ -1,7 +1,7 @@ CREATE MATERIALIZED VIEW sandbox.rs_run_to_sdssid AS -select assn.pk as assignment_pk, at.mjd, t.catalogid, c.program, c.carton, -i.label, i.default_lambda_eff, sdssid.sdss_id, +select assn.pk as assignment_pk, at.mjd, t.catalogid, c.program, c.carton, +i.label as instrument, i.default_lambda_eff, sdssid.sdss_id, obs.label as observatory, at.status as done, f.field_id from targetdb.assignment_status as at @@ -18,29 +18,18 @@ join targetdb.field as f on f.pk = d2f.field_pk join targetdb.version as v on v.pk = f.version_pk where v.plan = 'eta-9'; --- CREATE MATERIALIZED VIEW sandbox.done_to_sdssid --- AS --- select at.mjd, t.catalogid, c.program, c.carton, --- i.label, i.default_lambda_eff, sdssid.sdss_id, --- obs.label as observatory --- from targetdb.assignment_status as at --- join targetdb.assignment as assn on assn.pk = at.assignment_pk --- join targetdb.hole as hole on hole.pk = assn.hole_pk --- join targetdb.observatory as obs on obs.pk = hole.observatory_pk --- join targetdb.carton_to_target as c2t on c2t.pk = assn.carton_to_target_pk --- join targetdb.target as t on c2t.target_pk = t.pk --- join targetdb.carton as c on c.pk = c2t.carton_pk --- join targetdb.instrument as i on i.pk = assn.instrument_pk --- join catalogdb.sdss_id_flat as sdssid on sdssid.catalogid = t.catalogid --- where at.status = 1; +CREATE MATERIALIZED VIEW sandbox.carton_to_sdssid +AS +select t.catalogid, c.program, c.carton, +i.label as instrument, +i.default_lambda_eff, sdssid.sdss_id, +(select sum(n) from unnest(cad.nexp) as n) as nexp +from targetdb.carton_to_target as c2t +join targetdb.target as t on c2t.target_pk = t.pk +join targetdb.carton as c on c.pk = c2t.carton_pk +join targetdb.cadence as cad on cad.pk = c2t.cadence_pk +join targetdb.instrument as i on i.pk = c2t.instrument_pk +join catalogdb.sdss_id_flat as sdssid on sdssid.catalogid = t.catalogid +where c.version_pk >= 136; --- CREATE MATERIALIZED VIEW sandbox.carton_to_sdssid --- AS --- select t.catalogid, c.program, c.carton, --- i.label, i.default_lambda_eff, sdssid.sdss_id --- from targetdb.carton_to_target as c2t --- join targetdb.target as t on c2t.target_pk = t.pk --- join targetdb.carton as c on c.pk = c2t.carton_pk --- join targetdb.instrument as i on i.pk = c2t.instrument_pk --- join catalogdb.sdss_id_flat as sdssid on sdssid.catalogid = t.catalogid --- where c.version_pk >= 136; +-- TO DO: use Tom's targeting generation table once it's on pipelines