Skip to content

Check Consistency Schulze

Class used to check if there is a conflict between a schulze method and majority judgment vote for polls also votable with MJ.

CheckConsistencyShulze

Source code in apps/votes_results/classes/vote_consistency/check_consistency_shulze.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class CheckConsistencyShulze:

    @staticmethod    
    def check(shulze_vote_id: str, mj_votes: List[dict]) -> bool:
        """Checks if the shulze vote key is consistent with the majority judgment votes.

        Args:
            shulze_vote_id (str): Shulze vote option vote id.
            mj_votes (List[dict]): List of dicts with mj keys and ratings. Example: [{'poll_choice_id': 1, 'rating': 3}, {'poll_choice_id': 2, 'rating': 2}]

        Returns:
            bool: True if the Shulze option vote key is consistent with the majority judgment votes, False otherwise.
        """
        if shulze_vote_id != None:
            try:
                vote = SchulzeMethodVoteService.get_vote_by_id(shulze_vote_id)
                shulze_options: list = vote.get_order()

                for shulze_options_index in range(0, len(vote.get_order()) - 1):
                    previous_rating: list= list(filter(lambda x: x['poll_choice_id'] == int(shulze_options[shulze_options_index]), mj_votes ))[0]['rating']
                    next_rating: list = list(filter(lambda x: x['poll_choice_id'] == int(shulze_options[shulze_options_index + 1]), mj_votes ))[0]['rating']

                    if previous_rating < next_rating:
                        return False
            except Exception as e:
                # If the poll is not found, the vote is not consistent
                return False
        return True

check(shulze_vote_id, mj_votes) staticmethod

Checks if the shulze vote key is consistent with the majority judgment votes.

Parameters:

Name Type Description Default
shulze_vote_id str

Shulze vote option vote id.

required
mj_votes List[dict]

List of dicts with mj keys and ratings. Example: [{'poll_choice_id': 1, 'rating': 3}, {'poll_choice_id': 2, 'rating': 2}]

required

Returns:

Name Type Description
bool bool

True if the Shulze option vote key is consistent with the majority judgment votes, False otherwise.

Source code in apps/votes_results/classes/vote_consistency/check_consistency_shulze.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@staticmethod    
def check(shulze_vote_id: str, mj_votes: List[dict]) -> bool:
    """Checks if the shulze vote key is consistent with the majority judgment votes.

    Args:
        shulze_vote_id (str): Shulze vote option vote id.
        mj_votes (List[dict]): List of dicts with mj keys and ratings. Example: [{'poll_choice_id': 1, 'rating': 3}, {'poll_choice_id': 2, 'rating': 2}]

    Returns:
        bool: True if the Shulze option vote key is consistent with the majority judgment votes, False otherwise.
    """
    if shulze_vote_id != None:
        try:
            vote = SchulzeMethodVoteService.get_vote_by_id(shulze_vote_id)
            shulze_options: list = vote.get_order()

            for shulze_options_index in range(0, len(vote.get_order()) - 1):
                previous_rating: list= list(filter(lambda x: x['poll_choice_id'] == int(shulze_options[shulze_options_index]), mj_votes ))[0]['rating']
                next_rating: list = list(filter(lambda x: x['poll_choice_id'] == int(shulze_options[shulze_options_index + 1]), mj_votes ))[0]['rating']

                if previous_rating < next_rating:
                    return False
        except Exception as e:
            # If the poll is not found, the vote is not consistent
            return False
    return True