Returns int based on current flight rules from parsed METAR data

    0=VFR, 1=MVFR, 2=IFR, 3=LIFR

    Note: Common practice is to report IFR if visibility unavailable
779344
def get_flight_rules(vis: Number, ceiling: Cloud) -> int:
    
    # Parse visibility
    if not vis:
        return 2
    if vis.repr == 'CAVOK' or vis.repr.startswith('P6'):
        vis = 10  # type: ignore
    elif vis.repr.startswith('M'):
        vis = 0  # type: ignore
    # Convert meters to miles
    elif len(vis.repr) == 4:
        vis = vis.value * 0.000621371  # type: ignore
    else:
        vis = vis.value  # type: ignore
    # Parse ceiling
    cld = ceiling.altitude if ceiling else 99
    # Determine flight rules
    if (vis <= 5) or (cld <= 30):  # type: ignore
        if (vis < 3) or (cld < 10):  # type: ignore
            if (vis < 1) or (cld < 5):  # type: ignore
                return 3  # LIFR
            return 2  # IFR
        return 1  # MVFR
    return 0
432847
def check_int(num,
              num_descr='number',
              min_value=0,
              max_value=np.Inf):
    """"""

    if not np.isfinite(num) or num < min_value or num > max_value:
        raise ValueError('{}={} is not finite or '
                         'is not >= {} or '
                         'is not < {}'.format(num_descr, num, min_value, max_value))

    return int(num)
900736
def get_metar(
            metar: typing.Union[str, 'CustomMetar']
    ) -> typing.Tuple[typing.Union[str, None], typing.Union['CustomMetar', None]]:
        
        error: typing.Optional[str] = None
        if isinstance(metar, CustomMetar):
            return None, metar

        if isinstance(metar, str):
            LOGGER.debug('building CustomMetar from: %s', metar)
            if len(metar) == 4:
                LOGGER.debug('retrieving METAR from ICAO')
                # NOAA has discontinued their hosting of raw METAR text files ...
                # error, metar = noaa.retrieve_metar(metar)
                # metar = avwx.AVWX.query_icao(metar).rawreport
                metar = AWC.query_icao(metar).raw_metar
        else:
            error = f'expected a string or or a CustomMetar object, got: {type(metar)}'

        if error:
            return error, None

        try:
            return None, CustomMetar(metar_code=metar)
        except ParserError:
            return f'Unable to parse METAR: {metar}', None
410252
def isToneCal(self):
        
        return self.ui.calTypeCmbbx.currentIndex() == self.ui.calTypeCmbbx.count() -1
178780
def getViewportValues(self, view=None):
        
        values = {
            'width': 'device-width',
            'initial-scale': '1.0',
        }

        return ','.join('%s=%s' % (k, v) for k, v in values.items())
596297
def retrieve_metar(station_icao) -> typing.Tuple[typing.Optional[str], typing.Optional[str]]:
    
    url = _BASE_METAR_URL.format(station=station_icao)
    with requests.get(url) as resp:
        if not resp.ok:
            return f'unable to obtain METAR for station {station_icao}\n' \
                   f'Got to "http://tgftp.nws.noaa.gov/data/observations/metar/stations" ' \
                   f'for a list of valid stations', None
        return None, resp.content.decode().split('\n')[1]
83411
function parseIntVersion(vstr) {
    if (!vstr || vstr=='') return 0;
    var ar = vstr.split('.');
    var iVer = 0;
    for (var i=0; i<ar.length; i++) {
        iVer *= 1000;
        iVer += ar[i] >> 0;
    }
    return iVer;
}
393658
def c_mvar(self):
        
        if self.b == -4:
            return 1.0
        elif self.b == -3:
            return 0.0
        elif self.b == -2:
            return -1.0
        elif self.b == -1:
            return -2.0
        elif self.b == 0:
            return -3.0
389827
public static int checkVlen(int i) {
    int count = 0;
    if (i >= -112 && i <= 127) {
      return 1;
    } else {
      int len = -112;
      if (i < 0) {
        i ^= -1L; // take one's complement'
        len = -120;
      }

      long tmp = i;
      while (tmp != 0) {
        tmp = tmp >> 8;
        len--;
      }

      count++;

      len = (len < -120) ? -(len + 120) : -(len + 112);

      while (len != 0) {
        count++;
        len--;
      }

      return count;
    }
  }
638840
def fmtinfo(value):
    
    if value is None:
        raise ValueError('cannot format None!')

    if isinstance(value, text_type):
        return '', value, False

    if isinstance(value, bool):
        # Note: isinstance(True, int) = True, so this must come before the next case.
        if value:
            return 'b', 'y', False
        return 'b', '', False

    if isinstance(value, six.integer_types):
        return 'i', text_type(value), False

    if isinstance(value, float):
        return 'f', text_type(value), True

    if hasattr(value, '__pk_fmtinfo__'):
        return value.__pk_fmtinfo__()

    raise ValueError('don\'t know how to format %r as a measurement' % value)
1150381
def _num_values(self):
        
        # Add min_values to string
        num_values = str(self.min_values) if self.min_values else "0"

        # Handle infinite max_values or finite max_values
        if self.max_values is None or self.max_values == float("inf"):
            num_values += "+"
        else:
            num_values += ".." + str(self.max_values)

        # Return the num_values string
        return num_values
1233342
def get_var_count(self):
        
        n = c_int()
        self.library.get_var_count.argtypes = [POINTER(c_int)]
        self.library.get_var_count(byref(n))
        return n.value
184333
def icao(msg):
    

    DF = df(msg)

    if DF in (11, 17, 18):
        addr = msg[2:8]
    elif DF in (0, 4, 5, 16, 20, 21):
        c0 = bin2int(crc(msg, encode=True))
        c1 = hex2int(msg[-6:])
        addr = '%06X' % (c0 ^ c1)
    else:
        addr = None

    return addr
442046
function converDataValue(value, dimInfo) {
    // Performance sensitive.
    var dimType = dimInfo && dimInfo.type;
    if (dimType === 'ordinal') {
        // If given value is a category string
        var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
        return ordinalMeta
            ? ordinalMeta.parseAndCollect(value)
            : value;
    }

    if (dimType === 'time'
        // spead up when using timestamp
        && typeof value !== 'number'
        && value != null
        && value !== '-'
    ) {
        value = +parseDate(value);
    }

    // dimType defaults 'number'.
    // If dimType is not ordinal and value is null or undefined or NaN or '-',
    // parse to NaN.
    return (value == null || value === '')
        ? NaN
        // If string (like '-'), using '+' parse to NaN
        // If object, also parse to NaN
        : +value;
}
1121179
def get_int(value, default, test_fn=None):
    
    try:
        converted = int(value)
    except ValueError:
        return default

    test_fn = test_fn if test_fn else lambda x: True
    return converted if test_fn(converted) else default
530459
def current_line_num(self):
        '''
        '''
        if self.is_optimized_out():
            return None
        f_trace = self.field('f_trace')
        if long(f_trace) != 0:
            # we have a non-NULL f_trace:
            return self.f_lineno
        else:
            #try:
            return self.co.addr2line(self.f_lasti)
585929
def value(self, data):
        """"""
        value = data.get(self.name)
        if value:
            return int(value)
        return self.default