Skip to content

Check Consistency MJ Vote

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

CheckConsistencyMjVote

Source code in apps/votes_results/classes/vote_consistency/check_consistency_mj_vote.py
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class CheckConsistencyMjVote:

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

        Args:
            single_option_vote_key (str): Single 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 single option vote key is consistent with the majority judgment votes, False otherwise.
        """
        if mj_votes:
            max_rating: dict = [max(mj_votes, key=lambda x:x['rating'])]
            items_with_max_rating: List[dict] = [item for item in mj_votes if item['rating'] == max_rating[0]['rating']]
        else:
            return False

        for item in items_with_max_rating:
            if item['poll_choice_id'] == int(single_option_vote_key):
                return True
        return False

check(single_option_vote_key, mj_votes) staticmethod

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

Parameters:

Name Type Description Default
single_option_vote_key str

Single 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 single option vote key is consistent with the majority judgment votes, False otherwise.

Source code in apps/votes_results/classes/vote_consistency/check_consistency_mj_vote.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@staticmethod    
def check(single_option_vote_key: str, mj_votes: List[dict]) -> bool:
    """Checks if the single option vote key is consistent with the majority judgment votes.

    Args:
        single_option_vote_key (str): Single 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 single option vote key is consistent with the majority judgment votes, False otherwise.
    """
    if mj_votes:
        max_rating: dict = [max(mj_votes, key=lambda x:x['rating'])]
        items_with_max_rating: List[dict] = [item for item in mj_votes if item['rating'] == max_rating[0]['rating']]
    else:
        return False

    for item in items_with_max_rating:
        if item['poll_choice_id'] == int(single_option_vote_key):
            return True
    return False