-
Notifications
You must be signed in to change notification settings - Fork 10
Implement a class version of EvoraServer
and add argument parsing
#41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
self.FILTER_DICT = {'Ha': 0, 'B': 1, 'V': 2, 'g': 3, 'r': 4, 'i': 5} | ||
self.FILTER_DICT_REVERSE = {0: 'Ha', 1: 'B', 2: 'V', 3: 'g', 4: 'r', 5: 'i'} | ||
|
||
# If we're debugging, use a local directory instead - create if doesn't exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this wasn't a change you made, but we should have this documented that using debug mode will save in a local directory. I wonder if we even need this functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are great changes that will make our code much more readable and usable. While testing locally, I found that calls were failing from the client. This may mean we need to make changes to the client as well, or we need to make some extra edits to the server (like a wrapper for each route). Will look into it. Outstanding work, thank you!
INFO:werkzeug:127.0.0.1 - - [20/Jul/2024 14:45:32] "GET /getTemperature HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Users\sebas\anaconda3\lib\site-packages\flask\app.py", line 1488, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\sebas\anaconda3\lib\site-packages\flask\app.py", line 1466, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\sebas\anaconda3\lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\sebas\anaconda3\lib\site-packages\flask\app.py", line 1463, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\sebas\anaconda3\lib\site-packages\flask\app.py", line 872, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\sebas\anaconda3\lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\sebas\anaconda3\lib\site-packages\flask\app.py", line 870, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\sebas\anaconda3\lib\site-packages\flask\app.py", line 855, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
TypeError: route_getTemperature() missing 1 required positional argument: 'self'
start_time = datetime.now() | ||
|
||
while (datetime.now() - start_time).total_seconds() < float(req["exptime"]): | ||
if ABORT_FLAG: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.
if filter not in FILTER_DICT: | ||
payload['error'] = f'Unknown filter {filter}.' | ||
return jsonify(payload) | ||
if DEBUGGING: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.DEBUGGING
|
||
date = Time.now().utc.isot.split("T")[0].replace("-", "") | ||
|
||
path = os.path.join(DEFAULT_PATH, date) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.
# ensure nothing gets overwritten | ||
num = 0 | ||
length = len(file[0:-5]) | ||
while os.path.isfile(f"{DEFAULT_PATH}/{file}"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.
file_name = ( | ||
f'{self.DEFAULT_PATH}/temp.fits' | ||
if exptype == 'Real Time' | ||
else getFilePath(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.
if self.DEBUGGING: | ||
return jsonify({'success': True, 'filter': self.FILTER_DICT_REVERSE[self.DUMMY_FILTER_POSITION], 'error': ''}) | ||
|
||
status, reply = await send_to_wheel('get') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.
|
||
global DUMMY_FILTER_POSITION | ||
status, reply = await send_to_wheel(f'move {filter_num}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.
await asyncio.sleep(2) | ||
DUMMY_FILTER_POSITION = filter_num | ||
payload['success'] = True | ||
status, reply = await send_to_wheel('home') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.
app.run(host='127.0.0.1', port=3000, debug=True, processes=1, threaded=True) | ||
# TODO: | ||
# - Add arg to download astrometry data | ||
# - Put everything into a class to make globals more pythonic to access |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo done :)
Added argument parsing using
argparse
, and to turnevora-server
into a bit of a nicer command-line application.The PEP-8 style guide generally frowns on globals (unless absolutely necessary). Since
EvoraServer
is a pretty self-contained app, I threw all our functions into a globalEvoraServer
class that we can call internal functions from. This way, functions are able to access theEvoraServer
"class variables" (i.e.self.FILTER_POSITION, self.ABORT_FLAG
, etc) without having to redeclare them as globals within every function.See the end of
app.py
for implementation.