Beispiel #1
0
    def get(self, request, *args, **kwargs):
        '''
        Pass any permissable GET data.  URL parameters override GET parameters
        '''
        try:
            year = int(self.kwargs.get('year'))
        except (ValueError, TypeError):
            year = getIntFromGet(request, 'year')

        if self.kwargs.get('month'):
            try:
                month = int(self.kwargs.get('month'))
            except (ValueError, TypeError):
                try:
                    month = list(month_name).index(
                        self.kwargs.get('month').title())
                except (ValueError, TypeError):
                    month = None
        else:
            month = getIntFromGet(request, 'month')

        kwargs.update({
            'year': year,
            'month': month,
            'startDate': getDateTimeFromGet(request, 'startDate'),
            'endDate': getDateTimeFromGet(request, 'endDate'),
            'basis': request.GET.get('basis'),
        })

        if kwargs.get('basis') not in EXPENSE_BASES.keys():
            kwargs['basis'] = 'accrualDate'

        context = self.get_context_data(**kwargs)
        return self.render_to_response(context)
Beispiel #2
0
def ClassCountHistogramCSV(request):
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="studentHistogramData.csv"'

    cohortStart = getDateTimeFromGet(request,'cohortStart')
    cohortEnd = getDateTimeFromGet(request,'cohortEnd')
    results = getClassCountHistogramData(cohortStart=cohortStart,cohortEnd=cohortEnd)

    writer = csv.writer(response)

    # Note: These are not translated because the chart Javascript looks for these keys
    header_row = ['# of Classes']

    keys = OrderedDict()
    for v in results.values():
        keys.update(v)

    header_row += [x for x in keys.keys()]
    writer.writerow(header_row)

    for k,v in results.items():
        this_row = [k]
        this_row += [v.get(x,None) for x in keys.keys()]
        writer.writerow(this_row)

    return response
Beispiel #3
0
    def get(self,request,*args,**kwargs):
        '''
        Pass any permissable GET data.  URL parameters override GET parameters
        '''
        try:
            year = int(self.kwargs.get('year'))
        except (ValueError, TypeError):
            year = getIntFromGet(request,'year')

        if self.kwargs.get('month'):
            try:
                month = int(self.kwargs.get('month'))
            except (ValueError, TypeError):
                try:
                    month = list(month_name).index(self.kwargs.get('month').title())
                except (ValueError, TypeError):
                    month = None
        else:
            month = getIntFromGet(request,'month')

        kwargs.update({
            'year': year,
            'month': month,
            'startDate': getDateTimeFromGet(request,'startDate'),
            'endDate': getDateTimeFromGet(request,'endDate'),
            'basis': request.GET.get('basis'),
        })

        if kwargs.get('basis') not in EXPENSE_BASES.keys():
            kwargs['basis'] = 'accrualDate'

        context = self.get_context_data(**kwargs)
        return self.render_to_response(context)
Beispiel #4
0
def LocationPerformanceJSON(request):
    startDate = getDateTimeFromGet(request,'startDate')
    endDate = getDateTimeFromGet(request,'endDate')
    results = getLocationPerformance(startDate,endDate)

    # Needs to return a list, not a dict
    results_list = [dict({'name': k},**dict(v)) for k,v in results.items()]
    return JsonResponse(results_list,safe=False)
Beispiel #5
0
def ClassCountHistogramJSON(request):
    cohortStart = getDateTimeFromGet(request,'cohortStart')
    cohortEnd = getDateTimeFromGet(request,'cohortEnd')
    results = getClassCountHistogramData(cohortStart=cohortStart,cohortEnd=cohortEnd)

    # Needs to return a sorted list, not a dict
    results_list = [dict({'bin_label': k},**dict(v)) for k,v in results.items()]
    sorted_list = sorted(results_list, key=lambda k: k['bin'][0])

    return JsonResponse(sorted_list,safe=False)
Beispiel #6
0
def AveragesByClassTypeJSON(request):

    startDate = getDateTimeFromGet(request,'startDate')
    endDate = getDateTimeFromGet(request,'endDate')

    results = getAveragesByClassType(startDate,endDate)

    # Needs to return a list, not a dict
    # Also, filter out types with no series or registrations
    # and sort descending
    results_list = [dict({'type': k},**dict(v)) for k,v in results.items() if v.get(str(_('Series'))) or v.get(str(_('Registrations')))]
    sorted_list = sorted(results_list, key=lambda k: k[str(_('Series'))],reverse=True)
    return JsonResponse(sorted_list,safe=False)
Beispiel #7
0
def discountFrequencyJSON(request):
    startDate = getDateTimeFromGet(request,'startDate')
    endDate = getDateTimeFromGet(request,'endDate')

    timeLimit = Q()

    if startDate:
        timeLimit = timeLimit & Q(dateTime__gte=startDate)
    if endDate:
        timeLimit = timeLimit & Q(dateTime__lte=endDate)

    # Percentage of registrations using discounts
    discounts_counter_sorted = sorted(Counter(Registration.objects.filter(timeLimit).annotate(
        discounts_applied=Count('registrationdiscount')).values_list('discounts_applied',flat=True)).items())

    results_list = [{'discounts': x[0], 'count': x[1]} for x in discounts_counter_sorted]
    return JsonResponse(results_list,safe=False)
Beispiel #8
0
def popularDiscountsJSON(request):
    startDate = getDateTimeFromGet(request,'startDate')
    endDate = getDateTimeFromGet(request,'endDate')

    timeLimit = Q(registrationdiscount__registration__dateTime__isnull=False)

    if startDate:
        timeLimit = timeLimit & Q(registrationdiscount__registration__dateTime__gte=startDate)
    if endDate:
        timeLimit = timeLimit & Q(registrationdiscount__registration__dateTime__lte=endDate)

    uses = list(DiscountCombo.objects.annotate(
        counter=Count(Case(
            When(timeLimit, then=1), output_field=IntegerField())
        )).filter(counter__gt=0).values('name','counter').order_by('-counter')[:10])

    return JsonResponse(uses,safe=False)
Beispiel #9
0
def popularVouchersJSON(request):
    startDate = getDateTimeFromGet(request, 'startDate')
    endDate = getDateTimeFromGet(request, 'endDate')

    timeLimit = Q(voucheruse__creationDate__isnull=False)

    if startDate:
        timeLimit = timeLimit & Q(voucheruse__creationDate__gte=startDate)
    if endDate:
        timeLimit = timeLimit & Q(voucheruse__creationDate__lte=endDate)

    uses = list(
        Voucher.objects.annotate(counter=Count(
            Case(When(timeLimit, then=1),
                 output_field=IntegerField()))).filter(counter__gt=0).values(
                     'name', 'counter', 'voucherId').order_by('-counter')[:10])

    return JsonResponse(uses, safe=False)
Beispiel #10
0
def AveragesByClassTypeCSV(request):
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="averagesByClassDescriptionType.csv"'

    writer = csv.writer(response)

    startDate = getDateTimeFromGet(request,'startDate')
    endDate = getDateTimeFromGet(request,'endDate')

    results = getAveragesByClassType(startDate,endDate)

    role_names = [x.replace(str(_('Average ')),'') for x in results.keys() if x.startswith(str(_('Average ')))]

    header_list = [str(_('Class Type')),str(_('Total Classes')),str(_('Total Students')),str(_('Avg. Students/Class'))]
    for this_role in role_names:
        header_list += [str(_('Total %s' % this_role)), str(_('Avg. %s/Class' % this_role))]

    # Note: These are not translated because the chart Javascript looks for these keys
    writer.writerow(header_list)

    for key,value in results.items():
        this_row = [
            key,
            value.get(str(_('Series')),0),
            value.get(str(_('Registrations')),0),
            value.get(str(_('Average Registrations')),None),
        ]
        for this_role in role_names:
            this_row += [
                value.get(str(_('Total %s' % this_role)), 0),
                value.get(str(_('Average %s' % this_role)), 0)
            ]
        writer.writerow(this_row)

    return response
Beispiel #11
0
def LocationPerformanceCSV(request):
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="locationPerformance.csv"'

    startDate = getDateTimeFromGet(request,'startDate')
    endDate = getDateTimeFromGet(request,'endDate')

    results = getLocationPerformance(startDate,endDate)

    writer = csv.writer(response)

    # Note: These are not translated because the chart Javascript looks for these keys
    writer.writerow(['Location','# Series','# Students','Avg. Students/Series'])

    for location,data in results.items():
        writer.writerow([
            location,  # The location name
            data.get('series',0),  # The num. of series taught there
            data.get('registrations',0),  # The num. of students taught there
            float(data.get('registrations',0)) / data.get('series',1)
        ])

    return response
Beispiel #12
0
def RegistrationReferralCountsJSON(request):
    startDate = getDateTimeFromGet(request,'startDate')
    endDate = getDateTimeFromGet(request,'endDate')
    results = getRegistrationReferralCounts(startDate,endDate)
    return JsonResponse(results,safe=False)