def retrieve_run_view_plot(run, plot, sensor, reference):
    from veloview.runview import plots, response_formatters, utils

    # Check all arguments have valid values
    if not utils.valid_run(run):
        sys.stderr.write("Invalid run number provided: {0}".format(run))
        sys.exit(1)
    if not utils.valid_sensor(sensor):
        sys.stderr.write("Invalid sensor number provided: {0}".format(sensor))
        sys.exit(1)

    # Format the plot name with the sensor number
    # str.format will work even with no format specifiers in the string
    plot = plot.format(sensor)

    # Try to the get the plot object
    try:
        plot_obj = plots.get_run_plot(plot, run, reference=reference)
    except KeyError, e:
        sys.stderr.write("Invalid plot name provided: {0}".format(plot))
        sys.stderr.write("Exception caught: {0}".format(e))
        sys.exit(1)
Example #2
0
def retrieve_run_view_plot(run, plot, sensor, noreference, run_data_dir):
    import json
    from veloview.runview import plots, response_formatters, utils

    # Change the run data directory to the user-specified one
    Config().run_data_dir = run_data_dir

    # Check all arguments have valid values
    err = False
    if not utils.valid_run(run):
        err = True
        msg = "Invalid run number provided: {0}".format(run)
    if not utils.valid_sensor(sensor):
        err = True
        msg = "Invalid sensor number provided: {0}".format(sensor)
    if err:
        exit_with_error(msg)

    # Format the plot name with the sensor number
    # str.format will work even with no format specifiers in the string
    plot = plot.format(sensor)

    # Try to the get the plot object, formatting it to JSON
    try:
        if noreference:
            # Return a 2-tuple to be consistent with the nominal+reference case
            response = (plots.get_run_plot(
                plot,
                run,
                reference=False,
                formatter=response_formatters.json_formatter),
                        json.dumps(None))
        else:
            response = plots.get_run_plot_with_reference(
                plot, run, formatter=response_formatters.json_formatter)
    except KeyError, e:
        err = True
        msg = ("Invalid plot name provided: {0}. "
               "Exception caught: {1}.").format(plot, e)
Example #3
0
def run_view_builder(run, page, sensor):
    # See if the request was for a particular run/page/sensor and redirect
    # If any GET parameter wasn't specified, or was specified with an invalid
    # value, fall back to the default
    if request.args:
        run = request.args.get('run', run)
        page = request.args.get('page', page)
        sensor = request.args.get('sensor', sensor)
        # Check that the integer URL params are castable
        try:
            run = int(run)
        except ValueError:
            new_run = default_run()
            flash('Invalid run number "{0}", reset to "{1}"'.format(
                run, new_run
            ), 'error')
            run = new_run
        try:
            sensor = int(sensor)
        except ValueError:
            new_sensor = 0
            flash('Invalid sensor number "{0}", reset to "{1}"'.format(
                sensor, new_sensor
            ), 'error')
            sensor = new_sensor
        url = url_for('run_view.run_view_builder',
                      run=run,
                      page=page,
                      sensor=sensor)
        return redirect(url)

    # Check if the run number is valid, redirecting to default if not
    if not runview_utils.valid_run(run):
        new_run = default_run()
        flash('Invalid run number "{0}", reset to "{1}"'.format(run, new_run),
              'error')
        run = new_run
        url = url_for('run_view.run_view_builder',
                      run=run,
                      page=page,
                      sensor=sensor)
        return redirect(url)

    # Check if the sensor number is valid, redirecting to default (0) if not
    if not runview_utils.valid_sensor(sensor):
        flash('Invalid sensor number "{0}", reset to "0"'.format(sensor),
              'error')
        sensor = 0
        url = url_for('run_view.run_view_builder',
                      run=run,
                      page=page,
                      sensor=sensor)
        return redirect(url)

    # Load the default page from the configuration if we're at the root
    if page == '':
        page = current_app.config['DEFAULT_CHILDREN'].get('run_view', None)
        if page is not None:
            page = page[len('run_view/'):]
    # Else load the page data associated with the route's page
    page_data = run_view_config.run_view_pages.get(page, None)

    # Set up the required template variables and render the page
    g.page = page
    g.pages = run_view_config.run_view_pages
    g.page_data = page_data
    g.run = run
    g.runs = runview_utils.run_list()
    g.nearby_runs = nearby_runs(g.run, g.runs)
    g.sensor = sensor
    g.active_page = 'run_view/{0}'.format(page)

    # 404 if the page doesn't exist in the config dict
    if page_data is None:
        abort(404)

    return render_template('run_view/dynamic.html')
 def test_invalid_run(self):
     """Should return False if run isn't present in the run number file."""
     probe_run = 123321
     self.assertTrue(probe_run not in RUNS)
     self.assertFalse(utils.valid_run(probe_run))
 def test_valid_run(self):
     """Should return True if run is present in the run number file."""
     for r in RUNS:
         self.assertTrue(utils.valid_run(r))
Example #6
0
def run_view_builder(run, page, sensor):
    # See if the request was for a particular run/page/sensor and redirect
    # If any GET parameter wasn't specified, or was specified with an invalid
    # value, fall back to the default
    if request.args:
        run = request.args.get('run', run)
        page = request.args.get('page', page)
        sensor = request.args.get('sensor', sensor)
        # Check that the integer URL params are castable
        try:
            run = int(run)
        except ValueError:
            new_run = default_run()
            flash('Invalid run number "{0}", reset to "{1}"'.format(
                run, new_run
            ), 'error')
            run = new_run
        try:
            sensor = int(sensor)
        except ValueError:
            new_sensor = 0
            flash('Invalid sensor number "{0}", reset to "{1}"'.format(
                sensor, new_sensor
            ), 'error')
            sensor = new_sensor
        url = url_for('run_view.run_view_builder',
                      run=run,
                      page=page,
                      sensor=sensor)
        return redirect(url)

    # Check if the run number is valid, redirecting to default if not
    if not runview_utils.valid_run(run):
        new_run = default_run()
        flash('Invalid run number "{0}", reset to "{1}"'.format(run, new_run),
              'error')
        run = new_run
        url = url_for('run_view.run_view_builder',
                      run=run,
                      page=page,
                      sensor=sensor)
        return redirect(url)

    # Check if the sensor number is valid, redirecting to default (0) if not
    if not runview_utils.valid_sensor(sensor):
        flash('Invalid sensor number "{0}", reset to "0"'.format(sensor),
              'error')
        sensor = 0
        url = url_for('run_view.run_view_builder',
                      run=run,
                      page=page,
                      sensor=sensor)
        return redirect(url)

    # Add the dummy DQ page
    pages = VeloConfig().run_view_pages.items()
    pages.insert(0, ('dq', {'title': 'Data quality'}))
    pages = OrderedDict(pages)

    # Load the default page from the configuration if we're at the root
    if page == '':
        page = current_app.config['DEFAULT_CHILDREN'].get('run_view', None)
        if page is not None:
            page = page[len('run_view/'):]
    # Else load the page data associated with the route's page
    page_data = pages.get(page, None)

    # Set up the required template variables and render the page
    g.page = page
    g.pages = pages
    g.page_data = page_data
    g.run = run
    g.runs = runview_utils.run_list()
    g.nearby_runs = nearby_runs(g.run, g.runs)
    g.sensor = sensor
    g.active_page = 'run_view/{0}'.format(page)

    # 404 if the page doesn't exist in the config dict
    if page_data is None:
        abort(404)

    return render_template('run_view/dynamic.html')
 def test_invalid_run(self):
     """Should return False if run isn't present in the run number file."""
     probe_run = 123321
     self.assertTrue(probe_run not in RUNS)
     self.assertFalse(utils.valid_run(probe_run))
 def test_valid_run(self):
     """Should return True if run is present in the run number file."""
     for r in RUNS:
         self.assertTrue(utils.valid_run(r))