finds a round in the count history in which the candidate_ids each had different vote counts
        if no such round exists, returns None
333784
def find_tie_breaker(self, candidate_ids):
        
        for candidate_aggregates in reversed(self.round_candidate_aggregates):
            candidates_on_vote = defaultdict(int)
            for candidate_id in candidate_ids:
                votes = candidate_aggregates.get_vote_count(candidate_id)
                candidates_on_vote[votes] += 1
            if max(candidates_on_vote.values()) == 1:
                return candidate_aggregates
856745
def has_been_completed_by(poll, user):
    
    user_votes = TopicPollVote.objects.filter(
        poll_option__poll=poll)
    if user.is_anonymous:
        forum_key = get_anonymous_user_forum_key(user)
        user_votes = user_votes.filter(anonymous_key=forum_key) if forum_key \
            else user_votes.none()
    else:
        user_votes = user_votes.filter(voter=user)
    return user_votes.exists()
445547
def fnmatch_multiple(candidates, pattern):
    '''
    
    '''
    # Make sure that candidates is iterable to avoid a TypeError when we try to
    # iterate over its items.
    try:
        candidates_iter = iter(candidates)
    except TypeError:
        return None

    for candidate in candidates_iter:
        try:
            if fnmatch.fnmatch(candidate, pattern):
                return candidate
        except TypeError:
            pass
    return None
533507
def vote(self, identifier, weight=100.0):
        ''' 
        '''
        for num_of_retries in range(default.max_retry):
            try:
                self.steem_instance().vote(identifier, 
                    weight, self.mainaccount)
                self.msg.message("voted for " + identifier)
                time.sleep(5)
            except Exception as e:
                if re.search(r'You have already voted in a similar way', str(e)):
                    self.msg.error_message('''Already voted on 
                                        {}'''.format(identifier))
                    return "already voted"
                else:
                    self.util.retry('''COULD NOT VOTE ON 
                                    {}'''.format(identifier), 
                                    e, num_of_retries, default.wait_time)
                    self.s = None
            else:
                return True
458806
def namedb_get_num_history_rows( cur, history_id ):
    
    ret = []
    select_query = "SELECT COUNT(*) FROM history WHERE history_id = ? ORDER BY block_id ASC, vtxindex ASC;"
    args = (history_id,)

    count = namedb_select_count_rows( cur, select_query, args )
    return count
462232
private int get_polling_period(String name, int src) throws DevFailed {
        //	Get the polling property
        String propname = (src==TangoConst.ATTRIBUTE) ? "polled_attr" : "polled_cmd";
        DbDatum datum = get_property(propname);
        if (datum.is_empty())
            Except.throw_exception("NOT_POLLED",
                    ((src==TangoConst.ATTRIBUTE) ? "Attribute " : "Command ") +
                            name + " not polled",
                    "DbDevice.get_polling_period()");


        String[] str = datum.extractStringArray();
        String _name = name.toLowerCase();
        for (int i = 0 ; i<str.length ; i += 2) {
            //	Check for name
            if (str[i].toLowerCase().equals(_name)) {
                //	not last index.
                if (i<str.length - 1) {
                    try {
                        return Integer.parseInt(str[i + 1]);
                    } catch (NumberFormatException e) {
                        Except.throw_exception("BAD_PARAM",
                                "Period value is not coherent",
                                "DbDevice.get_polling_period()");
                    }
                } else
                    Except.throw_exception("BAD_PARAM",
                            "Period value is not coherent",
                            "DbDevice.get_polling_period()");
            }
        }
        Except.throw_exception("NOT_POLLED",
                ((src==TangoConst.ATTRIBUTE) ? "Attribute " : "Command ") +
                        name + " not polled",
                "DbDevice.get_polling_period()");

        return -1;
    }
1050656
def round_robin?(flight_id=0)
      #each round-robin round should contains n-1 games where n is the nbr of teams (:dummy included if odd)
      return false if self.rounds[flight_id].size != (@flights[flight_id].size*self.cycles)-self.cycles

      #check if each team plays the same number of games against each other
      @flights[flight_id].each do |t1|
        @flights[flight_id].reject{|t| t == t1}.each do |t2|
          return false unless face_to_face(t1,t2).size == self.cycles || [t1,t2].include?(:dummy)
        end
      end
      return true
    end
131439
def find_modified(since, filter_list=None, _connection=None, page_size=25,
        page_number=0, sort_by=enums.DEFAULT_SORT_BY,
        sort_order=enums.DEFAULT_SORT_ORDER):
        
        filters = []
        if filter_list is not None:
            filters = filter_list
        if not isinstance(since, datetime):
            msg = 'The parameter "since" must be a datetime object.'
            raise exceptions.PyBrightcoveError(msg)
        fdate = int(since.strftime("%s")) / 60  ## Minutes since UNIX time
        return connection.ItemResultSet('find_modified_videos',
            Video, _connection, page_size, page_number, sort_by, sort_order,
            from_date=fdate, filter=filters)
736366
def last_round
      last_round = 0
      @player.values.each do |p|
        p.results.each do |r|
          last_round = r.round if r.round > last_round
        end
      end
      last_round
    end
1078339
def _get_candidates(self):
        
        candidates = np.where(self.dpp_vector == 0)
        return None if len(candidates[0]) == 0 else candidates[0]
960059
async def _find_trigger(self,
                            request: Request,
                            origin: Optional[Text]=None,
                            internal: bool=False) \
            -> Tuple[
                Optional[BaseTrigger],
                Optional[Type[BaseState]],
                Optional[bool],
            ]:
        

        reg = request.register

        if not origin:
            origin = reg.get(Register.STATE)
            logger.debug('From state: %s', origin)

        results = await asyncio.gather(*(
            x.rank(request, origin)
            for x
            in self.transitions
            if x.internal == internal
        ))

        if len(results):
            score, trigger, state, dnr = max(results, key=lambda x: x[0])

            if score >= settings.MINIMAL_TRIGGER_SCORE:
                return trigger, state, dnr

        return None, None, None
1048697
def resolve_election_tie(self, candidates):
        
        sorted_candidate_ids = list(sorted(candidates, key=self.candidate_order_fn))
        return sorted_candidate_ids[self.election_tie_cb(candidates)]
442100
def resolve_exclusion_tie(self, candidates):
        
        sorted_candidate_ids = list(sorted(candidates, key=self.candidate_order_fn))
        return sorted_candidate_ids[self.exclusion_tie_cb(candidates)]
348137
def history(self):
        
        history = self.history_class
        if history:
            return self.session.query(history).filter(history.id == self.id)
        else:
            return None
141926
def determine_elected_candidates_in_order(self, candidate_votes):
        
        eligible_by_vote = defaultdict(list)
        for candidate_id, votes in candidate_votes.candidate_votes_iter():
            if candidate_id in self.candidates_elected:
                continue
            if votes < self.quota:
                continue
            eligible_by_vote[votes].append(candidate_id)

        elected = []
        for votes in reversed(sorted(eligible_by_vote)):
            candidate_ids = eligible_by_vote[votes]
            # we sort here to ensure stability, so external callers can hard-coded their response
            candidate_ids.sort(key=self.candidate_order_fn)
            if len(candidate_ids) == 1:
                elected.append(candidate_ids[0])
            else:
                tie_breaker_round = self.find_tie_breaker(candidate_ids)
                if tie_breaker_round is not None:
                    self.results.provision_used(
                        ActProvision("Multiple candidates elected with %d votes. Tie broken from previous totals." % (votes)))
                    for candidate_id in reversed(sorted(candidate_ids, key=tie_breaker_round.get_vote_count)):
                        elected.append(candidate_id)
                else:
                    self.results.provision_used(
                        ActProvision("Multiple candidates elected with %d votes. Input required from Australian Electoral Officer." % (votes)))
                    permutations = list(itertools.permutations(candidate_ids))
                    permutations.sort()
                    choice = self.resolve_election_order(permutations)
                    for candidate_id in permutations[choice]:
                        elected.append(candidate_id)
        return elected
1184044
def nn_poll(fds, timeout=-1):
    
    polls = []
    for i, entry in enumerate(fds.items()):
        s = PollFds()
        fd, event = entry
        s.fd = fd
        s.events = event
        s.revents = 0
        polls.append(s)

    poll_array = (PollFds*len(fds))(*polls)
    res = _nn_poll(poll_array, len(fds), int(timeout))
    if res <= 0:
        return res, {}
    return res, {item.fd: item.revents for item in poll_array}
713196
def process_row(self, row):
        
        division = self.get_division(row)
        if not division:
            return None

        race = self.get_race(row, division)
        election = self.get_election(row, race)
        if not election:
            return None

        party = self.get_or_create_party(row)
        candidate = self.get_or_create_candidate(row, party, race)
        candidate_election = self.get_or_create_candidate_election(
            row, election, candidate, party
        )

        self.get_or_create_ap_election_meta(row, election)
        self.get_or_create_votes(row, division, candidate_election)