예제 #1
0
파일: forms.py 프로젝트: krelamparo/edtrac
    def __init__(self, *args, **kwargs):
        super(EditReporterForm, self).__init__(*args, **kwargs)
        instance = kwargs['instance']
        data = kwargs.get('data')
        self.fields['reporting_location'] = forms.ModelChoiceField(
            queryset=Location.objects.filter(type='district').order_by('name'))

        if instance and data:
            edited_school = School.objects.none()
            schools_in_reporting_location = School.objects.filter(location=instance.reporting_location)
            if not is_empty(data.get('schools')):
                edited_school = School.objects.filter(pk=data.get('schools'))
            self.fields['schools'] = forms.ModelChoiceField(queryset=schools_in_reporting_location | edited_school)
        elif instance.reporting_location is None:
            if instance.schools.count() == 0:
                self.fields['schools'] = forms.ModelChoiceField(queryset=School.objects.none(),
                                                                widget=forms.Select(attrs={'disabled': 'disabled'}))
            else:
                self.fields['schools'] = forms.ModelChoiceField(queryset=instance.schools.all())
        else:
            schools_in_reporting_location = School.objects.filter(location=instance.reporting_location)
            if instance.schools.all().exists() and instance.schools.all()[0] not in schools_in_reporting_location:
                self.fields['schools'] = forms.ModelChoiceField(
                    queryset=schools_in_reporting_location | instance.schools.all())
            else:
                self.fields['schools'] = forms.ModelChoiceField(queryset=schools_in_reporting_location)

        self.fields['schools'].required = False
        self.fields['gender'].required = False
        self.fields['grade'].required = False
예제 #2
0
def get_responses_by_location(locations, config_list, date_weeks):
    attendance_poll_names = config_list['attendance_poll']
    enrollment_poll_names = config_list['enrollment_poll']
    total_enrollment = 0
    total_enrollment_by_location = defaultdict(lambda: 0)
    total_present_by_location = defaultdict(lambda: 0)
    total_present_by_time = []
    total_enrollment_by_time = []
    school_percent = 0
    for index, attendance_poll_name in enumerate(attendance_poll_names):

        filtered_responses, filtered_enrollment, percent = get_responses_over_depth(
            attendance_poll_name, enrollment_poll_names[index],
            list(locations), date_weeks)

        transformed_enrollment = transform([filtered_enrollment], locations)
        if not is_empty(transformed_enrollment[0]):
            transformed_responses = transform(filtered_responses, locations)
            get_aggregated_result(
                total_present_by_location,
                get_aggregation_by_location(transformed_responses))
            get_aggregated_result(
                total_enrollment_by_location,
                get_aggregation_by_location(transformed_enrollment))
            total_enrollment += sum(total_enrollment_by_location.values())
            get_aggregated_list(
                total_enrollment_by_time,
                get_agrregated_enrollment_by_time(total_enrollment_by_location,
                                                  transformed_responses))

            get_aggregated_list(total_present_by_time,
                                get_aggregation_by_time(transformed_responses))
        school_percent += percent
    school_percent /= len(attendance_poll_names)
    absent_by_time = [
        round(compute_percent_out_of_total(value, total_enrollment_by_time[i]),
              2) for i, value in enumerate(total_present_by_time)
    ]

    absent_by_location = {}
    for key in total_present_by_location:
        absent_by_location[key] = round(
            compute_percent_out_of_total(
                total_present_by_location[key],
                total_enrollment_by_location[key] * len(date_weeks)), 2)

    return absent_by_location, absent_by_time, school_percent
예제 #3
0
    def __init__(self, *args, **kwargs):
        super(EditReporterForm, self).__init__(*args, **kwargs)
        instance = kwargs['instance']
        data = kwargs.get('data')
        self.fields['reporting_location'] = forms.ModelChoiceField(
            queryset=Location.objects.filter(type='district').order_by('name'))

        if instance and data:
            edited_school = School.objects.none()
            schools_in_reporting_location = School.objects.filter(
                location=instance.reporting_location)
            if not is_empty(data.get('schools')):
                edited_school = School.objects.filter(pk=data.get('schools'))
            self.fields['schools'] = forms.ModelChoiceField(
                queryset=schools_in_reporting_location | edited_school)
        elif instance.reporting_location is None:
            if instance.schools.count() == 0:
                self.fields['schools'] = forms.ModelChoiceField(
                    queryset=School.objects.none(),
                    widget=forms.Select(attrs={'disabled': 'disabled'}))
            else:
                self.fields['schools'] = forms.ModelChoiceField(
                    queryset=instance.schools.all())
        else:
            schools_in_reporting_location = School.objects.filter(
                location=instance.reporting_location)
            if instance.schools.all().exists() and instance.schools.all(
            )[0] not in schools_in_reporting_location:
                self.fields['schools'] = forms.ModelChoiceField(
                    queryset=schools_in_reporting_location
                    | instance.schools.all())
            else:
                self.fields['schools'] = forms.ModelChoiceField(
                    queryset=schools_in_reporting_location)

        self.fields['schools'].required = False
        self.fields['gender'].required = False
        self.fields['grade'].required = False
예제 #4
0
def latest(reporter):
    if not is_empty(reporter.responses.all()):
        return reporter.responses.exclude(poll=None).latest('date').date
예제 #5
0
def latest(reporter):
    if not is_empty(reporter.responses.all()):
        return reporter.responses.exclude(poll=None).latest('date').date