def _timeframe(args, time_as_ts=False): end_time = args['end_time'] high_value = args.get('high_value', 100) if not end_time: end_time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ") high_value = 100 return calculate_proper_timeframe(args['build_id'], args['test_name'], args['lg_type'], args.get('low_value', 0), high_value, args['start_time'], end_time, args.get('aggregator', 'auto'), time_as_ts=time_as_ts)
def prepare_comparison_responses(args): tests = args['id[]'] tests_meta = [] longest_test = 0 longest_time = 0 sampler = args.get('sampler', "REQUEST") for i in range(len(tests)): data = APIReport.query.filter_by(id=tests[i]).first().to_json() if data['duration'] > longest_time: longest_time = data['duration'] longest_test = i tests_meta.append(data) start_time, end_time, aggregation = calculate_proper_timeframe( args.get('low_value', 0), args.get('high_value', 100), tests_meta[longest_test]['start_time'], tests_meta[longest_test]['end_time'], args.get('aggregator', 'auto')) if args.get('aggregator', 'auto') != "auto": aggregation = args.get('aggregator') metric = args.get('metric', '') scope = args.get('scope', '') status = args.get("status", 'all') timestamps, users = get_backend_users(tests_meta[longest_test]['build_id'], tests_meta[longest_test]['lg_type'], start_time, end_time, aggregation) test_start_time = "{}_{}".format( tests_meta[longest_test]['start_time'].replace("T", " ").split(".")[0], metric) data = { test_start_time: calculate_analytics_dataset(tests_meta[longest_test]['build_id'], tests_meta[longest_test]['name'], tests_meta[longest_test]['lg_type'], start_time, end_time, aggregation, sampler, scope, metric, status) } for i in range(len(tests_meta)): if i != longest_test: test_start_time = "{}_{}".format( tests_meta[i]['start_time'].replace("T", " ").split(".")[0], metric) data[test_start_time] = calculate_analytics_dataset( tests_meta[i]['build_id'], tests_meta[i]['name'], tests_meta[i]['lg_type'], tests_meta[i]['start_time'], tests_meta[i]['end_time'], aggregation, sampler, scope, metric, status) return comparison_data(timeline=timestamps, data=data)