<commit_before>from admintools.issues import IssueType
from admintools.models import DataQualityIssue
from opencivicdata.core.models import Jurisdiction
from opencivicdata.legislative.models import VoteEvent


def create_vote_event_issues(queryset, issue, jur):
    obj_list = []
    alert = IssueType.level_for(issue)
    issue = IssueType.class_for(issue) + '-' + issue
    for query_obj in queryset:
        if not DataQualityIssue.objects.filter(object_id=query_obj.id,
                                               alert=alert, issue=issue,
                                               jurisdiction=jur):
            obj_list.append(
                DataQualityIssue(content_object=query_obj, alert=alert,
                                 issue=issue, jurisdiction=jur)
            )
    DataQualityIssue.objects.bulk_create(obj_list)
    return len(obj_list)


def vote_event_issues():
    all_jurs = Jurisdiction.objects.order_by('name')
    for jur in all_jurs:
        voteevents = VoteEvent.objects.filter(
            legislative_session__jurisdiction=jur)
        count = 0
        for issue in IssueType.get_issues_for('voteevent'):
            if issue == 'missing-bill':
                queryset = voteevents.filter(bill__isnull=True)
                count += create_vote_event_issues(queryset, issue, jur)

            elif issue == 'unmatched-voter':
                queryset = voteevents.filter(votes__isnull=False,
                                             votes__voter__isnull=True) \
                                             .distinct()
                count += create_vote_event_issues(queryset, issue, jur)

            elif issue == 'missing-voters':
                queryset = voteevents.filter(votes__isnull=True)
                count += create_vote_event_issues(queryset, issue, jur)

            elif issue == 'missing-counts':
                queryset = voteevents.filter(counts__option='yes',
                                             counts__value=0).filter(
                                                 counts__option='no',
                                                 counts__value=0)
                count += create_vote_event_issues(queryset, issue, jur)

            elif issue == 'bad-counts':
                queryset = voteevents.filter(counts__option='other',
                                             counts__value__gt=0)
                count += create_vote_event_issues(queryset, issue, jur)
            else:
                raise ValueError("VoteEvents Importer needs update "
                                 "for new issue.")
        print("Imported VoteEvents Related {} Issues for {}".format(count,
                                                                    jur.name))
<commit_msg>bug_solved: bad votes quertset<commit_after>from admintools.issues import IssueType
from admintools.models import DataQualityIssue
from opencivicdata.core.models import Jurisdiction
from opencivicdata.legislative.models import VoteEvent, VoteCount, PersonVote


def create_vote_event_issues(queryset, issue, jur):
    obj_list = []
    alert = IssueType.level_for(issue)
    issue = IssueType.class_for(issue) + '-' + issue
    for query_obj in queryset:
        if not DataQualityIssue.objects.filter(object_id=query_obj.id,
                                               alert=alert, issue=issue,
                                               jurisdiction=jur):
            obj_list.append(
                DataQualityIssue(content_object=query_obj, alert=alert,
                                 issue=issue, jurisdiction=jur)
            )
    DataQualityIssue.objects.bulk_create(obj_list)
    return len(obj_list)


def vote_event_issues():
    all_jurs = Jurisdiction.objects.order_by('name')
    for jur in all_jurs:
        voteevents = VoteEvent.objects.filter(
            legislative_session__jurisdiction=jur)
        count = 0
        for issue in IssueType.get_issues_for('voteevent'):
            if issue == 'missing-bill':
                queryset = voteevents.filter(bill__isnull=True)
                count += create_vote_event_issues(queryset, issue, jur)

            elif issue == 'unmatched-voter':
                queryset = voteevents.filter(votes__isnull=False,
                                             votes__voter__isnull=True) \
                                             .distinct()
                count += create_vote_event_issues(queryset, issue, jur)

            elif issue == 'missing-voters':
                queryset = voteevents.filter(votes__isnull=True)
                count += create_vote_event_issues(queryset, issue, jur)

            elif issue == 'missing-counts':
                queryset = voteevents.filter(counts__option='yes',
                                             counts__value=0).filter(
                                                 counts__option='no',
                                                 counts__value=0)
                count += create_vote_event_issues(queryset, issue, jur)

            elif issue == 'bad-counts':
                all_counts = VoteCount.objects.filter(
                    vote_event__legislative_session__jurisdiction=jur)
                queryset = set()
                for _count in all_counts:
                    if PersonVote.objects.filter(
                        vote_event=_count.vote_event,
                            option=_count.option).count() != _count.value:
                        queryset.add(_count.vote_event)
                count += create_vote_event_issues(queryset, issue, jur)
            else:
                raise ValueError("VoteEvents Importer needs update "
                                 "for new issue.")
        print("Imported VoteEvents Related {} Issues for {}".format(count,
                                                                    jur.name))

{'fraction_non_alphanumeric': 0.07701482364968479, 'fraction_numerical': 0.001192707445902198, 'mean_word_length': 1.5633187772925765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1539181', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1388, 'n_words': 273}