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))
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)
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))
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 )