Skip to content

Commit

Permalink
updates from @dr-rodriguez
Browse files Browse the repository at this point in the history
  • Loading branch information
Will-Cooper committed Jul 15, 2023
1 parent 006eda9 commit 3426300
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"forwardPorts": [8000],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip install -r requirements.txt && wget -O SIMPLE.db https://raw.githubusercontent.com/SIMPLE-AstroDB/SIMPLE-binary/main/SIMPLE.db && python simple_app/app_simple.py -d"
"postCreateCommand": "pip install -r requirements.txt && wget -O SIMPLE.db https://raw.githubusercontent.com/SIMPLE-AstroDB/SIMPLE-binary/main/SIMPLE.db && python -m simple_app.app_simple -d"

// Configure tool-specific properties.
// "customizations": {},
Expand Down
8 changes: 4 additions & 4 deletions simple_app/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1 class="display-2">The SIMPLE Archive</h1>
<p class="display-6">
We are currently working on including kinematics, spectra, images, and modelled and retrieved parameters.
We are developing several different methods to interact with the database, including python,
a website and API, and database browsers.
a website and API, and database browsers.<br>
This database uses the <a href="https://docs.sqlalchemy.org/en/14/orm/index.html" target="_blank">
SQLAlchemy ORM</a> and is designed to be interacted with via the
<a href="https://pypi.org/project/astrodbkit2/" target="_blank"> astrodbkit2</a> package.
Expand All @@ -37,16 +37,16 @@ <h2 class="display-3">Getting Involved</h2>
</p>
<h3 class="display-5">Imposter syndrome disclaimer:</h3>
<p class="display-6">
We want your help. No, really.
We want your help. No, really.<br>
There may be a little voice inside your head that is telling you that you’re not ready to
be an open-source contributor; that your skills aren’t nearly good enough to contribute.
What could you possibly offer a project like this one?
We assure you - the little voice in your head is wrong.
We assure you - the little voice in your head is wrong.<br>
If you can write code at all, you can contribute code to open source.
Contributing to open-source projects is a fantastic way to advance one’s coding skills.
Writing perfect code isn’t the measure of a good developer (that would disqualify all of us!);
it’s trying to create something, making mistakes, and learning from those mistakes.
That’s how we all improve, and we are happy to help others learn.
That’s how we all improve, and we are happy to help others learn.<br>
Being an open-source contributor doesn’t just mean writing code, either.
You can help by writing documentation, tests, or even giving feedback about the project
(and yes - that includes giving feedback about the contribution process).
Expand Down
26 changes: 12 additions & 14 deletions simple_app/templates/index_simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,29 @@ <h1 class="display-2">Welcome!</h1>
<h2 class="display-3">Figures</h2>
<div class="container-fluid">
<div class="row">
<div class="p-2 col-xxl-6 float-start">
<div class="p-2 col-xxl-4">
<img src="{{ url_for('static', filename='images/color_spectra_counts.png') }}"
class="rounded img-fluid" alt="">
class="rounded img-fluid float-xxl-start" alt="">
</div>
<div class="p-2 col-xxl-6 float-end">
<div class="p-2 col-xxl-4">
<img src="{{ url_for('static', filename='images/colormag_counts.png') }}"
class="rounded img-fluid float-xxl-end" alt="">
class="rounded img-fluid mx-auto d-block" alt="">
</div>
</div>
<div class="row">
<div class="p-2 col-xxl-6 float-start">
<div class="p-2 col-xxl-4">
<img src="{{ url_for('static', filename='images/photometry_counts.png') }}"
class="rounded img-fluid" alt="">
</div>
<div class="p-2 col-xxl-6 float-end">
<img src="{{ url_for('static', filename='images/spectra_ins_counts.png') }}"
class="rounded img-fluid float-xxl-end" alt="">
</div>
</div>
<div class="row">
<div class="p-2 col-xxl-6 float-start">
<div class="p-2 col-xxl-4">
<img src="{{ url_for('static', filename='images/spectra_ins_counts.png') }}"
class="rounded img-fluid float-xxl-start" alt="">
</div>
<div class="p-2 col-xxl-4">
<img src="{{ url_for('static', filename='images/spectra_telins_counts.png') }}"
class="rounded img-fluid" alt="">
class="rounded img-fluid mx-auto d-block" alt="">
</div>
<div class="p-2 col-xxl-6 float-end">
<div class="p-2 col-xxl-4">
<img src="{{ url_for('static', filename='images/sptypes_counts.png') }}"
class="rounded img-fluid float-xxl-end" alt="">
</div>
Expand Down
36 changes: 34 additions & 2 deletions simple_app/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_results_concat(db, test_get_all_photometry, test_get_all_sources,

def test_one_df_query(db):
assert db
bad_query = 'thisisabad_query'
bad_query = 'thisisabadquery'
good_query = 'twa'
# test search object
results = db.search_object(bad_query, fmt='pandas')
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_one_df_query(db):

def test_multi_df_query(db):
assert db
bad_query = 'thisisabad_query'
bad_query = 'thisisabadquery'
good_query = 'cruz'
with pytest.raises(KeyError):
results: Optional[dict] = db.search_string(bad_query, fmt='pandas', verbose=False)
Expand All @@ -178,3 +178,35 @@ def test_multi_df_query(db):
assert 'Sources' in results_out
assert isinstance(results_out['Sources'], str)
return


def test_multi_param_str_parse():
twa_query = '174.96308 -31.989305'
empty_query = ''
hms_query = '12h34m56s \t +78d90m12s'
for query in (twa_query, empty_query, hms_query):
a, b, c = CoordQueryForm.multi_param_str_parse(query)
assert isinstance(a, str)
assert isinstance(b, str)
assert isinstance(c, float)
assert c == 10.
twa_query = '174.96308 \t -31.989305 15 '
a, b, c = CoordQueryForm.multi_param_str_parse(twa_query)
assert a == '174.96308'
assert b == '-31.989305'
assert c == 15.
return


def test_ra_dec_unit_parse():
twa_query = '174.96308 -31.989305'
a, b, c = CoordQueryForm.multi_param_str_parse(twa_query)
ra, dec, unit = CoordQueryForm.ra_dec_unit_parse(a, b)
assert isinstance(ra, float)
assert isinstance(dec, float)
assert unit == 'deg'
hms_query = '12h34m56s \t +78d90m12s'
a, b, c = CoordQueryForm.multi_param_str_parse(hms_query)
ra, dec, unit = CoordQueryForm.ra_dec_unit_parse(a, b)
assert unit == 'hourangle,deg'
return
5 changes: 2 additions & 3 deletions simple_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ def multi_param_str_parse(s: str) -> Optional[Tuple[str, str, float]]:
"""
# split up the string by empty space
try:
query_split: np.ndarray = np.array(s.replace('\t', ' ').lower().strip().split(' '))
query_split = query_split[np.logical_not(query_split == '')]
query_split = s.lower().split()
query_length = len(query_split)

# check length is 2 or 3
Expand Down Expand Up @@ -323,7 +322,7 @@ def validate_sqlfield(self, field):
field
The data within the query form
"""
forbidden = ('update', 'drop', 'truncate', 'grant', 'commit', 'create', 'replace', 'alter', 'insert')
forbidden = ('update', 'drop', 'truncate', 'grant', 'commit', 'create', 'replace', 'alter', 'insert', 'delete')
db = SimpleDB(self.db_file, connection_arguments={'check_same_thread': False}) # open database

# check query field has data within
Expand Down

0 comments on commit 3426300

Please sign in to comment.