def get_count_for_yes_no_response_by_school(polls, locations, time_range): yes_result = ( Response.objects.filter( poll__in=polls, has_errors=False, message__direction="I", date__range=time_range, eav_values__value_text__in=["Yes", "YES", "yes"], contact__reporting_location__in=locations, ) .values("contact__emisreporter__schools") .annotate(total=Count("contact__emisreporter__schools")) ) no_result = ( Response.objects.filter( poll__in=polls, has_errors=False, message__direction="I", date__range=time_range, eav_values__value_text__in=["No", "NO", "no"], contact__reporting_location__in=locations, ) .values("contact__emisreporter__schools") .annotate(total=Count("contact__emisreporter__schools")) ) yes_totals = [(result["contact__emisreporter__schools"], result["total"] or 0) for result in yes_result] no_totals = [(result["contact__emisreporter__schools"], result["total"] or 0) for result in no_result] return collapse(yes_totals), collapse(no_totals)
def get_count_deployed_head_teachers_by_school(dataSource): heads = EmisReporter.objects.filter(schools__in=dataSource.values_list('schools', flat=True), groups__name='Head Teachers').values('schools') \ .order_by().annotate(total=Count('schools')) school_totals = [(result['schools'], result['total'] or 0) for result in heads] return collapse(school_totals)
def get_count_gender_deployed_head_teachers_by_location(dataSource, gender): gendered_heads = EmisReporter.objects.filter(schools__in=dataSource.values_list('schools', flat=True), groups__name='Head Teachers', gender=gender, ).values( 'reporting_location') \ .order_by().annotate(total=Count('reporting_location')) location_totals = [(result['reporting_location'], result['total'] or 0) for result in gendered_heads] return collapse(location_totals)
def get_count_gender_deployed_head_teachers_by_location(dataSource, gender): gendered_heads = ( EmisReporter.objects.filter( schools__in=dataSource.values_list("schools", flat=True), groups__name="Head Teachers", gender=gender ) .values("reporting_location") .order_by() .annotate(total=Count("reporting_location")) ) location_totals = [(result["reporting_location"], result["total"] or 0) for result in gendered_heads] return collapse(location_totals)
def get_count_deployed_head_teachers_by_school(dataSource): heads = ( EmisReporter.objects.filter( schools__in=dataSource.values_list("schools", flat=True), groups__name="Head Teachers" ) .values("schools") .order_by() .annotate(total=Count("schools")) ) school_totals = [(result["schools"], result["total"] or 0) for result in heads] return collapse(school_totals)
def get_count_for_yes_no_response_by_school(polls, locations, time_range): yes_result = Response.objects.filter(poll__in=polls, has_errors=False, message__direction='I', date__range=time_range, eav_values__value_text__in=['Yes', 'YES', 'yes'], contact__reporting_location__in=locations) \ .values('contact__emisreporter__schools').annotate(total=Count('contact__emisreporter__schools')) no_result = Response.objects.filter(poll__in=polls, has_errors=False, message__direction='I', date__range=time_range, eav_values__value_text__in=['No', 'NO', 'no'], contact__reporting_location__in=locations) \ .values('contact__emisreporter__schools').annotate(total=Count('contact__emisreporter__schools')) yes_totals = [(result['contact__emisreporter__schools'], result['total'] or 0) for result in yes_result] no_totals = [(result['contact__emisreporter__schools'], result['total'] or 0) for result in no_result] return collapse(yes_totals), collapse(no_totals)
def gendered_text_responses_by_school(date_weeks, locations, options, gender): poll = Poll.objects.get(name='edtrac_head_teachers_attendance') gendered_schools = EmisReporter.objects.filter(reporting_location__in=locations, gender=gender, groups__name="Head Teachers") \ .exclude(schools=None) \ .values('reporting_location__id') results = Response.objects.filter(poll=poll, has_errors=False, message__direction='I', date__range=date_weeks, eav_values__value_text__in=options, contact__reporting_location__id__in=gendered_schools) \ .values('contact__emisreporter__schools') \ .annotate(total=Count('contact__emisreporter__schools')) school_totals = [(result['contact__emisreporter__schools'], result['total'] or 0) for result in results] return collapse(school_totals)
def gendered_text_responses_by_school(date_weeks, locations, options, gender): poll = Poll.objects.get(name="edtrac_head_teachers_attendance") gendered_schools = ( EmisReporter.objects.filter(reporting_location__in=locations, gender=gender, groups__name="Head Teachers") .exclude(schools=None) .values("reporting_location__id") ) results = ( Response.objects.filter( poll=poll, has_errors=False, message__direction="I", date__range=date_weeks, eav_values__value_text__in=options, contact__reporting_location__id__in=gendered_schools, ) .values("contact__emisreporter__schools") .annotate(total=Count("contact__emisreporter__schools")) ) school_totals = [(result["contact__emisreporter__schools"], result["total"] or 0) for result in results] return collapse(school_totals)