def render_GET(self, request): net, sta, chans, time_window, time_start, time_end, availability, canvas_size = self._extract_request(request) try: # SCAFFOLD not quite right max_time_start, max_time_end = eventdata.available_range_for_stachan(sta, chans[0]) except KeyError: request.setHeader("response-code", 500) return "No data for sta %s" % sta #default time slice is the min and max: if time_start == 0 and time_end == 0: time_start, time_end = max_time_start, max_time_end response_data = {} for chan in chans: if availability: pass #get Line data else: segment = eventdata.get_segment(time_start, time_end, sta, chan, canvas_size) response_data.update({chan:segment}) request.setHeader("content-type", "application/json") response_data.update({"sta": sta, "chans":chans, "max_ts":max_time_start, "max_te":max_time_end}) response_data = json.dumps(response_data) return response_data
def render_GET(self, request): #{{{ type, net, sta, orid, chan, orid_time, time_window, time_start, time_end, availability, canvas_size, amount, filter, phases = self._extract_request(request) """ Handle different type of data request such as metadata (stations, events) and waveform data """ request.setHeader("content-type", "application/json") response_data = {} if config.verbose: log.msg("Type of query:%s " % type) if type == 'wf': """ TEST: http://localhost:8008/data?type=wf&sta=113A&orid=66554 http://localhost:8008/data?type=wf&sta=113A&orid=66554&ts=1230900154&te=1230900254&chan=BHZ http://localhost:8008/data?type=wf&sta=113A&ts=1230900154&te=1230900254 #DEBUG TOOL: #This line will output all vars as a json object: return json.dumps({"net": net, "sta": sta, "chan":chan, "orid":orid, "orid_time":orid_time, "time_window":time_window, "time_start":time_start, "time_end":time_end, "availability":availability, "canvas_size":canvas_size, "amount":amount, "filter":filter }) """ function = "Function: get_segment(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" % (str(sta), str(chan), canvas_size, orid, orid_time, time_window, time_start, time_end, amount, filter, phases) if config.debug: log.msg(function) # try: return json.dumps(eventdata.get_segment(sta, chan, canvas_size, orid, orid_time, time_window, time_start, time_end, amount, filter, phases)) # except: # request.setHeader("response-code", 500) # log.msg("\n") # log.msg("Problems on... " + function) # log.msg("\n") # return function elif type == 'coverage': """ You can test this with: http://localhost:8008/data?type=coverage - list coverage tuples of (time,end_time) for all stations and default channels or http://localhost:8008/data?type=coverage&sta=X18A&chan=BHZ - list coverage tuples of (time,end_time) for station X18A chan BHZ or http://localhost:8008/data?type=coverage&te=1230940700 - list coverage tuples of (time,end_time) until time_end or http://localhost:8008/data?type=coverage&chan=BHZ&ts=1230768001&te=1230940700 - list coverage tuples of (time,end_time) between start and end times for all BHZ chans or http://localhost:8008/data?type=coverage&sta=X18A&chan=BHZ&ts=1230768001&te=1230940700 Multiple stations/channels query... http://localhost:8008/data?type=events&sta=113A&sta=123A&chan=BHZ&chan=BHE&chan=BHN """ if config.verbose: log.msg("Query coverage. STA:%s CHAN:%s START:%s END:%s" % (str(sta),str(chan),str(time_start),str(time_end)) ) response_data = {'type':'coverage'} response_data.update({'format':'bars'}) response_data.update(eventdata.coverage(sta,chan,time_start,time_end)) return json.dumps(response_data) elif type == 'events': """ You can test this with: http://localhost:8008/data?type=events - list of events or http://localhost:8008/data?type=events&sta=127A - dict. of events recorded by station 127A or http://localhost:8008/data?type=events&orid=66484 - list of stations that recorded event 66484 or http://localhost:8008/data?type=events&sta=127A&orid=66484 - returns a floating point that is the arrival time UPDATE: Multiple stations query... http://localhost:8008/data?type=events&sta=113A&sta=123A """ if config.verbose: log.msg("Query events. STA:%s ORID:%s" % (str(sta),orid) ) return json.dumps(eventdata.event_list(sta,orid)) elif type == 'stations': """ You can test this with: http://localhost:8008/data?type=stations http://localhost:8008/data?type=stations&sta=Y12C """ return json.dumps(eventdata.available_stations(sta)) elif type == 'filters': """ You can test this with: http://localhost:8008/data?type=filters """ return json.dumps(config.filters, sort_keys=True) else: request.setHeader("response-code", 500) log.msg("ERROR in query. Unknown type:%s" % type) return "Unknown query type:(%s)" % type return 0