Example #1
0
def institute_users(request, institute_id, machine_category_id=1):

    machine_category = MachineCategory.objects.get(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)

    user_list = []

    user_total, user_total_jobs = 0, 0
    for u in UserCache.objects.order_by('-cpu_hours').filter(start=start, end=end).filter(project__machine_categories=machine_category).filter(user__institute=institute).filter(no_jobs__gt=0):
        user_total = user_total + u.cpu_hours
        user_total_jobs = user_total_jobs + u.no_jobs
        user_list.append({'user': u.user, 'project': u.project, 'usage': u.cpu_hours, 'jobs': u.no_jobs, 'percent': ((u.cpu_hours / available_time) * 100)})
        
    try:
        user_percent = (user_total / available_time) * 100
    except:
        user_percent = 0
    
    querystring = request.META.get('QUERY_STRING', '')
    
    return render_to_response('usage/institute_users.html', locals(), context_instance=RequestContext(request))
Example #2
0
    def get_mpots(self, start=datetime.date.today()-datetime.timedelta(days=90), end=datetime.date.today()):
        from karaage.util.helpers import get_available_time

        TWOPLACES = Decimal(10) ** -2
        usage, jobs = self.project.get_usage(start, end)
        if usage is None:
            usage = Decimal('0')
        total_time, ave_cpus = get_available_time()
        if total_time == 0:
            return 0
        return ((Decimal(usage) / total_time) * 100 * 1000).quantize(TWOPLACES)
Example #3
0
    def gen_institutes_pie(self, start, end, machine_category):
        """Generates a pie graph showing all active institutes usage
    
        Keyword arguments:
        start -- start date
        end -- end date
        machine_category -- MachineCategory object
        
        """
        
        start_str = start.strftime('%Y-%m-%d')
        end_str = end.strftime('%Y-%m-%d')
        
        institute_list = Institute.active.all()
        
        available_time, avg_cpus = get_available_time(start, end, machine_category)
        
        myPie = gdchart.Pie()
        myPie.width = 500
        myPie.height = 500
        myPie.title = "Institutes Usage - (%s - %s) - %s" % (start_str, end_str, machine_category.name) 
        myPie.bg_color = "white"
        data = []
        labels = []
        total = 0
        for i in institute_list:  
            usage = i.get_usage(start, end, machine_category)
            if usage[0] is not None:
                total = total + int(usage[0])
                data.append(int(usage[0]))
                labels.append(i.name)

        data.append(int(available_time - total))
        labels.append('Unused')
        data = tuple(data)
        
        myPie._datalen = len(data)
        myPie._data = data
        myPie._conformanceCheck()
        
        myPie.setLabels(labels)
        
        #myPie.explode = [10,10,10,10,10,10,10,10,10,10]

        myPie.color = ["red", "green", "yellow", "orange", "blue", "red", "green", "yellow", "orange", "blue"]

        try:
            myPie.draw("%s/institutes/%s-%s_%i.png" % (settings.GRAPH_ROOT, start_str, end_str, machine_category.id))
        except:
            pass
Example #4
0
def top_users(request, machine_category_id=settings.DEFAULT_MC, 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)
    user_list = []

    user_total, user_total_jobs = 0, 0
    for u in UserCache.objects.order_by('-cpu_hours').filter(start=start, end=end).filter(project__machine_categories=machine_category)[:count]:
        if u.cpu_hours:
            user_total += u.cpu_hours
            user_total_jobs += u.no_jobs
            user_list.append({'user': u.user, 'project': u.project, 'usage': u.cpu_hours, 'jobs': u.no_jobs, 'percent': ((u.cpu_hours / available_time) * 100)})
        
    user_percent = (user_total / available_time) * 100
    querystring = request.META.get('QUERY_STRING', '')
    
    return render_to_response('usage/top_users.html', locals(), context_instance=RequestContext(request))
Example #5
0
def index(request, machine_category_id=settings.DEFAULT_MC):

    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=settings.DEFAULT_MC)
    
    show_zeros = True

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

    querystring = request.META.get('QUERY_STRING', '')

    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
        if jobs > 0:
            m_list.append({'machine': m, 'usage': time, 'jobs': jobs})
            
    for i in institute_list:
        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 = InstituteChunk.objects.get(institute=i, machine_category=machine_category)
            display_quota = quota.quota
        except InstituteChunk.DoesNotExist:
            display_quota = None
        if display_quota or jobs > 0:
            data_row = {'institute': i, 'usage': time, 'jobs': jobs, 'quota': display_quota}
            try:
                data_row['percent'] = Decimal(time) / Decimal(available_time) * 100
            except ZeroDivisionError:
                data_row['percent'] = 0
            if data_row['quota'] is not None:
                try:
                    data_row['p_used'] = (data_row['percent'] / data_row['quota']) * 100
                except ZeroDivisionError:
                    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'

    try:
        utilization = (Decimal(total) / available_time) * 100
    except ZeroDivisionError:
        utilization = 0
    except:
        utilization = 0
        
    try:
        graph = get_institute_graph_url(start, end, machine_category)
        trend_graph = get_trend_graph_url(start, end, machine_category)
    except:
        pass

    return render_to_response('usage/usage_institue_list.html', locals(), context_instance=RequestContext(request))
Example #6
0
def institute_usage(request, institute_id, machine_category_id=settings.DEFAULT_MC):

    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)

    querystring = request.META.get('QUERY_STRING', '')

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

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

    if i_jobs > 0:

        for p in institute.project_set.filter(machine_categories=machine_category):
            p_usage, p_jobs = p.get_usage(start, end, machine_category)
            chunk, created = p.projectchunk_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,
                     })

        user_list = []
        user_total, user_total_jobs = 0, 0
        if i_usage:
            for u in UserCache.objects.order_by('-cpu_hours').filter(start=start, end=end).filter(project__institute=institute).filter(project__machine_categories=machine_category)[:5]:
                if not u.cpu_hours:
                    continue
                user_total += u.cpu_hours
                user_total_jobs += u.no_jobs
                try:
                    quota_percent = u.cpu_hours / (available_usage * quota.quota) * 10000
                except ZeroDivisionError:
                    quota_percent = 0
                user_list.append(
                    {'user': u.user,
                     'project': u.project,
                     'usage': u.cpu_hours,
                     'jobs': u.no_jobs,
                     'percent': ((u.cpu_hours / i_usage) * 100),
                     'quota_percent': quota_percent,
                     })
                
            user_percent = (user_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))
Example #7
0
 def do_availablity_test(self, start, end, mc, expected_time, expected_cpu):
     from karaage.util.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)