コード例 #1
0
def image_stats():
    # Get parameters
    image_id = request.args.get('id', '')
    time_from = request.args.get('from', '')
    time_to = request.args.get('to', '')
    data_type = request.args.get('data_type', '1')
    embed = request.args.get('embed', '')
    try:
        # Validate params, get iso and datetime versions
        if image_id == '':
            raise ValueError('No image was specified.')
        image_id = parse_long(image_id)
        (iso_time_from,
         iso_time_to) = process_time_parameters(time_from, time_to)
        dt_time_from = parse_iso_datetime(iso_time_from)
        dt_time_to = parse_iso_datetime(iso_time_to)
        embed = parse_boolean(embed)

        return render_template(
            'reports_image_stats.html',
            timezone=get_timezone_code(),
            timezone_seconds=get_timezone_offset(),
            time_from=dt_time_from,
            time_to=dt_time_to,
            data_type=data_type,
            db_image=data_engine.get_image(image_id=image_id),
            embed=embed)
    except Exception as e:
        log_security_error(e, request)
        if app.config['DEBUG']:
            raise
        raise InternalServerError(safe_error_str(e))
コード例 #2
0
ファイル: views.py プロジェクト: quru/qis
def datafeed_image():
    try:
        # Get parameters
        image_id = parse_long(request.args.get('id', ''))
        dt_time_from = parse_iso_datetime(request.args.get('from'))
        dt_time_to = parse_iso_datetime(request.args.get('to'))
        data_type = parse_int(request.args.get('data_type', ''))

        require_full_period = (data_type < 8)
        if require_full_period:
            # Stop at 'now' minus the stats gap so we don't return incomplete stats
            dt_time_limit = datetime.utcnow() - timedelta(
                minutes=app.config['STATS_FREQUENCY'])
            if dt_time_to > dt_time_limit:
                dt_time_to = dt_time_limit

        # Get stats and convert to chart data
        results = data_engine.search_image_stats(dt_time_from, dt_time_to,
                                                 image_id)
        results = add_zero_stats(dt_time_from, dt_time_to,
                                 app.config['STATS_FREQUENCY'], results,
                                 ImageStats)
        data = _db_results_to_flot_data(results, data_type)

        return make_json_response(200,
                                  data=data,
                                  first=0 if len(data) == 0 else data[0][0],
                                  last=0 if len(data) == 0 else data[-1][0])

    except Exception as e:
        if not log_security_error(e, request):
            logger.error('Error reading image stats: ' + str(e))
        if app.config['DEBUG']:
            raise
        return make_json_response(200, data=[], first=0, last=0)
コード例 #3
0
def system_stats():
    # Get parameters
    time_from = request.args.get('from', '')
    time_to = request.args.get('to', '')
    data_type = request.args.get('data_type', '1')
    embed = request.args.get('embed', '')
    try:
        # Validate params, get iso and datetime versions
        (iso_time_from,
         iso_time_to) = process_time_parameters(time_from, time_to)
        dt_time_from = parse_iso_datetime(iso_time_from)
        dt_time_to = parse_iso_datetime(iso_time_to)
        embed = parse_boolean(embed)

        return render_template('reports_system_stats.html',
                               timezone=get_timezone_code(),
                               timezone_seconds=get_timezone_offset(),
                               time_from=dt_time_from,
                               time_to=dt_time_to,
                               data_type=data_type,
                               embed=embed)
    except Exception as e:
        log_security_error(e, request)
        if app.config['DEBUG']:
            raise
        raise InternalServerError(safe_error_str(e))
コード例 #4
0
def process_time_parameters(from_str, to_str):
    """
    Validates or sets default values for 2 timestamps, expected to be either
    empty strings or in "yyyy-mm-ddThh:mm:ss" format as UTC times.
    If the 'to' value is empty, it is defaulted to the current UTC time.
    If the 'from' value is empty, it is defaulted to UTC midnight at the
    beginning of the same day as the 'to' value.
    Returns a tuple of (from_str, to_str), or raises a ValueError if either
    of the supplies values is not in the correct format.
    """
    if to_str:
        # Just validate it
        dt_time_to = parse_iso_datetime(to_str)
    else:
        # Set as now
        dt_time_to = datetime.utcnow()
        to_str = to_iso_datetime(dt_time_to)

    if from_str:
        # Just validate it
        dt_time_from = parse_iso_datetime(from_str)
        if dt_time_from >= dt_time_to:
            dt_time_from = dt_time_to - timedelta(minutes=1)
            from_str = to_iso_datetime(dt_time_from)
    else:
        # Set as midnight on day of time_to
        dt_time_from = dt_time_to - timedelta(
            hours=dt_time_to.hour,
            minutes=dt_time_to.minute,
            seconds=dt_time_to.second,
            microseconds=dt_time_to.microsecond)
        from_str = to_iso_datetime(dt_time_from)

    return (from_str, to_str)
コード例 #5
0
ファイル: views_pages.py プロジェクト: quru/qis
def image_stats():
    # Get parameters
    image_id = request.args.get('id', '')
    time_from = request.args.get('from', '')
    time_to = request.args.get('to', '')
    data_type = request.args.get('data_type', '1')
    embed = request.args.get('embed', '')
    try:
        # Validate params, get iso and datetime versions
        if image_id == '':
            raise ValueError('No image was specified.')
        image_id = parse_long(image_id)
        (iso_time_from, iso_time_to) = process_time_parameters(time_from, time_to)
        dt_time_from = parse_iso_datetime(iso_time_from)
        dt_time_to = parse_iso_datetime(iso_time_to)
        embed = parse_boolean(embed)

        return render_template(
            'reports_image_stats.html',
            timezone=get_timezone_code(),
            timezone_seconds=get_timezone_offset(),
            time_from=dt_time_from,
            time_to=dt_time_to,
            data_type=data_type,
            db_image=data_engine.get_image(image_id=image_id),
            embed=embed
        )
    except Exception as e:
        log_security_error(e, request)
        if app.config['DEBUG']:
            raise
        raise InternalServerError(str(e))
コード例 #6
0
ファイル: views_pages.py プロジェクト: quru/qis
def system_stats():
    # Get parameters
    time_from = request.args.get('from', '')
    time_to = request.args.get('to', '')
    data_type = request.args.get('data_type', '1')
    embed = request.args.get('embed', '')
    try:
        # Validate params, get iso and datetime versions
        (iso_time_from, iso_time_to) = process_time_parameters(time_from, time_to)
        dt_time_from = parse_iso_datetime(iso_time_from)
        dt_time_to = parse_iso_datetime(iso_time_to)
        embed = parse_boolean(embed)

        return render_template(
            'reports_system_stats.html',
            timezone=get_timezone_code(),
            timezone_seconds=get_timezone_offset(),
            time_from=dt_time_from,
            time_to=dt_time_to,
            data_type=data_type,
            embed=embed
        )
    except Exception as e:
        log_security_error(e, request)
        if app.config['DEBUG']:
            raise
        raise InternalServerError(str(e))
コード例 #7
0
ファイル: views_pages.py プロジェクト: quru/qis
def process_time_parameters(from_str, to_str):
    """
    Validates or sets default values for 2 timestamps, expected to be either
    empty strings or in "yyyy-mm-ddThh:mm:ss" format as UTC times.
    If the 'to' value is empty, it is defaulted to the current UTC time.
    If the 'from' value is empty, it is defaulted to UTC midnight at the
    beginning of the same day as the 'to' value.
    Returns a tuple of (from_str, to_str), or raises a ValueError if either
    of the supplies values is not in the correct format.
    """
    if to_str:
        # Just validate it
        dt_time_to = parse_iso_datetime(to_str)
    else:
        # Set as now
        dt_time_to = datetime.utcnow()
        to_str = to_iso_datetime(dt_time_to)

    if from_str:
        # Just validate it
        dt_time_from = parse_iso_datetime(from_str)
        if dt_time_from >= dt_time_to:
            dt_time_from = dt_time_to - timedelta(minutes=1)
            from_str = to_iso_datetime(dt_time_from)
    else:
        # Set as midnight on day of time_to
        dt_time_from = dt_time_to - timedelta(
            hours=dt_time_to.hour, minutes=dt_time_to.minute,
            seconds=dt_time_to.second, microseconds=dt_time_to.microsecond
        )
        from_str = to_iso_datetime(dt_time_from)

    return (from_str, to_str)
コード例 #8
0
ファイル: views.py プロジェクト: quru/qis
def datafeed_image():
    try:
        # Get parameters
        image_id = parse_long(request.args.get('id', ''))
        dt_time_from = parse_iso_datetime(request.args.get('from'))
        dt_time_to = parse_iso_datetime(request.args.get('to'))
        data_type = parse_int(request.args.get('data_type', ''))

        require_full_period = (data_type < 8)
        if require_full_period:
            # Stop at 'now' minus the stats gap so we don't return incomplete stats
            dt_time_limit = datetime.utcnow() - timedelta(minutes=app.config['STATS_FREQUENCY'])
            if dt_time_to > dt_time_limit:
                dt_time_to = dt_time_limit

        # Get stats and convert to chart data
        results = data_engine.search_image_stats(dt_time_from, dt_time_to, image_id)
        results = add_zero_stats(
            dt_time_from, dt_time_to,
            app.config['STATS_FREQUENCY'], results, ImageStats
        )
        data = _db_results_to_flot_data(results, data_type)

        return make_json_response(
            200,
            data=data,
            first=0 if len(data) == 0 else data[0][0],
            last=0 if len(data) == 0 else data[-1][0]
        )

    except Exception as e:
        if not log_security_error(e, request):
            logger.error('Error reading image stats: ' + str(e))
        if app.config['DEBUG']:
            raise
        return make_json_response(
            200,
            data=[],
            first=0,
            last=0
        )
コード例 #9
0
ファイル: views_portfolios_api.py プロジェクト: quru/qis
    def _get_validated_object_parameters(self, data_dict):
        params = {
            'description': data_dict['description'],
            'originals': parse_boolean(data_dict['originals']),
            'image_parameters': data_dict.get('image_parameters', '{}'),
            'expiry_time': parse_iso_date(data_dict['expiry_time'])
        }
        if len(data_dict['expiry_time']) >= 19:
            # It looks like expiry_time has a time part
            params['expiry_time'] = parse_iso_datetime(
                data_dict['expiry_time'])

        validate_string(params['description'], 0, 5 * 1024)
        validate_string(params['image_parameters'], 2, 100 * 1024)
        params['image_parameters'] = _image_params_to_template_dict(
            params['image_parameters'])
        if params['expiry_time'] < datetime.utcnow():
            raise ValueError('expiry time (UTC) has already passed')
        return params