Returns a list that associates all the winners of a profile under Single non-transferable vote rule.

        :ivar Profile profile: A Profile object that represents an election profile.
161548
def SNTV_winners(self, profile, K):
        

        # Currently, we expect the profile to contain complete ordering over candidates. Ties are
        # allowed however.
        elecType = profile.getElecType()
        if elecType != "soc" and elecType != "toc" and elecType != "csv":
            print("ERROR: unsupported election type")
            exit()

        m = profile.numCands
        candScoresMap = MechanismPlurality().getCandScoresMap(profile)
        if K >= m:
            return list(candScoresMap.keys())
        # print(candScoresMap)
        sorted_items = sorted(candScoresMap.items(), key=lambda x: x[1], reverse=True)
        sorted_dict = {key: value for key, value in sorted_items}
        winners = list(sorted_dict.keys())[0:K]
        return winners
272737
def get_associated_profiles(profile_path, result_role, server):
    
    associated_profiles = server.conn.Associators(
        ObjectName=profile_path,
        AssocClass="CIM_ReferencedProfile",
        ResultRole=result_role)
    if VERBOSE:
        print('GET_ASSICIATED_PROFILES path=%r, result_role=%s\nReturns %s' %
              (profile_path, result_role, associated_profiles))
        if server.conn.debug:
            print('LAST_REQUEST\n%s' % server.conn.last_request)
            print('LAST_REPLY\n%s' % server.conn.last_reply)
    return associated_profiles
1043741
def _item_list(profile=None, **connection_args):
    '''
    
    '''
    kstone = auth(profile, **connection_args)
    ret = []
    for item in kstone.items.list():
        ret.append(item.__dict__)
        # ret[item.name] = {
        #         'id': item.id,
        #         'name': item.name,
        #         }
    return ret
572613
def iterargs(self):
    
    iterargs = OrderedDict()
    for name in self._iterargs:
      plural = self._profile.iterargs[name]
      iterargs[name] = tuple(self._values[plural])
    return iterargs
1078339
def _get_candidates(self):
        
        candidates = np.where(self.dpp_vector == 0)
        return None if len(candidates[0]) == 0 else candidates[0]
415214
def get_social_accounts(user):
    
    accounts = {}
    for account in user.socialaccount_set.all().iterator():
        providers = accounts.setdefault(account.provider, [])
        providers.append(account)
    return accounts
633609
def baldwinsoc_winners(self, profile):
        
        ordering = profile.getOrderVectors()
        m = profile.numCands
        prefcounts = profile.getPreferenceCounts()
        if min(ordering[0]) == 0:
            startstate = set(range(m))
        else:
            startstate = set(range(1, m + 1))
        wmg = self.getWmg2(prefcounts, ordering, startstate, normalize=False)
        known_winners = set()
        # ----------Some statistics--------------
        hashtable2 = set()

        # push the node of start state into the priority queue
        root = Node(value=startstate)
        stackNode = []
        stackNode.append(root)

        while stackNode:
            # ------------pop the current node-----------------
            node = stackNode.pop()
            # -------------------------------------------------
            state = node.value.copy()

            # goal state 1: if the state set contains only 1 candidate, then stop
            if len(state) == 1 and list(state)[0] not in known_winners:
                known_winners.add(list(state)[0])
                continue
            # goal state 2 (pruning): if the state set is subset of the known_winners set, then stop
            if state <= known_winners:
                continue
            # ----------Compute plurality score for the current remaining candidates--------------
            plural_score = dict()
            for cand in state:
                plural_score[cand] = 0
            for cand1, cand2 in itertools.permutations(state, 2):
                plural_score[cand1] += wmg[cand1][cand2]

            # if current state satisfies one of the 3 goal state, continue to the next loop

            # After using heuristics, generate children and push them into priority queue
            # frontier = [val for val in known_winners if val in state] + list(set(state) - set(known_winners))

            minscore = min(plural_score.values())
            for to_be_deleted in state:
                if plural_score[to_be_deleted] == minscore:
                    child_state = state.copy()
                    child_state.remove(to_be_deleted)
                    tpc = tuple(sorted(child_state))
                    if tpc in hashtable2:
                        continue
                    else:
                        hashtable2.add(tpc)
                        child_node = Node(value=child_state)
                        stackNode.append(child_node)
        return sorted(known_winners)
184912
def results(self):
        

        results = {
            'overall': self.results_overall_metrics(),
            'class_wise': self.results_class_wise_metrics(),
            'class_wise_average': self.results_class_wise_average_metrics()
        }

        return results
27804
def get_profiles(self, profile_base="/data/b2g/mozilla", timeout=None):
        

        rv = {}

        if timeout is None:
            timeout = self._timeout

        profile_path = posixpath.join(profile_base, "profiles.ini")
        try:
            proc = self.shell("cat %s" % profile_path, timeout=timeout)
            config = ConfigParser.ConfigParser()
            config.readfp(proc.stdout_file)
            for section in config.sections():
                items = dict(config.items(section))
                if "name" in items and "path" in items:
                    path = items["path"]
                    if "isrelative" in items and int(items["isrelative"]):
                        path = posixpath.normpath("%s/%s" % (profile_base, path))
                    rv[items["name"]] = path
        finally:
            proc.stdout_file.close()
            proc.stderr_file.close()

        return rv
204856
def get_initial_totals(self):
        ""
        candidate_votes = {}
        # initialise to zero for every individual candidate
        for candidate_id in self.candidate_ids:
            candidate_votes[candidate_id] = 0
        for candidate_id in self.candidate_ids:
            candidate_votes[candidate_id] = self.candidate_bundle_transactions.get_paper_count(candidate_id)
        for candidate_id in candidate_votes:
            candidate_votes[candidate_id] = int(candidate_votes[candidate_id])
        return candidate_votes, 0, 0
1229103
def get_incumbent_id(self):
		
		tmp_list = []
		for k,v in self.data.items():
			try:
				# only things run for the max budget are considered
				res = v.results[self.HB_config['max_budget']]
				if not res is None:
					tmp_list.append((res['loss'], k))
			except KeyError as e:
				pass
			except:
				raise

		if len(tmp_list) > 0:
			return(min(tmp_list)[1])
		return(None)
1002425
def list_():
    '''
    
    '''

    result = __salt__['cmd.run']('tuned-adm list').splitlines()
    # Remove "Available profiles:"
    result.pop(0)
    # Remove "Current active profile:.*"
    result.pop()
    # Output can be : " - <profile name> - <description>" (v2.7.1)
    # or " - <profile name> " (v2.4.1)
    result = [i.split('- ')[1].strip() for i in result]
    return result
483401
def getMaximinScores(profile):
    

    # Currently, we expect the profile to contain complete ordering over candidates. Ties are
    # allowed however.
    elecType = profile.getElecType()
    if elecType != "soc" and elecType != "toc":
        print("ERROR: unsupported election type")
        exit()

    wmgMap = profile.getWmg()
    # Initialize each Copeland score as infinity.
    maximinscores = {}
    for cand in wmgMap.keys():
        maximinscores[cand] = float("inf")

    # For each pair of candidates, calculate the number of votes in which one beat the other.

    # For each pair of candidates, calculate the number of times each beats the other.
    for cand1, cand2 in itertools.combinations(wmgMap.keys(), 2):
        if cand2 in wmgMap[cand1].keys():
            maximinscores[cand1] = min(maximinscores[cand1], wmgMap[cand1][cand2])
            maximinscores[cand2] = min(maximinscores[cand2], wmgMap[cand2][cand1])

    return maximinscores
1076251
def MoVSimplifiedBucklin(profile):
    

    # Currently, we expect the profile to contain complete ordering over candidates.
    elecType = profile.getElecType()
    if elecType != "soc" and elecType != "csv" and elecType != "toc":
        print("ERROR: unsupported profile type")
        exit()

    # Initialization
    n = profile.numVoters
    m = profile.numCands
    half = math.floor(float(n) / 2)
    prefcounts = profile.getPreferenceCounts()
    len_prefcounts = len(prefcounts)
    rankmaps = profile.getRankMaps()
    values = zeros([len_prefcounts, m], dtype=int)
    if min(list(rankmaps[0].keys())) == 0:
        delta = 0
    else:
        delta = 1
    for i in range(len_prefcounts):
        for j in range(delta, m + delta):
            values[i][j - delta] = rankmaps[i][j]

    winners = MechanismSimplifiedBucklin().getWinners(profile)  # the winner list
    d = winners[0]  # the winner under the numerically tie-breaking rule
    alter = delete(range(delta, m + delta), d - delta)
    # Initialize MoV
    MoV = n * ones(m, dtype=int)
    for c in alter:
        for ell in range(1, int(math.floor(float(m) / 2)) + 2):
            numcond1 = sum(dot(array(prefcounts), logical_and(values[:, c - delta] > ell, values[:, d - delta] <= ell - 1)))
            numcond2 = sum(dot(array(prefcounts), logical_and(values[:, c - delta] > ell, values[:, d - delta] > ell - 1)))
            numcond3 = sum(dot(array(prefcounts), logical_and(values[:, c - delta] <= ell, values[:, d - delta] <= ell - 1)))
            diff_c = half - sum(dot(array(prefcounts), (values[:, c - delta] <= ell)))
            diff_d = half - sum(dot(array(prefcounts), (values[:, d - delta] <= ell - 1)))
            if diff_c < 0:
                if diff_d < 0 and numcond1 + numcond3 > abs(diff_d):
                    MoV[c - delta] = min(MoV[c - delta], abs(diff_d))
                continue
            # -------diff_c >= 0------------
            if diff_d >= 0:
                if numcond1 + numcond2 > diff_c >= 0:
                    MoV[c - delta] = min(MoV[c - delta], diff_c + 1)
            else:
                if numcond1 > diff_c and numcond1 > abs(diff_d):
                    MoV[c - delta] = min(MoV[c - delta], max(diff_c + 1, abs(diff_d)))
                elif diff_c >= numcond1 > abs(diff_d):
                    if numcond1 + numcond2 > diff_c:
                        MoV[c - delta] = min(MoV[c - delta], diff_c + 1)
                elif abs(diff_d) >= numcond1 > diff_c:
                    if numcond1 + numcond3 > abs(diff_d):
                        MoV[c - delta] = min(MoV[c - delta], abs(diff_d))
                else:  # numcond1 <= diff_c and numcond1 <= abs(diff_d)
                    if numcond1 + numcond2 > diff_c and numcond1 + numcond3 > abs(diff_d):
                        MoV[c - delta] = min(MoV[c - delta], numcond1 + abs(diff_c) + 1 + abs(diff_d))

    return min(MoV)
869743
def get_all_instance_profiles(path_prefix='/', region=None, key=None,
                              keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    marker = False
    profiles = []
    while marker is not None:
        marker = marker if marker else None
        p = conn.list_instance_profiles(path_prefix=path_prefix,
                                                   marker=marker)
        res = p.list_instance_profiles_response.list_instance_profiles_result
        profiles += res.instance_profiles
        marker = getattr(res, 'marker', None)
    return profiles
660070
def get_all_outcome_links_for_context_accounts(self, account_id, outcome_group_style=None, outcome_style=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - account_id
        """ID"""
        path["account_id"] = account_id

        # OPTIONAL - outcome_style
        """The detail level of the outcomes. Defaults to "abbrev".
        Specify "full" for more information."""
        if outcome_style is not None:
            params["outcome_style"] = outcome_style

        # OPTIONAL - outcome_group_style
        """The detail level of the outcome groups. Defaults to "abbrev".
        Specify "full" for more information."""
        if outcome_group_style is not None:
            params["outcome_group_style"] = outcome_group_style

        self.logger.debug("GET /api/v1/accounts/{account_id}/outcome_group_links with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("GET", "/api/v1/accounts/{account_id}/outcome_group_links".format(**path), data=data, params=params, all_pages=True)
164530
def getScoringVector(self, profile):
        

        scoringVector = []
        scoringVector.append(1)
        for i in range(1, profile.numCands):
            scoringVector.append(0)
        return scoringVector