Пример #1
0
    def get_context_data(self, **kwargs):
        t = self.get_tournament()
        r = self.get_round()

        draw = r.debate_set_with_prefetches(ordering=("room_rank",), speakers=False, divisions=False)

        teams = Team.objects.filter(debateteam__debate__round=r).prefetch_related("speaker_set")
        adjs = get_adjs(self.get_round())

        regions = regions_ordered(t)
        categories = categories_ordered(t)
        adjs, teams = populate_conflicts(adjs, teams)
        adjs, teams = populate_histories(adjs, teams, t, r)

        kwargs["allRegions"] = json.dumps(regions)
        kwargs["allCategories"] = json.dumps(categories)
        kwargs["allDebates"] = debates_to_json(draw, t, r)
        kwargs["allTeams"] = teams_to_json(teams, regions, categories, t, r)
        kwargs["allAdjudicators"] = adjs_to_json(adjs, regions, t)

        return super().get_context_data(**kwargs)
Пример #2
0
def get_diversity_data_sets(t, for_public):

    all_regions = regions_ordered(t)
    region_filters = [{r['seq']:r['name']} for r in all_regions]

    data_sets = {
        'speakers_gender': [],
        'speakers_region': [],
        'speakers_results': [],
        'detailed_speakers_results': [],
        'adjudicators_gender': [],
        'adjudicators_region': [],
        'adjudicators_results': [],
        'detailed_adjudicators_results': [],
        'regions': all_regions  # For CSS
    }

    # ==========================================================================
    # Speakers Demographics
    # ==========================================================================

    if Speaker.objects.filter(team__tournament=t).count() > 0:
        data_sets['speakers_gender'].append(compile_data(
            'All', Speaker.objects.filter(team__tournament=t), 'gender', filters=[
                {'Unknown':  None},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                {'Male':     Person.GENDER_MALE},
            ], count=True))

    if Speaker.objects.filter(team__tournament=t).filter(team__breakingteam__isnull=False).count() > 0:
        data_sets['speakers_gender'].append(compile_data(
            'Breaking', Speaker.objects.filter(team__tournament=t, team__breakingteam__isnull=False), 'gender', filters=[
                {'Unknown':  None},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                {'Male':     Person.GENDER_MALE},
            ], count=True))

    if Speaker.objects.filter(team__tournament=t).filter(novice=True).count() > 0:
        data_sets['speakers_gender'].append(compile_data(
            'Pros', Speaker.objects.filter(team__tournament=t, novice=False), 'gender', filters=[
                {'Unknown':  None},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                {'Male':     Person.GENDER_MALE},
            ], count=True))
        data_sets['speakers_gender'].append(compile_data(
            'Novices', Speaker.objects.filter(team__tournament=t, novice=True), 'gender', filters=[
                {'Unknown':  None},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                {'Male':     Person.GENDER_MALE},
            ], count=True))

    if Team.objects.exclude(institution__region__isnull=True).count() > 0:
        data_sets['speakers_region'].append(compile_data(
            'All', Speaker.objects.filter(
                team__tournament=t), 'team__institution__region__name', filters=region_filters, count=True))
        if t.pref('public_breaking_teams') is True or for_public is False:
            data_sets['speakers_region'].append(compile_data(
                'Breaking', Speaker.objects.filter(
                    team__tournament=t, team__breakingteam__isnull=False), 'team__institution__region__name', filters=region_filters, count=True))
        if Speaker.objects.filter(team__tournament=t).filter(novice=True).count() > 0:
            data_sets['speakers_region'].append(compile_data(
                'Pros', Speaker.objects.filter(
                    team__tournament=t, novice=False), 'team__institution__region__name', filters=region_filters, count=True))
            data_sets['speakers_region'].append(compile_data(
                'Novices', Speaker.objects.filter(
                    team__tournament=t, novice=True), 'team__institution__region__name', filters=region_filters, count=True))

    # ==========================================================================
    # Adjudicators Demographics
    # ==========================================================================

    if Adjudicator.objects.filter(tournament=t).count() > 0:
        data_sets['adjudicators_gender'].append(compile_data(
            'All', Adjudicator.objects.filter(tournament=t), 'gender', filters=[
                {'Unknown':  None},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                {'Male':     Person.GENDER_MALE},
            ], count=True))

    if Adjudicator.objects.filter(tournament=t).filter(independent=True).count() > 0:
        data_sets['adjudicators_gender'].append(compile_data(
            'Indies', Adjudicator.objects.filter(tournament=t, independent=True), 'gender', filters=[
                {'Unknown':  None},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                {'Male':     Person.GENDER_MALE},
            ], count=True))

    if t.pref('public_breaking_adjs') is True or for_public is False:
        if Adjudicator.objects.filter(breaking=True).count() > 0:
            data_sets['adjudicators_gender'].append(compile_data(
                'Breaking', Adjudicator.objects.filter(tournament=t, breaking=True), 'gender', filters=[
                    {'Unknown':  None},
                    {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                    {'Male':     Person.GENDER_MALE},
                ], count=True))

    if DebateAdjudicator.objects.filter(adjudicator__tournament=t, type=DebateAdjudicator.TYPE_CHAIR).count() > 0:
        data_sets['adjudicators_gender'].append(compile_data(
            'Chairs', DebateAdjudicator.objects.filter(adjudicator__tournament=t, type=DebateAdjudicator.TYPE_CHAIR), 'adjudicator__gender', filters=[
                {'Unknown':  None},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                {'Male':     Person.GENDER_MALE},
            ], count=True))

    if DebateAdjudicator.objects.filter(adjudicator__tournament=t, type=DebateAdjudicator.TYPE_PANEL).count() > 0:
        data_sets['adjudicators_gender'].append(compile_data(
            'Panellists', DebateAdjudicator.objects.filter(adjudicator__tournament=t, type=DebateAdjudicator.TYPE_PANEL), 'adjudicator__gender', filters=[
                {'Unknown':  None},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                {'Male':     Person.GENDER_MALE},
            ], count=True))

    if DebateAdjudicator.objects.filter(adjudicator__tournament=t, type=DebateAdjudicator.TYPE_TRAINEE).count() > 0:
        data_sets['adjudicators_gender'].append(compile_data(
            'Trainees', DebateAdjudicator.objects.filter(adjudicator__tournament=t, type=DebateAdjudicator.TYPE_TRAINEE), 'adjudicator__gender', filters=[
                {'Unknown':  None},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                {'Male':     Person.GENDER_MALE},
            ], count=True))

    if DebateAdjudicator.objects.exclude(adjudicator__institution__region__isnull=True).count() > 0:
        data_sets['adjudicators_region'].append(compile_data(
            'All', Adjudicator.objects.filter(
                tournament=t), 'institution__region__name', filters=region_filters, count=True))
        if t.pref('public_breaking_adjs') is True or for_public is False:
            data_sets['adjudicators_region'].append(compile_data(
                'Breaking', Adjudicator.objects.filter(
                    tournament=t, breaking=True), 'institution__region__name', filters=region_filters, count=True))

    # ==========================================================================
    # Adjudicators Results
    # ==========================================================================

    if AdjudicatorFeedback.objects.filter(adjudicator__tournament=t).count() > 0:
        data_sets['adjudicators_results'].append(compile_data(
            'Average Rating', AdjudicatorFeedback.objects.filter(adjudicator__tournament=t), 'adjudicator__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], average=True, datum=True))

        data_sets['adjudicators_results'].append(compile_data(
            'Median Rating', AdjudicatorFeedback.objects.filter(adjudicator__tournament=t), 'adjudicator__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], median=True, datum=True))

        data_sets['adjudicators_results'].append(compile_data(
            'Upper Quartile Rating', AdjudicatorFeedback.objects.filter(adjudicator__tournament=t), 'adjudicator__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], upperq=True, datum=True))

        data_sets['adjudicators_results'].append(compile_data(
            'Lower Quartile Rating', AdjudicatorFeedback.objects.filter(adjudicator__tournament=t), 'adjudicator__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], lowerq=True, datum=True))

    if AdjudicatorFeedback.objects.filter(adjudicator__tournament=t, source_adjudicator__isnull=False).count() > 0:
        data_sets['detailed_adjudicators_results'].append(compile_data(
            'Average Rating Given by Teams', AdjudicatorFeedback.objects.filter(adjudicator__tournament=t, source_adjudicator__isnull=False),
            'source_adjudicator__adjudicator__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], average=True, datum=True))

    if AdjudicatorFeedback.objects.filter(adjudicator__tournament=t, source_adjudicator__type=DebateAdjudicator.TYPE_CHAIR).count() > 0:
        data_sets['detailed_adjudicators_results'].append(compile_data(
            'Average Rating Given by Chairs', AdjudicatorFeedback.objects.filter(
                adjudicator__tournament=t, source_adjudicator__type=DebateAdjudicator.TYPE_CHAIR, source_adjudicator__isnull=False),
            'source_adjudicator__adjudicator__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], average=True, datum=True))

    if AdjudicatorFeedback.objects.filter(adjudicator__tournament=t, source_adjudicator__type=DebateAdjudicator.TYPE_PANEL).count() > 0:
        data_sets['detailed_adjudicators_results'].append(compile_data(
            'Average Rating Given by Panellists', AdjudicatorFeedback.objects.filter(
                adjudicator__tournament=t, source_adjudicator__type=DebateAdjudicator.TYPE_PANEL, source_adjudicator__isnull=False),
            'source_adjudicator__adjudicator__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], average=True, datum=True))

    if AdjudicatorFeedback.objects.filter(adjudicator__tournament=t, source_adjudicator__type=DebateAdjudicator.TYPE_TRAINEE).count() > 0:
        data_sets['detailed_adjudicators_results'].append(compile_data(
            'Average Rating Given by Trainees', AdjudicatorFeedback.objects.filter(
                adjudicator__tournament=t, source_adjudicator__type=DebateAdjudicator.TYPE_TRAINEE, source_adjudicator__isnull=False),
            'source_adjudicator__adjudicator__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], average=True, datum=True))

    # ==========================================================================
    # Speakers Results
    # ==========================================================================

    if SpeakerScore.objects.filter(speaker__team__tournament=t).count() > 0:
        data_sets['speakers_results'].append(compile_data(
            'Average Score', SpeakerScore.objects.filter(speaker__team__tournament=t).exclude(position=t.REPLY_POSITION), 'speaker__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], average=True, datum=True))

        data_sets['speakers_results'].append(compile_data(
            'Median Score', SpeakerScore.objects.filter(speaker__team__tournament=t).exclude(position=t.REPLY_POSITION), 'speaker__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], median=True, datum=True))

        data_sets['speakers_results'].append(compile_data(
            'Upper Quartile Score', SpeakerScore.objects.filter(speaker__team__tournament=t).exclude(position=t.REPLY_POSITION), 'speaker__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], upperq=True, datum=True))

        data_sets['speakers_results'].append(compile_data(
            'Lower Quartile Score', SpeakerScore.objects.filter(speaker__team__tournament=t).exclude(position=t.REPLY_POSITION), 'speaker__gender', filters=[
                {'Male':     Person.GENDER_MALE},
                {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
            ], lowerq=True, datum=True))
        for i in range(1, t.pref('substantive_speakers') + 1):

            data_sets['detailed_speakers_results'].append(compile_data(
                'Speaker ' + str(i) + ' Average', SpeakerScore.objects.filter(speaker__team__tournament=t, position=str(i)), 'speaker__gender', filters=[
                    {'Male':     Person.GENDER_MALE},
                    {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                ], average=True, datum=True))

        if t.pref('reply_scores_enabled'):
            data_sets['detailed_speakers_results'].append(compile_data(
                'Reply Speaker Average', SpeakerScore.objects.filter(speaker__team__tournament=t, position=t.REPLY_POSITION), 'speaker__gender', filters=[
                    {'Male':     Person.GENDER_MALE},
                    {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                ], average=True, datum=True))

        if SpeakerScore.objects.filter(speaker__team__tournament=t, debate_team__debate__round__stage=Round.STAGE_ELIMINATION).count() > 0:
            data_sets['detailed_speakers_results'].append(compile_data(
                'Average Finals Score', SpeakerScore.objects.filter(debate_team__debate__round__stage=Round.STAGE_ELIMINATION).exclude(position=t.REPLY_POSITION), 'speaker__gender', filters=[
                    {'Male':     Person.GENDER_MALE},
                    {'NM':       [Person.GENDER_FEMALE, Person.GENDER_OTHER]},
                ], average=True, datum=True))

    return data_sets
Пример #3
0
def get_diversity_data_sets(t, for_public):

    all_regions = regions_ordered(t)

    region_values = [r['id'] for r in all_regions]
    region_labels = [r['seq'] for r in all_regions]

    data_sets = {
        'speakers_gender': [],
        'speakers_region': [],
        'speakers_results': [],
        'speakers_categories': [],
        'detailed_speakers_results': [],
        'adjudicators_gender': [],
        'adjudicators_position': [],
        'adjudicators_region': [],
        'adjudicators_results': [],
        'detailed_adjudicators_results': [],
        'regions': all_regions  # For CSS
    }

    # ==========================================================================
    # Speakers Demographics
    # ==========================================================================

    speakers = Speaker.objects.filter(team__tournament=t)

    if Speaker.objects.filter(team__tournament=t).count() > 0:
        data_sets['speakers_gender'].append(compile_gender_counts(_("All"), speakers, 'gender'))

    if t.pref('public_breaking_teams') is True or for_public is False:
        if Speaker.objects.filter(team__tournament=t).filter(team__breakingteam__isnull=False).count() > 0:
            data_sets['speakers_gender'].append(compile_gender_counts(_("Breaking"),
                    speakers.filter(team__breakingteam__isnull=False), 'gender'))

    for sc in SpeakerCategory.objects.filter(tournament=t).order_by('seq'):
        if Speaker.objects.filter(categories=sc).count() > 0:
            data_sets['speakers_categories'].append(compile_gender_counts(sc.name,
                    speakers.filter(categories=sc), 'gender'))
            data_sets['speakers_categories'].append(compile_gender_counts(_("Not %(category)s") % {'category': sc.name},
                    speakers.exclude(categories=sc), 'gender'))

    if Team.objects.exclude(institution__region__isnull=True).exists():
        data_sets['speakers_region'].append(compile_grouped_counts(_("All Speakers"), speakers,
                F('team__institution__region__id'), region_values, region_labels))

        if t.pref('public_breaking_teams') is True or for_public is False:
            data_sets['speakers_region'].append(compile_grouped_counts(_("Breaking"),
                    speakers.filter(team__breakingteam__isnull=False),
                    F('team__institution__region__id'), region_values, region_labels))

    # ==========================================================================
    # Adjudicators Demographics
    # ==========================================================================

    adjudicators = t.adjudicator_set.all()

    if adjudicators.count() > 0:
        data_sets['adjudicators_gender'].append(compile_gender_counts(_("All"), adjudicators, 'gender'))

    if Adjudicator.objects.filter(tournament=t).filter(independent=True).exists():
        data_sets['adjudicators_gender'].append(compile_gender_counts(_("Indies"),
            adjudicators.filter(independent=True), 'gender'))

    if (t.pref('public_breaking_adjs') is True or for_public is False) and Adjudicator.objects.filter(breaking=True).exists():
        data_sets['adjudicators_gender'].append(compile_gender_counts(_("Breaking"),
            adjudicators.filter(breaking=True), 'gender'))

    debateadjs = DebateAdjudicator.objects.filter(adjudicator__tournament=t)
    titles = [_("Chairs"), _("Panellists"), _("Trainees")]
    adjtypes = [
        DebateAdjudicator.TYPE_CHAIR,
        DebateAdjudicator.TYPE_PANEL,
        DebateAdjudicator.TYPE_TRAINEE
    ]
    data_sets['adjudicators_position'] = compile_grouped_gender_counts(titles, debateadjs,
            'adjudicator__gender', 'type', adjtypes)

    if Adjudicator.objects.exclude(institution__region__isnull=True).exists():
        data_sets['adjudicators_region'].append(compile_grouped_counts(_("All"), adjudicators,
                F('institution__region__id'), region_values, region_labels))

        if t.pref('public_breaking_adjs') is True or for_public is False:
            data_sets['adjudicators_region'].append(compile_grouped_counts(_("Breaking"), adjudicators.filter(breaking=True),
                    F('institution__region__id'), region_values, region_labels))

    # ==========================================================================
    # Adjudicators Results
    # ==========================================================================

    # Don't show data if genders have not been set
    data_sets['gendered_adjudicators'] = Adjudicator.objects.filter(gender="M").count() + Adjudicator.objects.filter(gender="F").count()
    if data_sets['gendered_adjudicators'] > 0:

        adjfeedbacks = AdjudicatorFeedback.objects.filter(adjudicator__tournament=t, confirmed=True)

        data_sets['feedbacks_count'] = adjfeedbacks.count()

        if data_sets['feedbacks_count'] > 0:

            titles = [
                _("Average Rating"),
                _("Median Rating"),
                _("Upper Quartile Rating"),
                _("Lower Quartile Rating"),
            ]
            statistics = ['mean', 'median', 'upperq', 'lowerq']
            data_sets['adjudicators_results'] = compile_statistics_by_gender(titles, adjfeedbacks, statistics, 'adjudicator__gender')

            titles = [
                _("Average Rating From Teams"),
                _("Average Rating From Chairs"),
                _("Average Rating From Panellists"),
                _("Average Rating From Trainees"),
            ]
            group_values = [
                None,
                DebateAdjudicator.TYPE_CHAIR,
                DebateAdjudicator.TYPE_PANEL,
                DebateAdjudicator.TYPE_TRAINEE
            ]
            data_sets['detailed_adjudicators_results'] = compile_grouped_means_by_gender(
                    titles, adjfeedbacks, 'adjudicator__gender', 'source_adjudicator__type', group_values)

    # ==========================================================================
    # Speakers Results
    # ==========================================================================

    # Don't show data if genders have not been set
    data_sets['gendered_speakers'] = Speaker.objects.filter(gender="M").count() + Speaker.objects.filter(gender="F").count()
    if data_sets['gendered_speakers'] > 0:

        speakerscores = SpeakerScore.objects.filter(speaker__team__tournament=t, ballot_submission__confirmed=True)

        data_sets['speaks_count'] = speakerscores.count()
        if data_sets['speaks_count'] > 0:

            titles = [
                _("Average Score"),
                _("Median Score"),
                _("Upper Quartile Score"),
                _("Lower Quartile Score"),
            ]
            statistics = ['mean', 'median', 'upperq', 'lowerq']
            data_sets['speakers_results'] = compile_statistics_by_gender(titles,
                    speakerscores.exclude(position=t.reply_position), statistics, 'speaker__gender')

            titles = [
                _("Reply Speaker Average") if pos == t.reply_position else
                _("Speaker %(num)d Average") % {'num': pos}
                for pos in t.positions
            ]
            data_sets['detailed_speakers_results'] = compile_grouped_means_by_gender(
                    titles, speakerscores, 'speaker__gender', 'position', t.positions)

            if speakerscores.filter(debate_team__debate__round__stage=Round.STAGE_ELIMINATION).exists():
                data_sets['detailed_speakers_results'].extend(compile_statistics_by_gender(
                    [_("Average Finals Score")],
                    speakerscores.filter(debate_team__debate__round__stage=Round.STAGE_ELIMINATION).exclude(position=t.reply_position),
                    ['mean'], 'speaker__gender'))

    return data_sets