예제 #1
0
def GeneratePdf_of_all_user(request):
    if request.user.is_superuser:
        dataSource = {}
        dataSource['data'] = []
        numbers = []
        for user in User.objects.all():
                data = {}
                data['weight_loss_per'] = calc_total_loss_per(user, user.userprofileinfo.current_weight)
                data['weight_loss']  = calc_total_loss(user, user.userprofileinfo.current_weight)
                data ['user'] = user
                numbers.append(data['weight_loss_per'])
                dataSource['data'].append(data)

        avg = round((mean(numbers)), 2)
        std = round(stdev(numbers), 2)
        med = round(median(numbers), 2)
        numbers.clear()
      #  numbers = {'avg': avg, 'std': std, 'med': med}

        for data in dataSource['data']:
            numbers.append((data.get('weight_loss')))

        avg2 = round((mean(numbers)), 2)
        std2 = round(stdev(numbers), 2)
        med2 = round(median(numbers), 2)

        numbers = {'avg': avg, 'std': std, 'med': med, 'avg2' : avg2, 'std2' : std2, 'med2': med2}

        pdf = render_to_pdf('accounts/all_users_report.html',
                            {'data': dataSource, 'numbers': numbers})

        return HttpResponse(pdf, content_type='application/pdf')

    else:
        return render(request, 'accounts/reports.html')
예제 #2
0
def  GeneratePdf(request, username):
        user = User.objects.get(username=username)
        dataSource = {}
        dataSource['data'] = []
        date = filter(request, False)
        current = user.userprofileinfo.current_weight
        list = list_of_weight_loss(date, user)

        if not list:
            messages.error(request, 'No data on this date.')
            return HttpResponseRedirect(reverse("accounts:reports_page", kwargs={"username": username}))
        for k in list:
                data = {}
                data['body_fat']= k.body_fat
                data['weight'] = k.weight
                data['timestamp'] = k.timestamp
                current = k.weight
                dataSource['data'].append(data)
        if (isinstance(date, datetime.date)):
            year = myconverter_year(date)
            type = date.strftime('%B') + " " + year
        else:
            type =date
        total = calc_total_loss(user, current)
        total_in_per = calc_total_loss_per(user, current)
        bmi = calc_bmi(user.userprofileinfo)
        pdf = render_to_pdf('accounts/pdf_template.html',
                                        {'data': dataSource, 'total': total, 'total_in_per': total_in_per,
                                         'bmi': bmi, 'user': user, 'type': type })

        return HttpResponse(pdf, content_type='application/pdf')
예제 #3
0
def ActivityLogReport(request):
    if request.user.is_superuser:
        dataSource = {}
        numbers= []
        dataSource['data'] = []
        if request.method == "POST":
            form = FilterDate(request.POST, instance=request.user.userprofileinfo)
            if form.is_valid():
                time = form.cleaned_data.get('timestamp')
                month = myconverter_month(time)
                year = myconverter_year(time)
                type = time.strftime('%B') + " " + year
                for user in User.objects.all():
                    data = {}
                    data['label'] = user
                    data['post'] = Post.objects.filter(user=user, created_at__month=month, created_at__year=year).count()
                    data ['like'] = Like.objects.filter(user=user, date__month=month, date__year=year).count()
                    data['follow'] = GroupMember.objects.filter(user=user, date__month=month, date__year=year).count()
                    data['comment'] =  Comment.objects.filter(user=user, timestamp__month=month, timestamp__year=year).count()
                    data['value'] = data['post'] + data['like'] + data['comment'] + data['follow']
                    dataSource['data'].append(data)
                    numbers.append(data['value'])

            avg = round(mean(numbers), 2)
            pdf = render_to_pdf('accounts/Activity_log_report.html', {'data': dataSource, 'avg' : avg, 'type': type})

            return HttpResponse(pdf, content_type='application/pdf')
예제 #4
0
def GeneratePdf_of_all_user(request):
    if request.user.is_superuser:
        dataSource = {}
        dataSource['data'] = []
        numbers1 = []
        numbers2 = []
        for user in User.objects.all():
                data = {}
                data['weight_loss_per'] = calc_total_loss_per(user, user.userprofileinfo.current_weight)
                data['weight_loss']  = calc_total_loss(user, user.userprofileinfo.current_weight)
                data ['user'] = user
                numbers1.append(data['weight_loss_per'])
                numbers2.append(data['weight_loss'])
                dataSource['data'].append(data)
        if numbers1.__len__() >=  2:
            numbers1 = numbers(numbers1)
        if numbers2.__len__() >=2:
            numbers2 = numbers(numbers2)

        pdf = render_to_pdf('accounts/all_users_report.html',
                            {'data': dataSource, 'numbers1': numbers1, 'numbers2': numbers2})

        return HttpResponse(pdf, content_type='application/pdf')

    else:
        return render(request, 'accounts/reports.html')
예제 #5
0
def  GeneratePdf(request, username):
        user = User.objects.get(username=username)
        dataSource = {}
        dataSource['data'] = []

        if request.method == "POST":
            form = FilterDate(request.POST, instance=request.user.userprofileinfo)
            if form.is_valid():

                time = form.cleaned_data.get('timestamp')
                month = myconverter_month(time)
                year = myconverter_year(time)
                list = user.userprofileinfo.weight_history.filter(timestamp__year=year, timestamp__month=month)
                type  = time
                if not list:

                    return render(request, 'accounts/reports.html')

        elif request.GET.get('year'):
                year = (request.GET.get('year'))
                list = user.userprofileinfo.weight_history.filter(timestamp__year=year)
                type = year
                if not list :
                    return render(request, 'accounts/reports.html')
        else:
                return render(request, 'accounts/reports.html')

        for k in list:
                data = {}
                data['body_fat']= k.body_fat
                data['weight'] = k.weight
                data['timestamp'] = k.timestamp
                current = k.weight
                dataSource['data'].append(data)

        total = calc_total_loss(user, current)
        total_in_per = calc_total_loss_per(user, current)
        bmi = calc_bmi(user.userprofileinfo)
        print(data)
        pdf = render_to_pdf('accounts/pdf_template.html',
                                        {'data': dataSource, 'total': total, 'total_in_per': total_in_per,
                                         'bmi': bmi, 'user': user, 'type': type })

        return HttpResponse(pdf, content_type='application/pdf')