Skip to content

Commit

Permalink
model classes for CartonToSdssID and RSRunRoSdssID
Browse files Browse the repository at this point in the history
  • Loading branch information
johndonor3 committed Sep 18, 2024
1 parent ac639d7 commit 1cf97d7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 27 deletions.
44 changes: 44 additions & 0 deletions python/sdssdb/peewee/sdss5db/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
43 changes: 16 additions & 27 deletions schema/sdss5db/targetdb/load_table/metrics/created_views.sql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit 1cf97d7

Please sign in to comment.