Commit 8f9d93df authored by Guillaume Mella's avatar Guillaume Mella

handle sinpe

parent 87983018
......@@ -81,7 +81,7 @@ class StarInfo(Base):
'BIBCODE': { 'field': 'bibcode', 'must': True, 'check': 'check_bibcode', 'alternate': 'REFERENCE'},
'COM': { 'field': 'com', 'must': False, 'alternate': 'REFERENCE'},
'REFERENCE': { 'must': False, 'parse': 'parse_reference' },
'UNKNOW_BY_SIMBAD': {'field': 'unknown_by_simbad', 'must': False},
'SINPE': {'field': 'sinpe', 'must': False, 'check': 'check_bool', 'parse': 'parse_sinpe'}, # SIMBAD Id Not Precise Enough
},
'checks': [
# here we should have names of methods to call that check object coherency
......@@ -131,7 +131,7 @@ class StarInfo(Base):
notes = Column(String(255))
bibcode = Column(String(19))
com = Column(String(255))
unknown_by_simbad = Column(Boolean)
sinpe = Column(Boolean)
star_info_entry = relationship('StarInfoEntry', back_populates='star_info')
submission = association_proxy('star_info_entry', 'submission')
......@@ -258,7 +258,7 @@ class StarInfo(Base):
# print("setting value '%s' to object variable '%s'"%(str(value), field_name))
setattr(self, field_name, value)
def check_star(self, field_name, field_info, value, accept_empty_value=False):
def check_star(self, field_name, field_info, value, accept_empty_value=False, accept_invalid_star_id=False):
# print("Checking star '%s' for field '%s'"%(value, field_name))
if not value:
if not accept_empty_value :
......@@ -267,7 +267,10 @@ class StarInfo(Base):
try:
star = self.query_starname(value)
except StarDoesNotExist:
self.append_error(field_name, "invalid star identifier '%s'"%(value))
if accept_invalid_star_id:
self.append_warning(field_name, "invalid star identifier '%s'"%(value))
else:
self.append_error(field_name, "invalid star identifier '%s'" % (value))
else:
print("found star for field '%s' :"%(field_name), star, star.id)
field_var = field_info.get('field', None)
......@@ -276,7 +279,7 @@ class StarInfo(Base):
self.set_field_value(field_var, value)
def check_star2(self, field_name, field_info, value):
self.check_star(field_name, field_info, value, True)
self.check_star(field_name, field_info, value, True, self.sinpe)
def check_float(self, field_name, field_info, value):
......@@ -293,6 +296,21 @@ class StarInfo(Base):
if field_var:
self.set_field_value(field_var, value)
def check_bool(self, field_name, field_info, value):
if isinstance(value, str):
if not value:
value = None
else:
try:
value = value.lower() in ("true", "t", "1")
except ValueError:
self.append_error(field_name, "invalid value '%s'"%(value))
return
field_var = field_info.get('field', None)
if field_var:
self.set_field_value(field_var, value)
def check_band(self, field_name, field_info, value):
field_var = field_info.get('field', None)
if field_var:
......@@ -401,6 +419,10 @@ class StarInfo(Base):
if comment:
self.set_field_value('com', comment)
# force parsing before checking since starname check depends on this field
def parse_sinpe(self, field_name, field_info, value):
self.check_bool(field_name, field_info, value)
#
# object level checks
#
......@@ -474,9 +496,6 @@ class StarInfo(Base):
elif bc:
self.append_error('band', 'calculated band_code invalid \'%s\''%(repr(bc)))
def check_unknown_by_simbad(self, field_name, field_info, value):
pass
#
# header parsing function
#
......
......@@ -17,7 +17,7 @@
<th>notes</th>
<th>bibcode</th>
<th>com</th>
<th>unknown_in_simbad</th>
<th>sinpe</th>
</tr>
</thead>
<tbody>
......@@ -36,7 +36,7 @@
<td>{{star.notes or '' }}</td>
<td>{{star.bibcode or '' }}</td>
<td>{{star.com or '' }}</td>
<td>{{star.unknown_by_simbad or '' }}</td>
<td>{{star.sinpe or '' }}</td>
</tr>
{% endif %}
{% endfor %}
......
id1,id2,ud_diam,ld_diam,e_ld_diam,band,mu_lambda,method,band_code,notes,bibcode,com{% for star in stars %}{% if star.star_info_entry.0.validated%}{{star.id1 or ''}},{{star.id2 or ''}},{{star.ud_diam or ''}},{{star.ld_diam or ''}},{{star.e_ld_diam or ''}},{{star.band or ''}},{{star.mu_lambda or ''}},{{star.method or ''}},{{star.band_code or ''}},"{{star.notes or ''}}",{{star.bibcode or ''}},"{{star.com or ''}}"{% endif %}
id1,id2,ud_diam,ld_diam,e_ld_diam,band,mu_lambda,method,band_code,notes,bibcode,com{% for star in stars %}{% if star.star_info_entry.0.validated%}{{star.id1 or ''}},{{star.id2 or ''}},{{star.ud_diam or ''}},{{star.ld_diam or ''}},{{star.e_ld_diam or ''}},{{star.band or ''}},{{star.mu_lambda or ''}},{{star.method or ''}},{{star.band_code or ''}},"{{star.notes or ''}}",{{star.bibcode or ''}},"{{star.com or ''}}","{{star.sinpe or ''}}"{% endif %}
{% endfor %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment