Get the health score for a peer.
    Health is: (number of responses received / number of requests sent)
778515
def atlas_peer_get_health( peer_hostport, peer_table=None ):
    
    with AtlasPeerTableLocked(peer_table) as ptbl:
        # availability score: number of responses / number of requests
        num_responses = 0
        num_requests = 0
        if ptbl.has_key(peer_hostport):
            for (t, r) in ptbl[peer_hostport]['time']:
                num_requests += 1
                if r:
                    num_responses += 1

        availability_score = 0.0
        if num_requests > 0:
            availability_score = float(num_responses) / float(num_requests)

    return availability_score
619448
def getStats(self):
        
        stats = protocol.ReadStats()
        stats.aligned_read_count = self._numAlignedReads
        stats.unaligned_read_count = self._numUnalignedReads
        return stats
619306
def health(self):
        """"""
        return json.dumps(dict(uptime='{:.3f}s'
                               .format((time.time() - self._start_time))))
68439
def get_stats(self, request, context):
        """"""
        _log_request(request, context)
        m = self.listener.memory
        return clearly_pb2.StatsMessage(
            task_count=m.task_count,
            event_count=m.event_count,
            len_tasks=len(m.tasks),
            len_workers=len(m.workers)
        )
321582
def stats(self):
        
        response = self.requester.get(
            '/{endpoint}/{id}/stats',
            endpoint=self.endpoint, id=self.id
        )
        return response.json()
34391
async def getHealth(self, *args, **kwargs):
        

        return await self._makeApiCall(self.funcinfo["getHealth"], *args, **kwargs)
1293002
def get_rating_for_user(self, user, ip_address=None, cookies={}):
        """"""
        kwargs = dict(
            content_type    = self.get_content_type(),
            object_id       = self.instance.pk,
            key             = self.field.key,
        )

        if not (user and user.is_authenticated()):
            if not ip_address:
                raise ValueError('``user`` or ``ip_address`` must be present.')
            kwargs['user__isnull'] = True
            kwargs['ip_address'] = ip_address
        else:
            kwargs['user'] = user
        
        use_cookies = (self.field.allow_anonymous and self.field.use_cookies)
        if use_cookies:
            # TODO: move 'vote-%d.%d.%s' to settings or something
            cookie_name = 'vote-%d.%d.%s' % (kwargs['content_type'].pk, kwargs['object_id'], kwargs['key'][:6],) # -> md5_hexdigest?
            cookie = cookies.get(cookie_name)
            if cookie:    
                kwargs['cookie'] = cookie
            else:
                kwargs['cookie__isnull'] = True
            
        try:
            rating = Vote.objects.get(**kwargs)
            return rating.score
        except Vote.MultipleObjectsReturned:
            pass
        except Vote.DoesNotExist:
            pass
        return
842483
def venue_healthcheck(self):
        
        url = urljoin(self.base_url, 'venues/TESTEX/heartbeat')
        return self.session.get(url).json()['ok']
153343
def post_vote(self, post_id, score):
        
        return self._get('posts/{0}/votes.json'.format(post_id),
                         {'score': score}, 'POST', auth=True)
944462
def _calculate_health(self):
        
        if self.redis_connected and self.kafka_connected:
            return "GREEN"
        elif self.redis_connected or self.kafka_connected:
            return "YELLOW"
        else:
            return "RED"
1032744
def getKendallTauScore(myResponse, otherResponse):
    
    # variables
    kt = 0
    list1 = myResponse.values()
    list2 = otherResponse.values()

    if len(list1) <= 1:
        return kt

    # runs through list1
    for itr1 in range(0, len(list1) - 1):
        # runs through list2
        for itr2 in range(itr1 + 1, len(list2)):
            # checks if there is a discrepancy. If so, adds
            if ((list1[itr1] > list1[itr2]
                 and list2[itr1] < list2[itr2])
                or (list1[itr1] < list1[itr2]
                    and list2[itr1] > list2[itr2])):
                kt += 1
    # normalizes between 0 and 1
    kt = (kt * 2) / (len(list1) * (len(list1) - 1))

    # returns found value
    return kt
369442
def total_msg_sent(self):
        
        return (self.get_count(PeerCounterNames.SENT_REFRESH) +
                self.get_count(PeerCounterNames.SENT_UPDATES))
563854
def health_check(self):
        

        api_response = 'Online'

        result = 'Health check on resource {}'.format(self._resource_name)
        try:
            health_check_flow = RunCommandFlow(self.cli_handler, self._logger)
            health_check_flow.execute_flow()
            result += ' passed.'
        except Exception as e:
            self._logger.exception(e)
            api_response = 'Error'
            result += ' failed.'

        try:
            self._api.SetResourceLiveStatus(self._resource_name, api_response, result)
        except Exception:
            self._logger.error('Cannot update {} resource status on portal'.format(self._resource_name))

        return result
659781
def get_health(self):
        
        summary = {'badreadings': [], 'health': const.Health.Ok}
        fallbackreadings = []
        try:
            self.oem_init()
            fallbackreadings = self._oem.get_health(summary)
            for reading in self.get_sensor_data():
                if reading.health != const.Health.Ok:
                    summary['health'] |= reading.health
                    summary['badreadings'].append(reading)
        except exc.BypassGenericBehavior:
            pass
        if not summary['badreadings']:
            summary['badreadings'] = fallbackreadings
        return summary
864684
def count(self):
        
        if hasattr(self, '_response'):
            return self._response.hits.total

        es = connections.get_connection(self._using)

        d = self.to_dict(count=True)
        # TODO: failed shards detection
        return es.count(
            index=self._index,
            body=d,
            **self._params
        )['count']
174477
def _request_status(self):
        
        if self.item_id:
            return True

        response = self.con.get(self.monitor_url)
        if not response:
            return False

        data = response.json()

        self.status = data.get('status', 'inProgress')
        self.completion_percentage = data.get(self._cc('percentageComplete'),
                                              0)
        self.item_id = data.get(self._cc('resourceId'), None)

        return self.item_id is not None
339331
def get_count(self, request, notifications, mark_as_read=False):
        
        return Response({'count': notifications.filter(is_read=False).count()})