Format wind elements into a readable sentence

    Returns the translation string

    Ex: NNE-020 (variable 010 to 040) at 14kt gusting to 20kt
482475
def wind(direction: Number,
         speed: Number,
         gust: Number,
         vardir: typing.List[Number] = None,  # type: ignore
         unit: str = 'kt',
         cardinals: bool = True,
         spoken: bool = False) -> str:
    
    ret = ''
    target = 'spoken' if spoken else 'repr'
    # Wind direction
    if direction:
        if direction.repr in WIND_DIR_REPR:
            ret += WIND_DIR_REPR[direction.repr]
        elif direction.value is None:
            ret += direction.repr
        else:
            if cardinals:
                ret += get_cardinal_direction(direction.value) + '-'  # type: ignore
            ret += getattr(direction, target)
    # Variable direction
    if vardir and isinstance(vardir, list):
        vardir = [getattr(var, target) for var in vardir]
        ret += ' (variable {} to {})'.format(*vardir)
    # Speed
    if speed and speed.value:
        ret += f' at {speed.value}{unit}'
    # Gust
    if gust and gust.value:
        ret += f' gusting to {gust.value}{unit}'
    return ret
514674
def wind_shear(shear: str, unit_alt: str = 'ft', unit_wind: str = 'kt') -> str:
    
    unit_alt = SPOKEN_UNITS.get(unit_alt, unit_alt)
    unit_wind = SPOKEN_UNITS.get(unit_wind, unit_wind)
    return translate.wind_shear(shear, unit_alt, unit_wind, spoken=True) or 'Wind shear unknown'
1127547
def parse_na_line(txt: str, units: Units) -> typing.Dict[str, str]:
    
    retwx = {}
    wxdata = txt.split(' ')
    wxdata, _, retwx['wind_shear'] = core.sanitize_report_list(wxdata)
    wxdata, retwx['type'], retwx['start_time'], retwx['end_time'] = core.get_type_and_times(wxdata)
    wxdata, retwx['wind_direction'], retwx['wind_speed'], \
        retwx['wind_gust'], _ = core.get_wind(wxdata, units)
    wxdata, retwx['visibility'] = core.get_visibility(wxdata, units)
    wxdata, retwx['clouds'] = core.get_clouds(wxdata)
    retwx['other'], retwx['altimeter'], retwx['icing'], retwx['turbulance'] \
        = core.get_taf_alt_ice_turb(wxdata)
    return retwx
1090627
function formatSingle(format, val) {
        var floatRegex = /f$/,
          decRegex = /\.([0-9])/,
          lang = defaultOptions.lang,
          decimals;

        if (floatRegex.test(format)) { // float
            decimals = format.match(decRegex);
            decimals = decimals ? decimals[1] : -1;
            if (val !== null) {
                val = numberFormat(
                  val,
                  decimals,
                  lang.decimalPoint,
                  format.indexOf(',') > -1 ? lang.thousandsSep : ''
                );
            }
        } else {
            val = dateFormat(format, val);
        }
        return val;
    }
400341
def str_val(val):
    
    str_val = val
    if val is None:
        str_val = "NA"
    elif type(val) == float:
        str_val = '%0.2f' % val
    else:
        str_val = str(val)
    return str_val
1367039
def pressure_trend_text(trend):
    
    _ = pywws.localisation.translation.ugettext
    if trend > 6.0:
        return _(u'rising very rapidly')
    elif trend > 3.5:
        return _(u'rising quickly')
    elif trend > 1.5:
        return _(u'rising')
    elif trend >= 0.1:
        return _(u'rising slowly')
    elif trend < -6.0:
        return _(u'falling very rapidly')
    elif trend < -3.5:
        return _(u'falling quickly')
    elif trend < -1.5:
        return _(u'falling')
    elif trend <= -0.1:
        return _(u'falling slowly')
    return _(u'steady')
495239
def get_forecast_fromstr(self, reply):
        
        self.forecast = json.loads(reply)

        for item in self.forecast.keys():
            setattr(self, item, self.forecast[item])
266595
private String makeMillisReadable(double lMillis) {
        int hours = 0;
        int minutes = 0;
        int seconds = 0;
        int millis = 0;
        String sTime;
        seconds = (int) (lMillis / 1000) % 60;
        millis = (int) (lMillis % 1000);
        if (seconds > 0) {
            minutes = (int) (lMillis / 1000 / 60) % 60;
            if (minutes > 0) {
                hours = (int) (lMillis / 1000 / 60 / 60) % 24;
                if (hours > 0) {
                    sTime = hours + "h " + minutes + "m " + seconds + "s " + millis + "ms";
                } else {
                    sTime = minutes + "m " + seconds + "s " + millis + "ms";
                }
            } else {
                sTime = seconds + "s " + millis + "ms";
            }
        } else {
            sTime = millis + "ms";
        }
        return sTime;
    }
1241350
def get_weather(self):
        
        import predix.data.weather
        weather = predix.data.weather.WeatherForecast()
        return weather
1335295
def format(self, altitude=None, deg_char='', min_char='m', sec_char='s'):
        
        latitude = "%s %s" % (
            format_degrees(abs(self.latitude), symbols={
                'deg': deg_char, 'arcmin': min_char, 'arcsec': sec_char
            }),
            self.latitude >= 0 and 'N' or 'S'
        )
        longitude = "%s %s" % (
            format_degrees(abs(self.longitude), symbols={
                'deg': deg_char, 'arcmin': min_char, 'arcsec': sec_char
            }),
            self.longitude >= 0 and 'E' or 'W'
        )
        coordinates = [latitude, longitude]

        if altitude is None:
            altitude = bool(self.altitude)
        if altitude:
            if not isinstance(altitude, string_compare):
                altitude = 'km'
            coordinates.append(self.format_altitude(altitude))

        return ", ".join(coordinates)
728391
def _translate_limit(self, len_, start, num):
        
        if start > len_ or num <= 0:
            return 0, 0
        return min(start, len_), num
1196040
def _parse_met(content):
        
        col_names = ['year', 'month', 'day', 'hour', 'minute',
                     'wind_direction', 'wind_speed', 'wind_gust',
                     'wave_height', 'dominant_wave_period', 'average_wave_period',
                     'dominant_wave_direction', 'pressure',
                     'air_temperature', 'water_temperature', 'dewpoint',
                     'visibility', '3hr_pressure_tendency', 'water_level_above_mean']

        col_units = {'wind_direction': 'degrees',
                     'wind_speed': 'meters/second',
                     'wind_gust': 'meters/second',
                     'wave_height': 'meters',
                     'dominant_wave_period': 'seconds',
                     'average_wave_period': 'seconds',
                     'dominant_wave_direction': 'degrees',
                     'pressure': 'hPa',
                     'air_temperature': 'degC',
                     'water_temperature': 'degC',
                     'dewpoint': 'degC',
                     'visibility': 'nautical_mile',
                     '3hr_pressure_tendency': 'hPa',
                     'water_level_above_mean': 'feet',
                     'time': None}

        df = pd.read_table(StringIO(content), comment='#', na_values='MM',
                           names=col_names, sep=r'\s+')
        df['time'] = pd.to_datetime(df[['year', 'month', 'day', 'hour', 'minute']], utc=True)
        df = df.drop(columns=['year', 'month', 'day', 'hour', 'minute'])
        df.units = col_units
        return df
646796
public static String formatLatitude(double latitude, UnitType unit)
    {
        return formatLatitude(Locale.getDefault(), latitude, unit);
    }
257256
def _to_DOM(self):
        
        root_node = ET.Element("forecast")
        interval_node = ET.SubElement(root_node, "interval")
        interval_node.text = self._interval
        reception_time_node = ET.SubElement(root_node, "reception_time")
        reception_time_node.text = str(self._reception_time)
        root_node.append(self._location._to_DOM())
        weathers_node = ET.SubElement(root_node, "weathers")
        for weather in self:
            weathers_node.append(weather._to_DOM())
        return root_node
821151
public static String formatLatitude(Locale locale, double latitude, UnitType unit)
    {
        return format(locale, latitude, unit, NS);
    }
450072
def zambretti_code(params, hourly_data):
    """"""
    north = literal_eval(params.get('Zambretti', 'north', 'True'))
    baro_upper = float(params.get('Zambretti', 'baro upper', '1050.0'))
    baro_lower = float(params.get('Zambretti', 'baro lower', '950.0'))
    if not hourly_data['rel_pressure']:
        return ''
    if hourly_data['wind_ave'] is None or hourly_data['wind_ave'] < 0.3:
        wind = None
    else:
        wind = hourly_data['wind_dir']
    if hourly_data['pressure_trend'] is None:
        trend = 0.0
    else:
        trend = hourly_data['pressure_trend'] / 3.0
    # normalise pressure
    pressure = 950.0 + (
        (1050.0 - 950.0) * (hourly_data['rel_pressure'] - baro_lower) /
        (baro_upper - baro_lower))
    # adjust pressure for wind direction
    if wind is not None:
        if not isinstance(wind, int):
            wind = int(wind + 0.5) % 16
        if not north:
            # southern hemisphere, so add 180 degrees
            wind = (wind + 8) % 16
        pressure += (  5.2,  4.2,  3.2,  1.05, -1.1, -3.15, -5.2, -8.35,
                     -11.5, -9.4, -7.3, -5.25, -3.2, -1.15,  0.9,  3.05)[wind]
    # compute base forecast from pressure and trend (hPa / hour)
    summer = north == (hourly_data['idx'].month >= 4 and
                       hourly_data['idx'].month <= 9)
    if trend >= 0.1:
        # rising pressure
        if summer:
            pressure += 3.2
        F = 0.1740 * (1031.40 - pressure)
        LUT = ('A', 'B', 'B', 'C', 'F', 'G', 'I', 'J', 'L', 'M', 'M', 'Q', 'T',
               'Y')
    elif trend <= -0.1:
        # falling pressure
        if summer:
            pressure -= 3.2
        F = 0.1553 * (1029.95 - pressure)
        LUT = ('B', 'D', 'H', 'O', 'R', 'U', 'V', 'X', 'X', 'Z')
    else:
        # steady
        F = 0.2314 * (1030.81 - pressure)
        LUT = ('A', 'B', 'B', 'B', 'E', 'K', 'N', 'N', 'P', 'P', 'S', 'W', 'W',
               'X', 'X', 'X', 'Z')
    # clip to range of lookup table
    F = min(max(int(F + 0.5), 0), len(LUT) - 1)
    # convert to letter code
    return LUT[F]
387616
public String offset(){
		if(this.forecast.get("offset").asDouble()<0)
			return ""+this.forecast.get("offset").asDouble();
		else if(this.forecast.get("offset").asDouble()>0)
			return ""+"+"+this.forecast.get("offset").asDouble();
		else
			return "";
	}