Ejemplo n.º 1
0
def instance_detail(request):
    data = utils.data_from_post(request)
    user = str(request.user)
    account = Account.objects.filter(login=user)[0].account_id
    instance = data['instance']
    filter_args_dict = data['filter_args_dict']
    date = get_date_object(data['date'])
    day = date.strftime(constants.day_fmt)

    results = ReportData.objects.filter(
        instance_identifier=instance, day=day, **filter_args_dict)

    response_data = {}
    response_data['list'] = results
    response_data['account'] = account

    return create_response(response_data)
Ejemplo n.º 2
0
    def get_MDU_MCU(**kwargs):
        start = utils.get_date_object(kwargs["start"])
        end = utils.get_date_object(kwargs["end"])
        filter_args = kwargs["filter_args_dict"]
        product_name = kwargs["description"]["Product"]
        results = []
        mdu_count = []
        mcu_count = []
        date = []
        daily_contract = []

        currentDate = start
        f = filter_args
        delta = timedelta(days=1)
        calculation = 'hourly'
        contract_quantity = get_product_info(f, product_name)

        while currentDate < end:
            hourly_highest_concurrent_usage = 0
            day = currentDate.strftime(constants.day_fmt)
            if calculation == 'hourly':
                #Find the number of instances that checked in that day
                mdu_each = ReportData.objects.filter(day=day, **filter_args)
                mdu = len(mdu_each.distinct("instance_identifier"))

            else:
                _LOG.error('check rules, unsupported format found != hourly')
                raise Exception("unsupported calculation")

            hour_delta = timedelta(hours=1)
            currentHour = datetime.strptime(day, constants.day_fmt)
            
            #Find the highest concurrent usuage in a 24 hour period
            for h in range(24):
                this_hour = currentHour.strftime(constants.hr_fmt)
                mcu = ReportData.objects.filter(hour=this_hour, **filter_args).count()
                if mcu > hourly_highest_concurrent_usage:
                    hourly_highest_concurrent_usage = mcu

                currentHour += hour_delta

            # The highest number is the count
            mcu = hourly_highest_concurrent_usage

            results.append({'date': currentDate.strftime(constants.just_date),
                            'mdu': mdu,
                            'mcu': mcu}
                           )
            
            this_date = currentDate.strftime(constants.jqplot_fmt)
            mdu_count.append([this_date, mdu])
            mcu_count.append([this_date, mcu])
            daily_contract.append([this_date, contract_quantity])
            date.append(this_date)

            currentDate += delta

        payload = {"list": results,
                   "mdu": mdu_count,
                   "mcu": mcu_count,
                   "daily_contract": daily_contract,
                   "date": date
                   }
        return payload