Implement a class version of EvoraServer and add argument parsing#41
Open
Pixadus wants to merge 4 commits intoUWMRO:mainfrom
Open
Implement a class version of EvoraServer and add argument parsing#41Pixadus wants to merge 4 commits intoUWMRO:mainfrom
EvoraServer and add argument parsing#41Pixadus wants to merge 4 commits intoUWMRO:mainfrom
Conversation
seb-cap
reviewed
Jul 20, 2024
| 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 |
Member
There was a problem hiding this comment.
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?
seb-cap
requested changes
Jul 20, 2024
Member
seb-cap
left a comment
There was a problem hiding this comment.
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: |
| if filter not in FILTER_DICT: | ||
| payload['error'] = f'Unknown filter {filter}.' | ||
| return jsonify(payload) | ||
| if DEBUGGING: |
|
|
||
| date = Time.now().utc.isot.split("T")[0].replace("-", "") | ||
|
|
||
| path = os.path.join(DEFAULT_PATH, date) |
| # ensure nothing gets overwritten | ||
| num = 0 | ||
| length = len(file[0:-5]) | ||
| while os.path.isfile(f"{DEFAULT_PATH}/{file}"): |
| file_name = ( | ||
| f'{self.DEFAULT_PATH}/temp.fits' | ||
| if exptype == 'Real Time' | ||
| else getFilePath(None) |
| if self.DEBUGGING: | ||
| return jsonify({'success': True, 'filter': self.FILTER_DICT_REVERSE[self.DUMMY_FILTER_POSITION], 'error': ''}) | ||
|
|
||
| status, reply = await send_to_wheel('get') |
| return jsonify(payload) | ||
|
|
||
| global DUMMY_FILTER_POSITION | ||
| status, reply = await send_to_wheel(f'move {filter_num}') |
| await asyncio.sleep(2) | ||
| DUMMY_FILTER_POSITION = filter_num | ||
| payload['success'] = True | ||
| status, reply = await send_to_wheel('home') |
| 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 No newline at end of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added argument parsing using
argparse, and to turnevora-serverinto a bit of a nicer command-line application.The PEP-8 style guide generally frowns on globals (unless absolutely necessary). Since
EvoraServeris a pretty self-contained app, I threw all our functions into a globalEvoraServerclass 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.pyfor implementation.