diff --git a/python/sdssdb/peewee/sdss5db/opsdb.py b/python/sdssdb/peewee/sdss5db/opsdb.py index fca9e657..d74e8209 100644 --- a/python/sdssdb/peewee/sdss5db/opsdb.py +++ b/python/sdssdb/peewee/sdss5db/opsdb.py @@ -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) diff --git a/python/sdssdb/sqlalchemy/sdss5db/opsdb.py b/python/sdssdb/sqlalchemy/sdss5db/opsdb.py index 5114bc83..30f9cdd5 100644 --- a/python/sdssdb/sqlalchemy/sdss5db/opsdb.py +++ b/python/sdssdb/sqlalchemy/sdss5db/opsdb.py @@ -14,6 +14,7 @@ Column, DateTime, Float, + Double, ForeignKey, Integer, SmallInteger, @@ -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') @@ -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 diff --git a/schema/sdss5db/opsdb/opsdb.sql b/schema/sdss5db/opsdb/opsdb.sql index 711faa00..2f7a9b06 100644 --- a/schema/sdss5db/opsdb/opsdb.sql +++ b/schema/sdss5db/opsdb/opsdb.sql @@ -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 @@ -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 @@ -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 ()