def create_export_report(request): _LOG.info("report called by method: %s" % (request.method)) user = str(request.user) account = Account.objects.filter(login=user)[0].account_id start, end = get_dates_from_request(request) if 'env' in request.GET: environment = request.GET['env'] else: environment = "All" rhic = request.GET['rhic'] contract = request.GET['contract_number'] list_of_rhics = [] if contract == 'All' and (rhic == 'All' or rhic == 'null'): list_of_rhics = list(RHIC.objects.filter(account_id=account)) results = hours_per_consumer(start, end, list_of_rhics=list_of_rhics, environment=environment) elif rhic != 'null': if rhic == "All": list_of_rhics = list(RHIC.objects.filter(contract=contract)) else: my_uuid = rhic list_of_rhics = list(RHIC.objects.filter(uuid=my_uuid)) results = hours_per_consumer(start, end, list_of_rhics, environment=environment) else: list_of_rhics = list(RHIC.objects.filter(account_id=account)) results = hours_per_consumer(start, end, list_of_rhics=list_of_rhics, environment=environment) format = constants.full_format response_data = {} response_data['list'] = results response_data['account'] = account response_data['start'] = start.strftime(format) response_data['end'] = end.strftime(format) #return create_response(utils.to_json(response_data)) return create_response(response_data)
def default_report(request): _LOG.info("default_report called by method: %s" % (request.method)) user = str(request.user) account = Account.objects.filter(login=user)[0].account_id data = data_from_post(request) start, end = get_dates_from_request(request) environment = data['env'] list_of_rhics = [] list_of_rhics = list(RHIC.objects.filter(account_id=account)) args = {'start': start, 'end': end, 'list_of_rhics': list_of_rhics, 'environment': environment, 'return_failed_only': True } usuage_compliance = hours_per_consumer(**args) fact_compliance = system_fact_compliance_list(account) format = constants.full_format response_data = {} response_data['list'] = usuage_compliance response_data['biz_list'] = fact_compliance response_data['account'] = account response_data['start'] = start.strftime(format) response_data['end'] = end.strftime(format) return create_response(response_data)
def test_hours_per_consumer(self): ReportData.drop_collection() count = 0 for key, value in products_dict.items(): count += 1 entry = TestData.create_entry(key, mem_high=True) entry.save(safe=True) lookup = len(ReportData.objects.all()) self.assertEqual(lookup, count) end = datetime.now() delta=timedelta(days=1) start = datetime.now() - delta list_of_rhics = RHIC.objects.all() results = hours_per_consumer(start, end, list_of_rhics ) # right now products_dict RHEL and JBoss are sharing a RHIC so.. -1 on length self.assertEqual(len(results), (len(products_dict) -1 ), "correct number of results returned") results_product_list = [] for r in results: self.assertEqual(r[0]['nau'], '1', "number of checkins is accurate") results_product_list.append(r[0]['product_name']) intersect = set(results_product_list).intersection(products_dict.keys()) self.assertEqual(len(intersect), (len(products_dict) -1), "number of products returned in results is accurate")
def check_product_result(self, result1, result2): lookup = len(ReportData.objects.all()) self.assertEqual(lookup, 2) end = datetime.now() delta=timedelta(days=1) start = datetime.now() - delta list_of_rhics = RHIC.objects.all() results = hours_per_consumer(start, end, list_of_rhics ) self.assertEqual(len(results), int(result1), "correct number of results returned, 1 result per rhic") self.assertEqual(len(results[0]), int(result2), "correct number of products returned in result..")
def report(request): _LOG.info("report called by method: %s" % (request.method)) user = str(request.user) account = Account.objects.filter(login=user)[0].account_id start, end = get_dates_from_request(request) data = data_from_post(request) if 'env' in data: environment = data["env"] else: environment = "All" rhic = data["rhic"] contract = data["contract_number"] list_of_rhics = [] if contract == 'All' and (rhic == 'All' or rhic == 'null'): list_of_rhics = list(RHIC.objects.filter(account_id=account)) elif rhic != 'null': if rhic == "All": list_of_rhics = list(RHIC.objects.filter(contract=contract)) else: my_uuid = data['rhic'] list_of_rhics = list(RHIC.objects.filter(uuid=my_uuid)) else: list_of_rhics = list(RHIC.objects.filter(account_id=account)) args = {'start': start, 'end': end, 'list_of_rhics': list_of_rhics, 'environment': environment } results = hours_per_consumer(**args) format = constants.full_format response_data = {} response_data['list'] = results response_data['account'] = account response_data['start'] = start.strftime(format) response_data['end'] = end.strftime(format) return create_response(response_data)
def create_export_report(request): """ This is now used by "Export Report" and should be the "GET" equiv of report @param request: http generate the data for the report. data is generated from hours_per_consumer Returns: Content-Disposition:attachment; filename=reportdata.csv Content-Type:text/csv """ _LOG.info("report called by method: %s" % (request.method)) user = str(request.user) account = Account.objects.filter(login=user)[0].account_id start, end = get_dates_from_request(request) if 'env' in request.GET: environment = request.GET['env'] else: environment = "All" rhic = request.GET['rhic'] contract = request.GET['contract_number'] list_of_rhics = [] if contract == 'All' and (rhic == 'All' or rhic == 'null'): list_of_rhics = list(RHIC.objects.filter(account_id=account)) results = hours_per_consumer(start, end, list_of_rhics=list_of_rhics, environment=environment) elif rhic != 'null': if rhic == "All": list_of_rhics = list(RHIC.objects.filter(contract=contract)) else: my_uuid = rhic list_of_rhics = list(RHIC.objects.filter(uuid=my_uuid)) results = hours_per_consumer(start, end, list_of_rhics, environment=environment) else: list_of_rhics = list(RHIC.objects.filter(account_id=account)) results = hours_per_consumer(start, end, list_of_rhics=list_of_rhics, environment=environment) format = constants.full_format response_data = {} response_data['list'] = results response_data['account'] = account response_data['start'] = start.strftime(format) response_data['end'] = end.strftime(format) #return create_response(utils.to_json(response_data)) return create_response(response_data)