Skip to content

Commit

Permalink
Merge branch 'main' into 103_persist-obs-form
Browse files Browse the repository at this point in the history
  • Loading branch information
mcauley-penney authored Apr 11, 2023
2 parents 9bb0c2d + 2af1ce2 commit 606ffe6
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# https://github.com/actions/setup-python
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Setup environment

name: Node Build
on:
push:
branches: [ "main", "ci-cd" ]
Expand Down
82 changes: 25 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,38 @@
# Getting Started with Create React App
# 🔭 Empyrean

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts
![Node Build](https://github.com/Empyrean-Capstone/Empyrean/actions/workflows/setup.yml/badge.svg)
</br>
</br>

In the project directory, you can run:

### `npm start`
> Thus all suspended did my mind gaze fixed,</br>
immovable, intent, ever enkindled by its</br>
gazing.</br>
&mdash; *[Paradiso, Canto XXXIII](https://archive.org/details/paradisoofdantea00dantrich/page/406/mode/2up)*

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
**Empyrean** is a web-based control system for astronomy cameras and spectrographs, designed to lower barriers to operation by abstracting away details other such tools saddle upon the astronomer. Using the Client-Server model, the aforementioned astronomical devices may connect to our application via interfaces, allowing various pairings of hardware to be controlled from the comfort of a simple reactive web UI.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`
## ⚙️ Features
- Simple and intuitive user interface using recognizable styling
- Handles multiple users
- Back-end interface allows different types of cameras and spectrographs to connect to our system

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`
## 🗺️ Roadmap
The most recent stable release can be seen in the `Releases` section on the repository's home page. Each release will contain a changelog discussing features and fixes that have been added or made since the last release. The repository abides by [semantic versioning](https://semver.org/) and each release will be of a minor or major version.

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
To see what features and fixes are planned for our next release, please
1. navigate to our [issue tracker](https://github.com/Empyrean-Capstone/Empyrean/issues)
2. click the `Milestones` dropdown
3. select the milestone whose version number immediately succeeds the version number of the last stable release

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
## 🚨 Call to Action
Join our project and provide assistance by:

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
- Solving a ticket in [our list of open issues](https://github.com/Empyrean-Capstone/Empyrean/issues).
- When creating a [pull request](https://github.com/Empyrean-Capstone/Empyrean/pulls), kindly consider the time it takes for reviewing and testing, and maintain proper coding style. Please see our documentation for discussion about our chosen methods of formatting and documenting our source code.
- Contributing feature requests by opening a new issue or [discussion](https://github.com/Empyrean-Capstone/Empyrean/discussions).
- Drawing attention to our tool by [![starring Empyrean](https://img.shields.io/github/stars/Empyrean-Capstone/Empyrean?style=social&label=starring%20Empyrean)](https://github.com/Empyrean-Capstone/Empyrean/)
7 changes: 4 additions & 3 deletions api/main/file_writing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,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)
5 changes: 3 additions & 2 deletions api/main/observations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def post_observation():

set_system_status(True)


obs_instructions: dict = request.get_json()

obs_instructions["owner_id"] = session.get("userid")
obs_instructions["observer"] = session.get("name")

# Have the spectrograph switch to the correct observation type'
# TODO: Ensure that the spectrograph has completed
sio.emit("prepare_observation", data=(obs_instructions["obs_type"], obs_instructions))

return {}
Expand Down Expand Up @@ -127,7 +127,8 @@ def conclude_exposure():
Allows the frontend to request another observation, and resets the
spectrograph to its default values to preserve its lamps.
"""


sio.emit("enable_request_form")
sio.emit("set_obs_type", data=("object"))

system_status = Status.query.filter_by(statusName="System").first()
Expand Down
21 changes: 15 additions & 6 deletions api/main/status/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def get_current_obsid() -> int:

# There is a status that every camera must have and update which is
# the id of the observation being taken
cur_camera_status = Status.query.filter_by(instrumentID=cur_camera_id, statusName="Observation ID").first()
cur_camera_status = Status.query.filter_by(
instrumentID=cur_camera_id,
statusName="Observation ID"
).first()

cur_obsid: int = int(cur_camera_status.statusValue)

Expand Down Expand Up @@ -162,14 +165,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 606ffe6

Please sign in to comment.