get measure of correctness available for a particular response
768190
def get_correctness_for_response(self, response):
        """"""
        for answer in self.my_osid_object.get_answers():
            if self._is_match(response, answer):
                try:
                    return answer.get_score()
                except AttributeError:
                    return 100
        for answer in self.my_osid_object.get_wrong_answers():
            if self._is_match(response, answer):
                try:
                    return answer.get_score()
                except AttributeError:
                    return 0
        return 0
1343866
def get_status(self, response, finished=False):
        """"""
        status_pos = 0
        for line in response.split("\n"):
            if line.startswith('JOBID'):
                try:
                    status_pos = line.find('STAT')
                except ValueError:
                    return None
            else:
                status = line[status_pos:].split()[0]
                if status in self.status_mapping:
                    return self.status_mapping[status]
        return None
954394
def accuracy(logits, labels):
  """"""
  is_correct = tf.nn.in_top_k(logits, labels, 1)
  correct = tf.reduce_sum(tf.cast(is_correct, tf.int32))
  incorrect = tf.reduce_sum(tf.cast(tf.logical_not(is_correct), tf.int32))
  correct_count = tf.Variable(0, False)
  incorrect_count = tf.Variable(0, False)
  correct_count_update = tf.assign_add(correct_count, correct)
  incorrect_count_update = tf.assign_add(incorrect_count, incorrect)
  accuracy_op = tf.cast(correct_count, tf.float32) / tf.cast(
      correct_count + incorrect_count, tf.float32)
  return [correct_count_update, incorrect_count_update], accuracy_op
1075615
def compute_quality_score(self, quality):
        """"""
        score = 0
        UNIT = 2
        if 'frequency' in quality:
            # TODO: should be related to frequency.
            if quality['update_in'] < 0:
                score += UNIT
            else:
                score -= UNIT
        if 'tags_count' in quality:
            if quality['tags_count'] > 3:
                score += UNIT
        if 'description_length' in quality:
            if quality['description_length'] > 100:
                score += UNIT
        if 'has_resources' in quality:
            if quality['has_only_closed_or_no_formats']:
                score -= UNIT
            else:
                score += UNIT
            if quality['has_unavailable_resources']:
                score -= UNIT
            else:
                score += UNIT
        if 'discussions' in quality:
            if quality['has_untreated_discussions']:
                score -= UNIT
            else:
                score += UNIT
        if score < 0:
            return 0
        return score
448446
async def check_response(response, valid_response_codes):
    """"""
    if response.status == 204:
        return True
    if response.status in valid_response_codes:
        _js = await response.json()
        return _js
    else:
        raise PvApiResponseStatusError(response.status)
1116861
def check_response (self):
        """"""
        if self.url_connection.status_code >= 400:
            self.set_result(u"%d %s" % (self.url_connection.status_code, self.url_connection.reason),
                            valid=False)
        else:
            if self.url_connection.status_code == 204:
                # no content
                self.add_warning(self.url_connection.reason,
                                 tag=WARN_HTTP_EMPTY_CONTENT)
            if self.url_connection.status_code >= 200:
                self.set_result(u"%r %s" % (self.url_connection.status_code, self.url_connection.reason))
            else:
                self.set_result(_("OK"))
1018463
def sr(self, multi=0):
        """"""  # noqa: E501
        remain = self.res[:]
        sr = []
        i = 0
        while i < len(remain):
            s = remain[i]
            j = i
            while j < len(remain) - 1:
                j += 1
                r = remain[j]
                if r.answers(s):
                    sr.append((s, r))
                    if multi:
                        remain[i]._answered = 1
                        remain[j]._answered = 2
                        continue
                    del(remain[j])
                    del(remain[i])
                    i -= 1
                    break
            i += 1
        if multi:
            remain = [x for x in remain if not hasattr(x, "_answered")]
        return SndRcvList(sr), PacketList(remain)
1324183
private void checkMeasure(TypeCheckInfo question, SFunctionDefinitionBase node, ILexNameToken iLexNameToken, PType result)
	{
		PTypeAssistantTC assistant = question.assistantFactory.createPTypeAssistant();
		
		if (!assistant.isNumeric(result))
		{
			if (assistant.isProduct(result))
			{
				AProductType pt = assistant.getProduct(result);

				for (PType t : pt.getTypes())
				{
					if (!assistant.isNumeric(t))
					{
						TypeCheckerErrors.report(3272, "Measure range is not a nat, or a nat tuple", node.getMeasure().getLocation(), node.getMeasure());
						TypeCheckerErrors.detail("Actual", result);
						break;
					}
				}
			}
			else
			{
				TypeCheckerErrors.report(3272, "Measure range is not a nat, or a nat tuple", node.getMeasure().getLocation(), node.getMeasure());
				TypeCheckerErrors.detail("Actual", result);
			}
		}
	}
1285390
def _check_response(response, expected):
        

        response_code = response.status_code
        if expected == response_code:
            return

        if response_code < 400:
            raise ex.UnexpectedResponseCodeException(response.text)

        elif response_code == 401:
            raise ex.UnauthorizedException(response.text)

        elif response_code == 400:
            raise ex.BadRequestException(response.text)

        elif response_code == 403:
            raise ex.ForbiddenException(response.text)

        elif response_code == 404:
            raise ex.NotFoundException(response.text)

        elif response_code == 429:
            raise ex.RateLimitedException(response.text)

        else:
            raise ex.InternalServerErrorException(response.text)
462732
def _check_response_for_errors(self, response):
        """"""

        try:
            doc = minidom.parseString(_string(response).replace("opensearch:", ""))
        except Exception as e:
            raise MalformedResponseError(self.network, e)

        e = doc.getElementsByTagName("lfm")[0]
        # logger.debug(doc.toprettyxml())

        if e.getAttribute("status") != "ok":
            e = doc.getElementsByTagName("error")[0]
            status = e.getAttribute("code")
            details = e.firstChild.data.strip()
            raise WSError(self.network, status, details)
1117338
def reply_ok(self):
        """"""
        return (self.mtype == self.REPLY and self.arguments and
                self.arguments[0] == self.OK)
1010909
def measurementReport():
    """"""
    a = TpPd(pd=0x6)
    b = MessageType(mesType=0x15)  # 00010101
    c = MeasurementResults()
    packet = a / b / c
    return packet
1079482
def _rsq_adj(self):
        """"""
        n = self.n
        k = self.k
        return 1.0 - ((1.0 - self._rsq) * (n - 1.0) / (n - k - 1.0))
557321
def answers(self, other):
        """"""
        if other.__class__ == self.__class__:
            return (other.service + 0x40) == self.service or \
                   (self.service == 0x7f and
                    self.request_service_id == other.service)
        return False
817042
def to_bool(answer, default):
    
    answer = str(answer).lower()
    default = str(default).lower()

    if answer and answer in "yes":
        return True

    return False
1273961
def _process_response(cls, response):
        
        if len(response) != 1:
            raise BadResponseError("Malformed response: {}".format(response))

        stats = list(itervalues(response))[0]
        if not len(stats):
            raise BadResponseError("Malformed response for host: {}".format(stats))

        return stats
278447
def verify_response_time(self, expected_below):
        
        if self.timedelta > expected_below:
            raise ValueError("Response time is more (%f) than expected (%f)!"
                             % (self.timedelta, expected_below))