Skip to content

Commit

Permalink
Merge pull request #240 from birdage/fix_plotting
Browse files Browse the repository at this point in the history
fix ui services
  • Loading branch information
oceanzus committed Feb 25, 2015
2 parents 56c166a + cdfeb01 commit e2f9a46
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
25 changes: 15 additions & 10 deletions ooiservices/app/uframe/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.')
Expand All @@ -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.')
Expand Down Expand Up @@ -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()
Expand Down
29 changes: 13 additions & 16 deletions ooiservices/app/uframe/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)}
Expand All @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion ooiservices/app/uframe/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e2f9a46

Please sign in to comment.