Пример #1
0
def standing():
    response_data = {}
    response_data['month'] = getRangeEnd().strftime('%B')
    response_data['year'] = getRangeEnd().year
    orderedLunches = CompanyLunch.objects.order_by('date')
    startDate = orderedLunches[0].date
    endDate = orderedLunches[1].date
    workoutsInRange = Workout.objects.filter(date__gte = startDate, date__lte = endDate)
    rackers = workoutsInRange.values_list('racker', flat=True).distinct()
    users = list()
    for rackerID in rackers:
        user = {}
        tempRacker = Racker.objects.get(pk=rackerID)
        user['email'] = tempRacker.name
        user['score'] = workoutsInRange.filter(racker=tempRacker).count()
        users.append(user)
    response_data['users'] = sorted(users, key=itemgetter('score'), reverse=True)
    return response_data
def getStanding():
    rackerlist = Racker.objects.all()
    names = []
    w = []
    start = getRangeStart()
    end = getRangeEnd()
    for racker in rackerlist:
        email = racker.email
        print email
        name = racker.name
        print name
        names.append(name)
        workouts = sumPersonalWorkouts(start,end,email)
        print workouts
        w.append(workouts)
        #temp = standing(email,workouts)
        #temp = standing(racker.email, sumPersonalWorkouts(start,end,racker.email)
       # cells.append(temp)
       # cells.append(temp)
    z = zip(w,names)
    sorted(z,reverse=True)
    return z 
def getPercentage():
    rackerlist = Racker.objects.all()
    total_workout = len(Workout.objects.all())
    print total_workout
    names = []
    counter = 0
    percentagelist = []
    start = getRangeStart()
    end = getRangeEnd()
    for racker in rackerlist:
        email = racker.email
        name = racker.name
        names.append(name)
        workouts = sumPersonalWorkouts(start,end,email)
        percentage = 100*float(workouts)/(float(total_workout))
        counter += percentage
        percentagelist.append(percentage)
        #temp = standing(email,workouts)
        #temp = standing(racker.email, sumPersonalWorkouts(start,end,racker.email)
       # cells.append(temp)
       # cells.append(temp)
    z = zip(percentagelist,names)
    sorted(z,reverse=True)
    return z