From 1754789b5ec4440eaab15ce21bba967d1cafb186 Mon Sep 17 00:00:00 2001 From: Goutte Date: Mon, 17 Jul 2017 08:58:15 +0200 Subject: [PATCH] Decorate and clean up the start/stop inputs. --- web/run.py | 135 +++++++++++++++++++-------------------------------------------------------------------------------------------------------------------- web/static/js/swapp.js | 7 ++++++- web/static/js/swapp.ls | 4 ++++ web/view/home.html.jinja2 | 22 +++++++++++++++++++--- 4 files changed, 48 insertions(+), 120 deletions(-) diff --git a/web/run.py b/web/run.py index f9a4402..fa456bf 100755 --- a/web/run.py +++ b/web/run.py @@ -339,12 +339,6 @@ def get_target_csv(source, started_at, stopped_at): except: abort(400, "Invalid stopped_at parameter : '%s'." % stopped_at) - # todo: iterate on models when there are many - try: - model_slug = source_config['models'][0]['slug'] - except: - abort(500, "Invalid model configuration for '%s'." % source) - filename = "%s_%s_%s.csv" % (source, started_at.strftime(date_fmt), stopped_at.strftime(date_fmt)) @@ -362,125 +356,34 @@ def get_target_csv(source, started_at, stopped_at): return send_from_directory(get_path("../cache/"), filename) -# @app.route("//data.csv") -# def get_orbiter_csv(source): +# DEV TOOLS ################################################################### + +# @app.route("/inspect") +# def analyze_cdf(): # """ -# DEPRECATED -# Grab data and orbit data for the specified `source`, -# rearrange it and return it as a CSV file. +# For debug purposes. # """ -# # http://cdpp1.cesr.fr/BASE/DDService/getDataUrl.php?dataSet=tao_ros_sw&StartTime=2014-02-23T10:00&StopTime=2016-02-24T23:59 -# # Process input parameters -# source_config = get_source_config(source) -# date_fmt = "%Y-%m-%dT%H:%M:%S" -# started_at = request.args.get('started_at') -# try: -# started_at = datetime.datetime.strptime(started_at, date_fmt) -# except: -# abort(400, "Invalid started_at parameter : '%s'." % started_at) -# stopped_at = request.args.get('stopped_at') -# try: -# stopped_at = datetime.datetime.strptime(stopped_at, date_fmt) -# except: -# abort(400, "Invalid stopped_at parameter : '%s'." % stopped_at) -# -# # todo: iterate on models when there are many -# try: -# model_slug = source_config['models'][0]['slug'] -# except: -# abort(500, "Invalid model configuration for '%s'." % source) -# -# # Grab the list of netCDF files from Myriam's API -# # http://cdpp.irap.omp.eu/BASE/DDService/getDataUrl.php?dataSet=jupiter_orb_all&StartTime=2014-02-23T10:00:10&StopTime=2017-02-24T23:59:00 -# # http://cdpp.irap.omp.eu/BASE/DATA/TAO/JUPITER/SW/sw_2014.nc.gz -# model_files = retrieve_data(source, model_slug, started_at, stopped_at) -# orbits_files = retrieve_data(source, source_config['orbit']['model'], started_at, stopped_at) +# cdf_to_inspect = get_path("../res/dummy.nc") +# cdf_to_inspect = get_path("../res/dummy_jupiter_coordinates.nc") # # si = StringIO.StringIO() -# cw = csv_writer(si) -# cw.writerow(( # the order matters ! -# 'time', -# 'vrad', 'vtan', 'vlen', -# 'magn', 'temp', 'pdyn', 'dens', 'angl', -# 'xhci', 'yhci' -# )) -# -# precision = "%Y-%m-%dT%H" # model and orbits times are equal-ish -# orbits_data = {} # keys are datetime as str, values arrays of XY -# for orbits_file in orbits_files: -# cdf_handle = Dataset(orbits_file, "r", format="NETCDF4") -# times = cdf_handle.variables['Time'] # YYYY DOY HH MM SS .ms -# data_hci = cdf_handle.variables['HCI'] -# for time, datum_hci in zip(times, data_hci): -# dtime = datetime_from_list(time) -# if started_at <= dtime <= stopped_at: -# dkey = dtime.strftime(precision) -# orbits_data[dkey] = datum_hci -# all_data = {} # keys are datetime as str, values tuples of data -# for model_file in model_files: -# # Time, StartTime, StopTime, V, B, N, T, Delta_angle, P_dyn -# cdf_handle = Dataset(model_file, "r", format="NETCDF4") -# times = cdf_handle.variables['Time'] # YYYY DOY HH MM SS .ms -# data_v = cdf_handle.variables['V'] -# data_b = cdf_handle.variables['B'] -# data_t = cdf_handle.variables['T'] -# data_n = cdf_handle.variables['N'] -# data_p = cdf_handle.variables['P_dyn'] -# data_d = cdf_handle.variables['Delta_angle'] -# for time, datum_v, datum_b, datum_t, datum_p, datum_n, datum_d \ -# in zip(times, data_v, data_b, data_t, data_n, data_p, data_d): -# vrad = datum_v[0] -# vtan = datum_v[1] -# dtime = datetime_from_list(time) -# if started_at <= dtime <= stopped_at: -# dkey = dtime.strftime(precision) -# x_hci = None -# y_hci = None -# if dkey in orbits_data: -# x_hci = orbits_data[dkey][0] -# y_hci = orbits_data[dkey][1] -# all_data[dkey] = ( -# dtime.strftime("%Y-%m-%dT%H:%M:%S+00:00"), -# vrad, vtan, sqrt(vrad * vrad + vtan * vtan), -# datum_b, datum_t, datum_n, datum_p, datum_d, -# x_hci, y_hci -# ) -# cdf_handle.close() +# cw = csv.DictWriter(si, fieldnames=['Name', 'Shape', 'Length']) +# cw.writeheader() # -# for dkey in sorted(all_data): -# cw.writerow(all_data[dkey]) +# # Time, StartTime, StopTime, V, B, N, T, Delta_angle, P_dyn, QualityFlag +# cdf_handle = Dataset(cdf_to_inspect, "r", format="NETCDF4") +# for variable in cdf_handle.variables: +# v = cdf_handle.variables[variable] +# cw.writerow({ +# 'Name': variable, +# 'Shape': v.shape, +# 'Length': v.size, +# }) +# cdf_handle.close() # # return si.getvalue() -# DEV TOOLS ################################################################### - -@app.route("/inspect") -def analyze_cdf(): - """ - For debug purposes. - """ - cdf_to_inspect = get_path("../res/dummy.nc") - cdf_to_inspect = get_path("../res/dummy_jupiter_coordinates.nc") - - si = StringIO.StringIO() - cw = csv.DictWriter(si, fieldnames=['Name', 'Shape', 'Length']) - cw.writeheader() - - # Time, StartTime, StopTime, V, B, N, T, Delta_angle, P_dyn, QualityFlag - cdf_handle = Dataset(cdf_to_inspect, "r", format="NETCDF4") - for variable in cdf_handle.variables: - v = cdf_handle.variables[variable] - cw.writerow({ - 'Name': variable, - 'Shape': v.shape, - 'Length': v.size, - }) - cdf_handle.close() - - return si.getvalue() - - # MAIN ######################################################################## if __name__ == "__main__": diff --git a/web/static/js/swapp.js b/web/static/js/swapp.js index 1ba8270..5afde1a 100644 --- a/web/static/js/swapp.js +++ b/web/static/js/swapp.js @@ -258,7 +258,7 @@ return [this.started_at, this.stopped_at]; }; SpaceWeather.prototype.resizeDomain = function(started_at, stopped_at){ - var ref$, formatted_started_at, formatted_stopped_at; + var ref$, max_stopped_at, formatted_started_at, formatted_stopped_at; if (stopped_at < started_at) { ref$ = [stopped_at, started_at], started_at = ref$[0], stopped_at = ref$[1]; } @@ -266,6 +266,11 @@ console.warn("Please provide distinct start and stop dates."); return; } + max_stopped_at = started_at.clone().add(2, 'years'); + if (stopped_at > max_stopped_at) { + console.warn("The time interval was truncated beacuse it was bigger than two years."); + stopped_at = max_stopped_at; + } this.setStartAndStop(started_at, stopped_at); formatted_started_at = started_at.format(); formatted_stopped_at = stopped_at.format(); diff --git a/web/static/js/swapp.ls b/web/static/js/swapp.ls index 9ff96f3..8b27397 100644 --- a/web/static/js/swapp.ls +++ b/web/static/js/swapp.ls @@ -227,6 +227,10 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE if started_at == stopped_at console.warn "Please provide distinct start and stop dates." return + max_stopped_at = started_at.clone().add(2, 'years') + if stopped_at > max_stopped_at + console.warn "The time interval was truncated beacuse it was bigger than two years." + stopped_at = max_stopped_at @setStartAndStop(started_at, stopped_at) formatted_started_at = started_at.format() diff --git a/web/view/home.html.jinja2 b/web/view/home.html.jinja2 index 0095429..837f123 100755 --- a/web/view/home.html.jinja2 +++ b/web/view/home.html.jinja2 @@ -31,9 +31,16 @@
Time Interval - - - +
+
+ + +
+ +
+ +
+
Planets @@ -250,6 +257,15 @@ stroke-width: 1px; stroke-dasharray: 5px; } + #form_time_interval { + padding-left: 30px; + } + #form_time_interval .mdl-textfield { + padding-top: 0; + } + #started_at, #stopped_at { + width: 85%; + } .targets-filters { padding-left: 17px; } -- libgit2 0.21.2