def get_test_value_summary(request, project): branch = request.GET['branch'] test_ids = utils.get_id_list(request.GET['test_ids']) page_name = request.GET.get("page_name", "") range = request.GET.get("range", 7) device = request.GET.get("device", "unagi") #make sure we're operating on an int try: range = int(range) except ValueError: range = 7 # don't allow ranges > 90 if range > 90: range = 90 now = int(time.time()) begin = now - 86400 * range return HttpResponse( json.dumps( testdata.get_test_value_summary(project, branch, device, test_ids, page_name, begin, now)), content_type=API_CONTENT_TYPE, )
def get_test_value_summary(request, project): branch = request.GET['branch'] test_ids = utils.get_id_list(request.GET['test_ids']) page_name = request.GET.get("page_name", "") range = request.GET.get("range", 7) device = request.GET.get("device", "unagi") #make sure we're operating on an int try: range = int(range) except ValueError: range = 7 # don't allow ranges > 90 if range > 90: range = 90 now = int(time.time()) begin = now - 86400 * range return HttpResponse( json.dumps(testdata.get_test_value_summary( project, branch, device, test_ids, page_name, begin, now )), content_type=API_CONTENT_TYPE, )
def _get_test_run_summary(project, method, request, dm): product_ids = [] test_ids = [] platform_ids = [] ##### #Calling get_id_list() insures that we have only numbers in the #lists, this gaurds against SQL injection ##### if 'product_ids' in request.GET: product_ids = utils.get_id_list(request.GET['product_ids']) if 'test_ids' in request.GET: test_ids = utils.get_id_list(request.GET['test_ids']) if 'platform_ids' in request.GET: platform_ids = utils.get_id_list(request.GET['platform_ids']) time_key = 'days_30' time_ranges = utils.get_time_ranges() if 'tkey' in request.GET: time_key = request.GET['tkey'] if not product_ids: ##Default to id 1 product_ids = [1] ##Set default product_id pck = dm.get_project_cache_key('default_product') default_products = cache.get(pck) default_products = dm.get_default_products() ##If we have one use it if default_products: product_ids = map( int, default_products.split(',') ) json_data = '{}' table = dm.get_test_run_summary(time_ranges[time_key]['start'], time_ranges[time_key]['stop'], product_ids, platform_ids, test_ids) json_data = json.dumps( table ) return json_data
def _get_test_run_summary(project, method, request, dm): product_ids = [] test_ids = [] platform_ids = [] ##### #Calling get_id_list() insures that we have only numbers in the #lists, this gaurds against SQL injection ##### if 'product_ids' in request.GET: product_ids = utils.get_id_list(request.GET['product_ids']) if 'test_ids' in request.GET: test_ids = utils.get_id_list(request.GET['test_ids']) if 'platform_ids' in request.GET: platform_ids = utils.get_id_list(request.GET['platform_ids']) time_key = 'days_30' time_ranges = utils.get_time_ranges() if 'tkey' in request.GET: time_key = request.GET['tkey'] if not product_ids: ##Default to id 1 product_ids = [1] ##Set default product_id pck = dm.get_project_cache_key('default_product') default_products = cache.get(pck) default_products = dm.get_default_products() ##If we have one use it if default_products: product_ids = map(int, default_products.split(',')) json_data = '{}' table = dm.get_test_run_summary(time_ranges[time_key]['start'], time_ranges[time_key]['stop'], product_ids, platform_ids, test_ids) json_data = json.dumps(table) return json_data
def _getTestRunSummary(project, method, request, dm): productIds = [] testIds = [] platformIds = [] ##### #Calling get_id_list() insures that we have only numbers in the #lists, this gaurds against SQL injection ##### if 'product_ids' in request.GET: productIds = utils.get_id_list(request.GET['product_ids']) if 'test_ids' in request.GET: testIds = utils.get_id_list(request.GET['test_ids']) if 'platform_ids' in request.GET: platformIds = utils.get_id_list(request.GET['platform_ids']) timeKey = 'days_30' timeRanges = utils.get_time_ranges() if 'tkey' in request.GET: timeKey = request.GET['tkey'] if not productIds: ##Set default productId## productIds = [12] jsonData = '{}' mc = memcache.Client([settings.DATAZILLA_MEMCACHED], debug=0) if productIds and (not testIds) and (not platformIds): if len(productIds) > 1: extendList = { 'data':[], 'columns':[] } for id in productIds: key = utils.get_cache_key(project, str(id), timeKey) compressedJsonData = mc.get(key) if compressedJsonData: jsonData = zlib.decompress( compressedJsonData ) data = json.loads( jsonData ) extendList['data'].extend( data['data'] ) extendList['columns'] = data['columns'] jsonData = json.dumps(extendList) else: key = utils.get_cache_key( project, str(productIds[0]), timeKey, ) compressedJsonData = mc.get(key) if compressedJsonData: jsonData = zlib.decompress( compressedJsonData ) else: table = dm.getTestRunSummary(timeRanges[timeKey]['start'], timeRanges[timeKey]['stop'], productIds, platformIds, testIds) jsonData = json.dumps( table ) return jsonData
def _get_test_run_summary(project, method, request, dm): product_ids = [] test_ids = [] platform_ids = [] ##### #Calling get_id_list() insures that we have only numbers in the #lists, this gaurds against SQL injection ##### if 'product_ids' in request.GET: product_ids = utils.get_id_list(request.GET['product_ids']) if 'test_ids' in request.GET: test_ids = utils.get_id_list(request.GET['test_ids']) if 'platform_ids' in request.GET: platform_ids = utils.get_id_list(request.GET['platform_ids']) time_key = 'days_30' time_ranges = utils.get_time_ranges() if 'tkey' in request.GET: time_key = request.GET['tkey'] if not product_ids: ##Default to id 1 product_ids = [1] ##Set default product_id pck = dm.get_project_cache_key('default_product') default_product = cache.get(pck) ##If we have one use it if default_product: product_ids = [ int(default_product['id']) ] json_data = '{}' if product_ids and (not test_ids) and (not platform_ids): if len(product_ids) > 1: extend_list = { 'data':[], 'columns':[] } for id in product_ids: key = utils.get_summary_cache_key(project, str(id), time_key) compressed_json_data = cache.get(key) if compressed_json_data: json_data = zlib.decompress( compressed_json_data ) data = json.loads( json_data ) extend_list['data'].extend( data['data'] ) extend_list['columns'] = data['columns'] json_data = json.dumps(extend_list) else: key = utils.get_summary_cache_key( project, str(product_ids[0]), time_key, ) compressed_json_data = cache.get(key) if compressed_json_data: json_data = zlib.decompress( compressed_json_data ) else: table = dm.get_test_run_summary(time_ranges[time_key]['start'], time_ranges[time_key]['stop'], product_ids, platform_ids, test_ids) json_data = json.dumps( table ) return json_data