diff --git a/ooiservices/app/uframe/controller.py b/ooiservices/app/uframe/controller.py index bcfd8954..61e4259c 100644 --- a/ooiservices/app/uframe/controller.py +++ b/ooiservices/app/uframe/controller.py @@ -101,7 +101,6 @@ def dict_from_stream(mooring, platform, instrument, stream_type, stream): if response.status_code != 200: raise IOError("Failed to get stream contents from uFrame") data = response.json() - print data[0] data_dict = {} preferred = data[0][u'preferred_timestamp'] data_dict['start'] = data[0]['pk']['time'] - COSMO_CONSTANT @@ -251,7 +250,8 @@ def get_uframe_stream_contents(mooring, platform, instrument, stream_type, strea UFRAME_DATA = current_app.config['UFRAME_URL'] + current_app.config['UFRAME_URL_BASE'] response = requests.get("/".join([UFRAME_DATA,mooring, platform, instrument, stream_type, stream])) if response.status_code != 200: - print response.text + #print response.text + pass return response except: return internal_server_error('uframe connection cannot be made.') @@ -261,14 +261,14 @@ def get_uframe_stream_contents_bounded(mooring, platform, instrument, stream_typ ''' Gets the bounded stream contents, start_time and end_time need to be datetime objects ''' - try: - start_str = start_time.isoformat() + 'Z' - end_str = end_time.isoformat() + 'Z' - query = '?beginDT=%s&endDT=%s' % (start_str, end_str) + try: + query = '?beginDT=%s&endDT=%s' % (start_time, end_time) UFRAME_DATA = current_app.config['UFRAME_URL'] + current_app.config['UFRAME_URL_BASE'] - response = requests.get("/".join([UFRAME_DATA,mooring, platform, instrument, stream_type, stream + query])) + url = "/".join([UFRAME_DATA,mooring, platform, instrument, stream_type, stream + query]) + response = requests.get(url) if response.status_code != 200: - print response.text + #print response.text + pass return response except: return internal_server_error('uframe connection cannot be made.') @@ -446,9 +446,14 @@ def get_profile_data(instrument,stream): #instrument = instrument.replace('-','/',2) #url = current_app.config['UFRAME_URL'] + current_app.config['UFRAME_URL_BASE'] +'/' + instrument+ "/telemetered/"+stream + "/" + dt_bounds #response = requests.get(url) - mooring, platform, instrument, stream_type, stream = split_stream_name('_'.join([instrument, stream])) - response = get_uframe_stream_contents(mooring, platform, instrument, stream_type, stream) + if 'startdate' in request.args and 'enddate' in request.args: + st_date = request.args['startdate'] + ed_date = request.args['enddate'] + response = get_uframe_stream_contents_bounded(mooring, platform, instrument, stream_type, stream,st_date,ed_date) + else: + response = get_uframe_stream_contents(mooring, platform, instrument, stream_type, stream) + if response.status_code != 200: raise IOError("Failed to get data from uFrame") data = response.json() diff --git a/ooiservices/app/uframe/data.py b/ooiservices/app/uframe/data.py index 33eb78b8..22dd9726 100644 --- a/ooiservices/app/uframe/data.py +++ b/ooiservices/app/uframe/data.py @@ -24,7 +24,7 @@ COSMO_CONSTANT = 2208988800 def get_data(stream, instrument,yfield,xfield,include_time=False): - from ooiservices.app.uframe.controller import split_stream_name, get_uframe_stream_contents + from ooiservices.app.uframe.controller import split_stream_name, get_uframe_stream_contents,get_uframe_stream_contents_bounded #get data from uframe #------------------- # m@c: 02/01/2015 @@ -34,11 +34,19 @@ def get_data(stream, instrument,yfield,xfield,include_time=False): #------------------- #TODO: create better error handler if uframe is not online/responding data = [] - #dt_bounds = '?beginDT=2014-05-03T12:12:12.000Z&endDT=2014-05-03T23:12:12.000Z' + + mooring, platform, instrument, stream_type, stream = split_stream_name('_'.join([instrument, stream])) + try: - mooring, platform, instrument, stream_type, stream = split_stream_name('_'.join([instrument, stream])) - response = get_uframe_stream_contents(mooring, platform, instrument, stream_type, stream) - data = response.json() + + if 'startdate' in request.args and 'enddate' in request.args: + st_date = request.args['startdate'] + ed_date = request.args['enddate'] + response = get_uframe_stream_contents_bounded(mooring, platform, instrument, stream_type, stream,st_date,ed_date) + data = response.json() + else: + response = get_uframe_stream_contents(mooring, platform, instrument, stream_type, stream) + data = response.json() except Exception,e: current_app.logger.exception('Failed to make plot') return {'error':'uframe connection cannot be made:'+str(e)} @@ -65,17 +73,6 @@ def get_data(stream, instrument,yfield,xfield,include_time=False): if yfield not in data[0]: return {'error':'requested data yfield not available'} - hasStartDate = False - hasEndDate = False - - if 'startdate' in request.args: - st_date = datetime.datetime.strptime(request.args['startdate'], "%Y-%m-%d %H:%M:%S") - hasStartDate = True - - if 'enddate' in request.args: - ed_date = datetime.datetime.strptime(request.args['enddate'], "%Y-%m-%d %H:%M:%S") - hasEndDate = True - #override the timestamp to the prefered x = [] y = [] diff --git a/ooiservices/app/uframe/plotting.py b/ooiservices/app/uframe/plotting.py index 18ea1511..dcf9328d 100644 --- a/ooiservices/app/uframe/plotting.py +++ b/ooiservices/app/uframe/plotting.py @@ -37,7 +37,7 @@ def generate_plot(data,plot_format,plot_layout,use_line,use_scatter,plot_profile kwargs = dict(linewidth=1.0,alpha=0.7) is_timeseries = False - if "time" == data['x']: + if "time" == data['x_field']: data['x'] = num2date(data['x'], units='seconds since 1900-01-01 00:00:00', calendar='gregorian') is_timeseries = True