Skip to content

Commit

Permalink
Merge pull request #115 from Empyrean-Capstone/104_refactor-logsheet-…
Browse files Browse the repository at this point in the history
…progress

104 refactor logsheet progress
  • Loading branch information
koseward authored Apr 11, 2023
2 parents 114f757 + 46538bc commit 2af1ce2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
7 changes: 4 additions & 3 deletions api/main/file_writing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,18 @@ def __update_db_cols(headers, request_input: dict) -> dict:
"mjdobs": headers["MJDOBS"],
"filename": f"{headers['LOGID']}.fits",
"date_made_open_source": request_input["date_made_open_source"],
"status": "Complete"
# TODO: need to determine if we need these and get them
# "ccd_temp": headers["CCD-TEMP"],
# "gamma": headers[""],
# "roworder": headers["ROWORDER"],
}

cur_observation = Observation.query.filter_by(id=headers["OBSID"]).first()
cur_observation.set_attrs(cols)
cur_obs = Observation.query.filter_by(id=headers["OBSID"]).first()
cur_obs.set_attrs(cols)
db.session.commit()

sio.emit("updateObservations", get_logs_json_str([cur_observation]))
sio.emit("updateObservations", get_logs_json_str([cur_obs]))

# TODO: return error if operation fails
return headers
Expand Down
27 changes: 13 additions & 14 deletions api/main/models/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def get_logs_json_str(observations: list):
class Observation(db.Model):
"""
The python object representation of the Observation table of the database
Attributes:
-----------
airm : Float
ccd_temp: Float
date_made_open_source: date
date_obs : date
exp_time : int
exp_time : int
filename : str
gain : float
gamma : float
Expand All @@ -48,15 +48,15 @@ class Observation(db.Model):
offset : float
owner_id : int
reworder : str
Methods:
--------
get_log_dict():
Get the values of the observations in a way that the frontend can read
set_attrs():
Set values of the observation to update or instantiate an observation
"""

airm = db.Column(db.Float)
ccd_temp = db.Column(db.Float)
date_made_open_source = db.Column(db.DateTime)
Expand All @@ -77,46 +77,45 @@ class Observation(db.Model):
offset = db.Column(db.Float)
owner_id = db.Column(db.Integer)
reworder = db.Column(db.String)
status = db.Column(db.String, default="Pending")

def __init__(self, init_dict):
"""
Intialized the observation with the given devault values
Parameters:
-----------
init_diect : dict
Initial values for the attributes above
Note: not all are needed, many can be initialized initially
Note: not all are needed, many can be initialized initially
as null.
"""

self.set_attrs(init_dict)

def __iter__(self):
"""
Create an iterable list of the attributes of this object
"""

return iter([self.id, self.object, "In Progress", str(self.date_obs), "None"])

def get_log_dict(self):
"""
Returns this object with fewer attributes to be used on the frontend
TODO: Find out how to calculate a correct signal-to-noise
Returns:
--------
dict
A dictionary of the logsheet ready for representation
"""

status: str = "Pending" if self.date_obs is None else "Complete"
target: str = self.object if self.obs_type.lower() == "object" else self.obs_type.lower()

return {
self.id: {
"target": target,
"progress": status,
"progress": self.status,
"date": str(self.date_obs),
"sigToNoise": "$50",
}
Expand All @@ -126,12 +125,12 @@ def set_attrs(self, attrs: dict):
"""
Sets the attributes of the object. Can be used to update or initialize
the object.
Parameters:
-----------
attrs : dict
Of all of the attributes to be upgraded
"""

for key, val in attrs.items():
setattr(self, key.lower(), val)
18 changes: 12 additions & 6 deletions api/main/status/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from main import db
from .. import sio
from . import status
from ..models import Status, Instrument
from ..models import Instrument, Observation, Status


# FIXME: must have a way to designate the current camera
Expand Down Expand Up @@ -140,14 +140,20 @@ def update_status(instrument_id: int, update_dict: dict):
# Let the frontend know that there have been changes to the database.
sio.emit("frontend_update_status", status_rows)

obs_id_status = update_dict.get("Observation ID")

# If the camera has updated which observation it is exposing on, update
# the frontend that displays which observation is being worked on.
if update_dict.get("Observation ID") is not None:
cur_obs_id_status: dict = update_dict["Observation ID"]
cur_id: str = cur_obs_id_status["value"]
if obs_id_status is not None:
cur_id: str = obs_id_status["value"]

if type(cur_id) is int:
cur_obs = Observation.query.filter_by(id=cur_id).first()
cur_obs.set_attrs({"status": "In Progress"})
db.session.commit()

log_status: dict = {cur_id: {"progress": "In Progress"}}
sio.emit("updateObservations", json.dumps(log_status))
log_status: dict = {cur_id: {"progress": "In Progress"}}
sio.emit("updateObservations", json.dumps(log_status))


@sio.on("observation_complete")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def upgrade():
sa.Column('obs_id', sa.String(), nullable=True),
sa.Column('log_id', sa.String(), nullable=True),
sa.Column('mjdobs', sa.Float(), nullable=True),
sa.Column('status', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user',
Expand Down

0 comments on commit 2af1ce2

Please sign in to comment.