Exemple #1
0
def institute_detail(request, institute_id):
    
    institute = get_object_or_404(Institute, pk=institute_id)

    start=datetime.date.today() - datetime.timedelta(days=90)
    end=datetime.date.today()

    if institute.is_active:
        graph = {}
        for ic in institute.institutequota_set.all():
            graph[ic.machine_category] = get_institute_trend_graph_url(institute, start, end, ic.machine_category)
    
    return render_to_response('institutes/institute_detail.html', locals(), context_instance=RequestContext(request))
Exemple #2
0
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))
Exemple #3
0
def institute_usage(request, institute_id, machine_category_id):
    result = progress(request)
    if result is not None:
        return result

    machine_category = get_object_or_404(
        MachineCategory, pk=machine_category_id)
    institute = get_object_or_404(Institute, pk=institute_id)
    start, end = get_date_range(request)

    result = gen_cache_for_machine_category(
        request, start, end, machine_category)
    if result is not None:
        return render_to_response(
            'usage/progress.html',
            {'task_id': result.task_id},
            context_instance=RequestContext(request))

    result = gen_cache_for_institute(
        request, start, end, institute, machine_category)
    if result is not None:
        return render_to_response(
            'usage/progress.html',
            {'task_id': result.task_id},
            context_instance=RequestContext(request))

    project_list = []
    institute_list = Institute.active.all()

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

    mc_cache = usage.get_machine_category_usage(machine_category, start, end)
    available_time = mc_cache.available_time

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

    i_usage, i_jobs = usage.get_institute_usage(
        institute, start, end, machine_category)

    for p_cache in models.ProjectCache.objects.filter(
            project__institute=institute,
            machine_category=machine_category,
            date=datetime.date.today(), start=start, end=end):
        p = p_cache.project
        p_usage = p_cache.cpu_time
        p_jobs = p_cache.no_jobs

        try:
            chunk = p.projectquota_set.get(machine_category=machine_category)
        except ProjectQuota.DoesNotExist:
            chunk = None

        if chunk is None and p_usage == 0 and p_jobs == 0:
            continue

        if chunk is not None:
            mpots = mc_cache.get_project_mpots(chunk, start, end)
            percent = mc_cache.get_project_cap_percent(chunk, start, end)
        else:
            mpots = None
            percent = None
        if available_time > 0 and quota.quota > 0:
            quota_percent = p_usage / (available_time * quota.quota) * 10000
        else:
            quota_percent = 0
        project_list.append(
            {'project': p,
             'usage': p_usage,
             'jobs': p_jobs,
             'percent': percent,
             'quota_percent': quota_percent,
             })

    person_list = []
    person_total, person_total_jobs = 0, 0

    query = models.PersonCache.objects.filter(
        project__institute=institute,
        machine_category=machine_category,
        date=datetime.date.today(), start=start, end=end)
    query = query.order_by('-cpu_time')

    for u in query[:5]:
        person_total += u.cpu_time
        person_total_jobs += u.no_jobs
        if i_usage > 0:
            i_percent = (u.cpu_time / i_usage) * 100
        else:
            i_percent = None
        if available_time > 0 and quota.quota > 0:
            quota_percent = u.cpu_time / (available_time * quota.quota) * 10000
        else:
            quota_percent = 0
        person_list.append(
            {'person': u.person,
             'project': u.project,
             'usage': u.cpu_time,
             'jobs': u.no_jobs,
             'percent': i_percent,
             'quota_percent': quota_percent,
             })

    if i_usage > 0:
        person_percent = (person_total / i_usage) * 100
    else:
        person_percent = None

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

    return render_to_response(
        'usage/usage_institute_detail.html', locals(),
        context_instance=RequestContext(request))