示例#1
0
def gen_all_project_graphs(period):
    """ Generate all project graph for list period days. """
    from karaage.machines.models import MachineCategory
    from karaage.projects.models import Project
    from karaage.usage.graphs import get_project_trend_graph_url
    import datetime

    project_list = Project.objects.all()

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

    for project in project_list.all():
        for machine_category in MachineCategory.objects.all():
            get_project_trend_graph_url(project, start, end, machine_category, force_overwrite=True)
示例#2
0
文件: views.py 项目: russell/karaage
def project_usage(request, project_id, machine_category_id):

    machine_category = get_object_or_404(MachineCategory, pk=machine_category_id)
    project = get_object_or_404(Project, pid=project_id)

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

    usage_list = []
    total, total_jobs = 0, 0

    start, end = get_date_range(request)
    start_str = start.strftime('%Y-%m-%d')
    end_str = end.strftime('%Y-%m-%d')

    # Custom SQL as need to get users that were removed from project too
    rows = CPUJob.objects.filter(
            project=project,
            machine__category=machine_category,
            date__range=(start_str, end_str)
            ).values('account').annotate().order_by('account')

    for row in rows:
        u = Account.objects.get(id=row['account']).person
        time, jobs = u.get_usage(project, start, end, machine_category)
        if time:
            total += time
            total_jobs += jobs
            if jobs > 0:
                usage_list.append({'person': u, 'usage': time, 'jobs': jobs})

    for u in usage_list:
        if total == 0:
            u['percent'] = 0
        else:
            u['percent'] = (u['usage'] / total) * 100

    usage_list = dictsortreversed(usage_list, 'usage')

    count = 0
    for i in usage_list:
        i['colour'] = get_colour(count)
        count += 1

    graph = get_project_trend_graph_url(project, start, end, machine_category)

    return render_to_response('usage/project_usage.html', locals(), context_instance=RequestContext(request))
示例#3
0
def project_usage(request, project_id, machine_category_id):
    machine_category = get_object_or_404(
        MachineCategory, pk=machine_category_id)
    project = get_object_or_404(Project, pid=project_id)

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

    result = progress(request)
    if result is not None:
        return result

    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_project(
        request, start, end, project, machine_category)
    if result is not None:
        return render_to_response(
            'usage/progress.html',
            {'task_id': result.task_id},
            context_instance=RequestContext(request))

    usage_list = []
    total, total_jobs = 0, 0

    # Custom SQL as need to get users that were removed from project too
    query = CPUJob.objects.filter(
        project=project,
        machine__category=machine_category,
        date__range=(start, end)
    )
    query = query.values('account').annotate().order_by('account')

    for row in query:
        u = Account.objects.get(id=row['account']).person
        time, jobs = usage.get_person_usage(
            u, project, start, end, machine_category)
        if time:
            total += time
            total_jobs += jobs
            if jobs > 0:
                usage_list.append({'person': u, 'usage': time, 'jobs': jobs})

    for u in usage_list:
        if total == 0:
            u['percent'] = 0
        else:
            u['percent'] = (u['usage'] / total) * 100

    usage_list = dictsortreversed(usage_list, 'usage')

    count = 0
    for i in usage_list:
        i['colour'] = graphs.get_colour(count)
        count += 1

    graph = graphs.get_project_trend_graph_url(
        project, start, end, machine_category)

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