コード例 #1
0
def runview_plot(run,
                 name,
                 sensor,
                 run_data_dir,
                 refRun='Auto',
                 getRef=False,
                 normalise=False,
                 notifyBox=None):
    Config().run_data_dir = run_data_dir
    err = False
    # Need to append the sensor number to the name.
    #     if not utils.valid_run(run):
    #         err = True
    #         msg = "Invalid run number provided: {0}".format(run)
    #         print msg
    if not utils.valid_sensor(sensor):
        err = True
        msg = "Invalid sensor number provided: {0}".format(sensor)
        print msg

    name = name.format(sensor)

    if getRef:
        if refRun == 'Auto':
            print 'Getting auto ref'
            return plots.get_run_plot_with_reference(name,
                                                     run,
                                                     normalise=normalise,
                                                     notifyBox=notifyBox)
        else:
            print 'Getting specified ref'
            return plots.get_run_plot_with_reference(name,
                                                     run,
                                                     refRun=refRun,
                                                     normalise=normalise,
                                                     notifyBox=notifyBox)
    else:
        return plots.get_run_plot(name,
                                  run,
                                  normalise=normalise,
                                  notifyBox=notifyBox)
コード例 #2
0
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)
コード例 #3
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)
コード例 #4
0
ファイル: run_view.py プロジェクト: suvayu/LHCbVeloView
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')
コード例 #5
0
 def test_invalid_sensor(self):
     """Return False if sensor isn't a valid sensor number."""
     for s in range(0, 200):
         if s not in SENSORS:
             self.assertFalse(utils.valid_sensor(s))
コード例 #6
0
 def test_valid_sensor(self):
     """Return True if sensor is a valid sensor number."""
     for s in SENSORS:
         self.assertTrue(utils.valid_sensor(s))
コード例 #7
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')
コード例 #8
0
 def test_invalid_sensor(self):
     """Return False if sensor isn't a valid sensor number."""
     for s in range(0, 200):
         if s not in SENSORS:
             self.assertFalse(utils.valid_sensor(s))
コード例 #9
0
 def test_valid_sensor(self):
     """Return True if sensor is a valid sensor number."""
     for s in SENSORS:
         self.assertTrue(utils.valid_sensor(s))