Skip to content

Commit

Permalink
Pred boss snr (#271)
Browse files Browse the repository at this point in the history
* first attempt to add opsdb.pred_snr table for robodamus

* revise pred_snr table

* add pred_snr_par table, remove tz from timestamp

* add two new firelds to opsdb.pred_snr

* tweak pred_snr columns

* remove surplus comma

---------

Co-authored-by: Tom Dwelly <[email protected]>
  • Loading branch information
johndonor3 and tdwelly authored Sep 23, 2024
1 parent 1897d8f commit b56353a
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 1 deletion.
37 changes: 37 additions & 0 deletions python/sdssdb/peewee/sdss5db/opsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,41 @@ class Meta:
table_name = 'overhead'


class PredSnr(OpsdbBase):
pk = AutoField()
robodamus_version = TextField()
model_id = TextField()
pred_time = DateTimeField()
camera_pk = ForeignKeyField(Camera,
column_name='camera_pk',
field='pk')
design_mode_label = ForeignKeyField(column_name='design_mode_label',
field='label',
model=targetdb.DesignMode)
pred_type = TextField()
pred_value = FloatField()
pred_flag = IntegerField()
num_gfas = IntegerField()
gfa_expid = IntegerField()
gfa_date_obs = DateTimeField()

class Meta:
table_name = 'pred_snr'


class PredSnrPar(OpsdbBase):
pk = AutoField()
pred_snr_pk = ForeignKeyField(PredSnr,
column_name='pred_snr_pk',
field='pk')
label = TextField()
datatype = TextField()
value_f = DoubleField()
value_i = IntegerField()
value_s = TextField()

class Meta:
table_name = 'pred_snr_par'


FieldToPriorityDeferred.set_model(FieldToPriority)
37 changes: 36 additions & 1 deletion python/sdssdb/sqlalchemy/sdss5db/opsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Column,
DateTime,
Float,
Double,
ForeignKey,
Integer,
SmallInteger,
Expand Down Expand Up @@ -149,7 +150,7 @@ class AssignmentToFocal(Base):
fiber_type = Column(Text)
assigned = Column(Boolean)
collided = Column(Boolean)
replaced = Column(Boolean)
replaced = Column(Boolean)

configuration = relationship('Configuration')

Expand Down Expand Up @@ -237,6 +238,40 @@ class Overhead(Base):
configuration = relationship('Configuration')


class PredSnr(Base):
__tablename__ = 'pred_snr'

pk = Column(Integer, primary_key=True, server_default=text(f"nextval('{Base._schema}.pred_snr_pk_seq'::regclass)"))
robodamus_version = Column(Text, index=True)
model_id = Column(Text, index=True)
pred_time = Column(DateTime, index=True)
camera_pk = Column(ForeignKey(f'{Base._schema}.camera.pk'), index=True)
design_mode_label = Column(ForeignKey('targetdb.design_mode.label'), index=True)
pred_type = Column(Text, index=True)
pred_value = Column(Float)
pred_flag = Column(Integer)
num_gfas = Column(Integer)
gfa_expid = Column(Integer)
gfa_date_obs = Column(DateTime, index=True)

camera = relationship('Camera')
design_mode = relationship('DesignMode')


class PredSnrPar(Base):
__tablename__ = 'pred_snr_par'

pk = Column(Integer, primary_key=True, server_default=text(f"nextval('{Base._schema}.pred_snr_par_pk_seq'::regclass)"))
pred_snr_pk = Column(ForeignKey(f'{Base._schema}.pred_snr.pk'), index=True)
label = Column(Text, index=True)
datatype = Column(Text)
value_f = Column(Double)
value_i = Column(BigInteger)
value_s = Column(Text)

pred_snr = relationship('PredSnr')


def define_relations():
""" leaving this empty as relations were autogenerated """
pass
Expand Down
72 changes: 72 additions & 0 deletions schema/sdss5db/opsdb/opsdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,29 @@ CREATE TABLE opsdb.overhead(
elapsed REAL,
success BOOLEAN);

CREATE TABLE opsdb.pred_snr (
pk SERIAL PRIMARY KEY NOT NULL,
robodamus_version TEXT,
model_id TEXT,
pred_time TIMESTAMP,
camera_pk SMALLINT,
design_mode_label TEXT,
pred_type TEXT,
pred_value REAL,
pred_flag INTEGER,
num_gfas INTEGER,
gfa_expid INTEGER,
gfa_date_obs TIMESTAMP);

CREATE TABLE opsdb.pred_snr_par (
pk SERIAL PRIMARY KEY NOT NULL,
pred_snr_pk BIGINT,
label TEXT,
datatype TEXT,
value_f DOUBLE PRECISION,
value_i BIGINT,
value_s TEXT);

-- Foreign keys

ALTER TABLE ONLY opsdb.base_priority
Expand Down Expand Up @@ -238,6 +261,19 @@ ALTER TABLE ONLY opsdb.overhead
ON UPDATE CASCADE ON DELETE CASCADE
DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY opsdb.pred_snr
ADD CONSTRAINT camera_fk
FOREIGN KEY (camera_pk) REFERENCES opsdb.camera(pk);

ALTER TABLE ONLY opsdb.pred_snr
ADD CONSTRAINT design_mode_fk
FOREIGN KEY (design_mode_label) REFERENCES targetdb.design_mode(label);

ALTER TABLE ONLY opsdb.pred_snr_par
ADD CONSTRAINT pred_snr_fk
FOREIGN KEY (pred_snr_pk) REFERENCES opsdb.pred_snr(pk);


-- Table data

INSERT INTO opsdb.exposure_flavor VALUES
Expand Down Expand Up @@ -294,6 +330,42 @@ CREATE INDEX CONCURRENTLY overhead_configuration_id_idx
ON opsdb.overhead
USING BTREE(configuration_id);

CREATE INDEX CONCURRENTLY pred_snr_camera_pk_idx
ON opsdb.pred_snr
USING BTREE(camera_pk);

CREATE INDEX CONCURRENTLY pred_snr_design_mode_label_idx
ON opsdb.pred_snr
USING BTREE(design_mode_label);

CREATE INDEX CONCURRENTLY pred_snr_pred_time_idx
ON opsdb.pred_snr
USING BTREE(pred_time);

CREATE INDEX CONCURRENTLY pred_snr_pred_type_idx
ON opsdb.pred_snr
USING BTREE(pred_type);

CREATE INDEX CONCURRENTLY pred_snr_gfa_date_obs_idx
ON opsdb.pred_snr
USING BTREE(gfa_date_obs);

CREATE INDEX CONCURRENTLY pred_snr_model_id_idx
ON opsdb.pred_snr
USING BTREE(model_id);

CREATE INDEX CONCURRENTLY pred_snr_robodamus_version_idx
ON opsdb.pred_snr
USING BTREE(robodamus_version);

CREATE INDEX CONCURRENTLY pred_snr_par_pred_snr_pk_idx
ON opsdb.pred_snr_par
USING BTREE(pred_snr_pk);

CREATE INDEX CONCURRENTLY pred_snr_label_idx
ON opsdb.pred_snr_par
USING BTREE(label);

-- pop function to retrieve next in queue and increment

CREATE FUNCTION opsdb.popQueue ()
Expand Down

0 comments on commit b56353a

Please sign in to comment.