def packet_synopsis(url_encoded_ivorn=None): """ Result: Nested dict providing key details, e.g.:: {"coords": [ { "dec": 10.9712, "error": 0.05, "ra": 233.7307, "time": "2015-10-01T15:04:22.930000+00:00" }, ... ], "refs": [ { "cite_type": u"followup", "description": "This is the XRT Position ...", "ref_ivorn": "ivo://nasa.gsfc.gcn/SWIFT#BAT_..." }, ... ], "voevent": { "author_datetime": "2015-10-01T15:04:46+00:00", "author_ivorn": "ivo://nasa.gsfc.tan/gcn", "ivorn": "ivo://nasa.gsfc.gcn/SWIFT#BAT_GRB_Pos_657286-112", "received": "2015-11-19T20:41:38.226431+00:00", "role": "observation", "stream": "nasa.gsfc.gcn/SWIFT", "version": "2.0" } "relevant_urls": [ "http://address1.foo.bar", "http://address2.foo.bar" ] } Returns some key details for the packet specified by IVORN. The required IVORN should be appended to the URL after ``/synopsis/`` in :ref:`URL-encoded <url-encoding>` form. """ ivorn = validate_ivorn(url_encoded_ivorn) voevent_row = db_session.query(Voevent).filter(Voevent.ivorn == ivorn).one() cites = db_session.query(Cite).filter(Cite.voevent_id == voevent_row.id).all() coords = db_session.query(Coord).filter(Coord.voevent_id == voevent_row.id).all() v_dict = voevent_row.to_odict(exclude=("id", "xml")) cite_list = [c.to_odict(exclude=("id", "voevent_id")) for c in cites] coord_list = [c.to_odict(exclude=("id", "voevent_id")) for c in coords] relevant_urls = lookup_relevant_urls(voevent_row, cites) result = {"voevent": v_dict, "refs": cite_list, "coords": coord_list, "relevant_urls": relevant_urls} return jsonify(make_response_dict(result))
def packet_xml(url_encoded_ivorn=None): """ Returns the XML packet contents stored for a given IVORN. The required IVORN should be appended to the URL after ``/xml/`` in :ref:`URL-encoded <url-encoding>` form. """ # Handle Apache / Debug server difference... # Apache conf must include the setting:: # AllowEncodedSlashes NoDecode # otherwise urlencoded paths have # double-slashes ('//') replaced with single-slashes ('/'). # However, the werkzeug simple-server decodes these by default, # resulting in differing dev / production behaviour, which we handle here. ivorn = validate_ivorn(url_encoded_ivorn) xml = db_session.query(Voevent.xml).filter(Voevent.ivorn == ivorn).scalar() r = make_response(xml) r.mimetype = 'text/xml' return r
def packet_xml(url_encoded_ivorn=None): """ Returns the XML packet contents stored for a given IVORN. The required IVORN should be appended to the URL after ``/xml/`` in :ref:`URL-encoded <url-encoding>` form. """ # Handle Apache / Debug server difference... # Apache conf must include the setting:: # AllowEncodedSlashes NoDecode # otherwise urlencoded paths have # double-slashes ('//') replaced with single-slashes ('/'). # However, the werkzeug simple-server decodes these by default, # resulting in differing dev / production behaviour, which we handle here. ivorn = validate_ivorn(url_encoded_ivorn) xml = db_session.query(Voevent.xml).filter(Voevent.ivorn == ivorn).scalar() r = make_response(xml) r.mimetype = "text/xml" return r
def packet_synopsis(url_encoded_ivorn=None): """ Result: Nested dict providing key details, e.g.:: {"coords": [ { "dec": 10.9712, "error": 0.05, "ra": 233.7307, "time": "2015-10-01T15:04:22.930000+00:00" }, ... ], "refs": [ { "cite_type": u"followup", "description": "This is the XRT Position ...", "ref_ivorn": "ivo://nasa.gsfc.gcn/SWIFT#BAT_..." }, ... ], "voevent": { "author_datetime": "2015-10-01T15:04:46+00:00", "author_ivorn": "ivo://nasa.gsfc.tan/gcn", "ivorn": "ivo://nasa.gsfc.gcn/SWIFT#BAT_GRB_Pos_657286-112", "received": "2015-11-19T20:41:38.226431+00:00", "role": "observation", "stream": "nasa.gsfc.gcn/SWIFT", "version": "2.0" } "relevant_urls": [ "http://address1.foo.bar", "http://address2.foo.bar" ] } Returns some key details for the packet specified by IVORN. The required IVORN should be appended to the URL after ``/synopsis/`` in :ref:`URL-encoded <url-encoding>` form. """ ivorn = validate_ivorn(url_encoded_ivorn) voevent_row = db_session.query(Voevent).filter( Voevent.ivorn == ivorn).one() cites = db_session.query(Cite). \ filter(Cite.voevent_id == voevent_row.id).all() coords = db_session.query(Coord). \ filter(Coord.voevent_id == voevent_row.id).all() v_dict = voevent_row.to_odict(exclude=('id', 'xml')) cite_list = [c.to_odict(exclude=('id', 'voevent_id')) for c in cites] coord_list = [c.to_odict(exclude=('id', 'voevent_id')) for c in coords] relevant_urls = lookup_relevant_urls(voevent_row, cites) result = { 'voevent': v_dict, 'refs': cite_list, 'coords': coord_list, 'relevant_urls': relevant_urls, } return jsonify(make_response_dict(result))
def get_query(self): return db_session.query(Voevent.ivorn)