示例#1
0
文件: views.py 项目: russell/karaage
def institute_users(request, machine_category_id, institute_id):

    machine_category = get_object_or_404(MachineCategory, pk=machine_category_id)
    institute = get_object_or_404(Institute, pk=institute_id)
    
    if not institute.can_view(request.user) and not getattr(settings, 'USAGE_IS_PUBLIC', False):
        return HttpResponseForbidden('<h1>Access Denied</h1>')

    start, end = get_date_range(request)

    available_time, cpus = get_available_time(start, end, machine_category)

    account_list = []

    account_total, account_total_jobs = 0, 0
    for u in PersonCache.objects.order_by('-cpu_hours').filter(start=start, end=end).filter(machine_category=machine_category).filter(account__institute=institute).filter(no_jobs__gt=0):
        account_total = account_total + u.cpu_hours
        account_total_jobs = account_total_jobs + u.no_jobs
        account_list.append({'account': u.account, 'project': u.project, 'usage': u.cpu_hours, 'jobs': u.no_jobs, 'percent': ((u.cpu_hours / available_time) * 100)})
        
    try:
        account_percent = (account_total / available_time) * 100
    except:
        account_percent = 0
    
    return render_to_response('usage/institute_users.html', locals(), context_instance=RequestContext(request))
示例#2
0
文件: models.py 项目: russell/karaage
    def get_mpots(self, start=datetime.date.today()-datetime.timedelta(days=90), end=datetime.date.today()):
        from karaage.common.helpers import get_available_time

        TWOPLACES = decimal.Decimal(10) ** -2
        usage, jobs = self.project.get_usage(start, end, self.machine_category)
        if usage is None:
            usage = decimal.Decimal('0')
        total_time, ave_cpus = get_available_time(start, end, self.machine_category)
        if total_time == 0:
            return 0
        return ((decimal.Decimal(usage) / total_time) * 100 * 1000).quantize(TWOPLACES)
示例#3
0
文件: views.py 项目: russell/karaage
def top_users(request, machine_category_id, count=20):

    machine_category = MachineCategory.objects.get(pk=machine_category_id)
    start, end = get_date_range(request)
    available_time, cpus = get_available_time(start, end, machine_category)
    account_list = []

    account_total, account_total_jobs = 0, 0
    for u in PersonCache.objects.order_by('-cpu_hours').filter(start=start, end=end).filter(machine_category=machine_category)[:count]:
        if u.cpu_hours:
            account_total += u.cpu_hours
            account_total_jobs += u.no_jobs
            account_list.append({'account': u.account, 'project': u.project, 'usage': u.cpu_hours, 'jobs': u.no_jobs, 'percent': ((u.cpu_hours / available_time) * 100)})
        
    account_percent = (account_total / available_time) * 100
    
    return render_to_response('usage/top_users.html', locals(), context_instance=RequestContext(request))
示例#4
0
文件: views.py 项目: russell/karaage
def index(request, machine_category_id):

    if not getattr(settings, 'USAGE_IS_PUBLIC', False):
        return HttpResponseForbidden('<h1>Access Denied</h1>')
    
    machine_category = get_object_or_404(MachineCategory, pk=machine_category_id)
    mc_list = MachineCategory.objects.exclude(id__exact=machine_category_id)
    
    show_zeros = True

    institute_list = Institute.active.all()
    total, total_jobs = 0, 0
    i_list = []
    m_list = []
    start, end = get_date_range(request)

    available_time, avg_cpus = get_available_time(start, end, machine_category)
    
    for m in machine_category.machine_set.all():
        time, jobs = m.get_usage(start, end)
        if time is None:
            time = 0
        m_list.append({'machine': m, 'usage': time, 'jobs': jobs})
            
    for iq in machine_category.institutequota_set.all():
        i = iq.institute

        time, jobs = i.get_usage(start, end, machine_category)
        if time is None:
            time = 0
    
        total = total + time
        total_jobs = total_jobs + jobs
        try:
            quota = InstituteQuota.objects.get(institute=i, machine_category=machine_category)
            display_quota = quota.quota
        except InstituteQuota.DoesNotExist:
            display_quota = None

        else:
            data_row = {'institute': i, 'usage': time, 'jobs': jobs, 'quota': display_quota}
            if available_time != 0:
                data_row['percent'] = Decimal(time) / Decimal(available_time) * 100
            else:
                data_row['percent'] = 0
            if data_row['quota'] is not None:
                if data_row['quota'] != 0:
                    data_row['p_used'] = (data_row['percent'] / data_row['quota']) * 100
                else:
                    data_row['p_used'] = 0
                data_row['diff'] = data_row['percent'] - data_row['quota']
                if data_row['diff'] <= 0:
                    data_row['class'] = 'green'
                else:
                    data_row['class'] = 'red'
            else:
                data_row['class'] = 'green'

            i_list.append(data_row)

    # Unused Entry
    unused = {'usage': available_time - total, 'quota': 0}
    try:
        unused['percent'] = (unused['usage'] / available_time) * 100
    except ZeroDivisionError:
        unused['percent'] = 0
    unused['diff'] = unused['percent'] - unused['quota'] / 100
    if unused['diff'] <= 0:
        unused['class'] = 'green'
    else:
        unused['class'] = 'red'

    if available_time != 0:
        utilization = (Decimal(total) / available_time) * 100
    else:
        utilization = 0

    institutes_graph = get_institute_graph_url(start, end, machine_category)
    machines_graph = get_machine_graph_url(start, end, machine_category)
    trend_graph = get_trend_graph_url(start, end, machine_category)

    return render_to_response('usage/usage_institute_list.html', locals(), context_instance=RequestContext(request))
示例#5
0
文件: views.py 项目: russell/karaage
def institute_usage(request, institute_id, machine_category_id):

    machine_category = get_object_or_404(MachineCategory, pk=machine_category_id)
    institute = get_object_or_404(Institute, pk=institute_id)
    project_list = []
    start, end = get_date_range(request)
    institute_list = Institute.active.all()

    if not institute.can_view(request.user) and not getattr(settings, 'USAGE_IS_PUBLIC', False):
        return HttpResponseForbidden('<h1>Access Denied</h1>')

    available_usage, ave_cpus = get_available_time(start, end, machine_category)

    quota = get_object_or_404(InstituteQuota, institute=institute, machine_category=machine_category)

    i_usage, i_jobs = institute.get_usage(start, end, machine_category)

    graph = None

    if i_jobs > 0:

        for p in institute.project_set.filter():
            p_usage, p_jobs = p.get_usage(start, end, machine_category)
            chunk, created = p.projectquota_set.get_or_create(machine_category=machine_category)
            if p_jobs > 0:
                mpots = chunk.get_mpots()
                if mpots:
                    try:
                        percent = (mpots / chunk.get_cap()) * 100
                    except ZeroDivisionError:
                        percent = 0
                else:
                    percent = 0
                try:
                    quota_percent = p_usage / (available_usage * quota.quota) * 10000
                except:
                    quota_percent = 0
                project_list.append(
                    {'project': p,
                     'usage': p_usage,
                     'jobs': p_jobs,
                     'percent': percent,
                     'quota_percent': quota_percent,
                     })

        account_list = []
        account_total, account_total_jobs = 0, 0
        if i_usage:
            for u in PersonCache.objects.order_by('-cpu_hours').filter(start=start, end=end).filter(project__institute=institute).filter(machine_category=machine_category)[:5]:
                if not u.cpu_hours:
                    continue
                account_total += u.cpu_hours
                account_total_jobs += u.no_jobs
                try:
                    quota_percent = u.cpu_hours / (available_usage * quota.quota) * 10000
                except ZeroDivisionError:
                    quota_percent = 0
                account_list.append(
                    {'person': u.person,
                     'project': u.project,
                     'usage': u.cpu_hours,
                     'jobs': u.no_jobs,
                     'percent': ((u.cpu_hours / i_usage) * 100),
                     'quota_percent': quota_percent,
                     })
                
            account_percent = (account_total / i_usage) * 100

    graph = get_institute_trend_graph_url(institute, start, end, machine_category)

    return render_to_response('usage/usage_institute_detail.html', locals(), context_instance=RequestContext(request))
示例#6
0
文件: tests.py 项目: russell/karaage
 def do_availablity_test(self, start, end, mc, expected_time, expected_cpu):
     from karaage.common.helpers import get_available_time
     available_time, avg_cpus = get_available_time(start.date(), end.date(), mc)
     self.failUnlessEqual(avg_cpus, expected_cpu)
     self.failUnlessEqual(available_time, expected_time)