Exemple #1
0
        private async Task <Metar> GetMetarAsync(string icao, bool isParse)
        {
            Metar met = null;

            if (!string.IsNullOrWhiteSpace(icao))
            {
                var url = URL.Replace(@"#", icao.ToUpperInvariant());
                using (var resp = await this.Client.GetAsync(url))
                {
                    using (var stream = await resp.Content.ReadAsStreamAsync())
                    {
                        using (var reader = new StreamReader(stream))
                        {
                            var date = new DateTime(DateTime.Parse(reader.ReadLine().Trim()).Ticks, DateTimeKind.Utc);
                            var raw  = reader.ReadLine().Trim();
                            met = new Metar(raw, date, icao);
                            if (isParse)
                            {
                                met.Parse();
                            }
                        }
                    }
                }
            }
            return(met);
        }
Exemple #2
0
 private static string TranslateMetarToText(Metar metar, AirportIdentifier.Models.AirportIdentifier airportIdentifier)
 {
     return
         ($"Here are the current weather conditions at {airportIdentifier.Name}, {airportIdentifier.Icao.ToPhonetic().Replace(" ", ",")}, " +
          $"As of, {metar.ZuluTime.ToPhonetic()}, " +
          $"wind, {metar.Wind.ToPhonetic()}, " +
          $"visibility, {metar.Visibility.ToPhonetic()}, " +
          $"{metar.Clouds.ToPhonetic()}, " +
          $"{metar.TemperatureAndDewpoint.ToPhonetic()}, " +
          $"altimeter, {metar.Altimeter.ToPhonetic()}");
 }
Exemple #3
0
        private void loadings(string station)
        {
            metList = new List <Metar>();
            try
            {
                string   total = "";
                string[] lines = System.IO.File.ReadAllLines(Sending.directoryUrl + station + "-" + "metar" + ".json");
                foreach (string line in lines)
                {
                    total += line;
                }

                List <MetarOnline> model = JsonConvert.DeserializeObject <List <MetarOnline> >(total);

                for (int d = 0; d < model.Count; d++)
                {
                    u             = new Metar(null);
                    u.Station     = model.ElementAt(d).Station;
                    u.Types       = model.ElementAt(d).Type;
                    u.Datetimes   = model.ElementAt(d).Datetime;
                    u.Timezones   = model.ElementAt(d).Timezone;
                    u.Direction   = model.ElementAt(d).Wind_direction;
                    u.Speed       = model.ElementAt(d).Wind_speed;
                    u.Unit        = model.ElementAt(d).Unit;
                    u.Visibility  = model.ElementAt(d).Visibility;
                    u.Weather     = model.ElementAt(d).Present_weather;
                    u.Cloud       = model.ElementAt(d).Cloud;
                    u.Temperature = model.ElementAt(d).Air_temperature;
                    u.Humidity    = model.ElementAt(d).Humidity;
                    u.Dew         = model.ElementAt(d).Dew_temperature;
                    u.Wet         = model.ElementAt(d).Wet_bulb;
                    u.Stationhpa  = model.ElementAt(d).Station_pressure_hpa;
                    u.Seahpa      = model.ElementAt(d).Sea_pressure_hpa;
                    u.Recent      = model.ElementAt(d).Recent_weather;
                    u.Users       = model.ElementAt(d).User;
                    u.Days        = model.ElementAt(d).Day;
                    metList.Add(u);
                }
                List <Metar> metLists = new List <Metar>(metList.Where(c => Convert.ToDateTime(c.Days).Month.ToString() == (monthTxtCbx.SelectedIndex + 1).ToString() && Convert.ToDateTime(c.Days).Day.ToString() == dayTxtCbx.Text && Convert.ToDateTime(c.Days).Year.ToString() == yearTxtBx.Text));

                MetarGrid.ItemsSource = null;
                MetarGrid.ItemsSource = metLists;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return;
            }
        }
Exemple #4
0
        private void deleteClick(object sender, RoutedEventArgs e)
        {
            Button button = sender as System.Windows.Controls.Button;
            Metar  metar  = button.DataContext as Metar;

            if (MessageBox.Show("Are you sure you want to delete this metar ?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                metar.Delete(metar.Id.ToString());
                RefreshUserList();
            }
            else
            {
                return;
            }
        }
Exemple #5
0
        private string Loading_metar(string station)
        {
            string reply = "";

            try
            {
                string   total = "";
                string[] lines = System.IO.File.ReadAllLines(Sending.directoryUrl + station + "-" + "metar" + ".json");
                foreach (string line in lines)
                {
                    total += line;
                }

                List <MetarOnline> model = JsonConvert.DeserializeObject <List <MetarOnline> >(total);

                for (int d = 0; d < model.Count; d++)
                {
                    m             = new Metar(null);
                    m.Station     = model.ElementAt(d).Station;
                    m.Types       = model.ElementAt(d).Type;
                    m.Datetimes   = model.ElementAt(d).Datetime;
                    m.Timezones   = model.ElementAt(d).Timezone;
                    m.Direction   = model.ElementAt(d).Wind_direction;
                    m.Speed       = model.ElementAt(d).Wind_speed;
                    m.Unit        = model.ElementAt(d).Unit;
                    m.Visibility  = model.ElementAt(d).Visibility;
                    m.Weather     = model.ElementAt(d).Present_weather;
                    m.Cloud       = model.ElementAt(d).Cloud;
                    m.Temperature = model.ElementAt(d).Air_temperature;
                    m.Humidity    = model.ElementAt(d).Humidity;
                    m.Dew         = model.ElementAt(d).Dew_temperature;
                    m.Wet         = model.ElementAt(d).Wet_bulb;
                    m.Stationhpa  = model.ElementAt(d).Station_pressure_hpa;
                    m.Seahpa      = model.ElementAt(d).Sea_pressure_hpa;
                    m.Recent      = model.ElementAt(d).Recent_weather;
                    m.Users       = model.ElementAt(d).User;
                    m.Days        = model.ElementAt(d).Day;
                    m.Sync        = "T";
                    m.Save();
                }
                return("Loaded synoptic information into local database!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return("done loading metars");
            }
        }
Exemple #6
0
        //TODO Add above GetMetarAsync

        private IEnumerable <Metar> GetBulk(bool isParse)
        {
            var metList = new List <Metar>();

            //TODO handle timeout etc
            using (var resp = this.Client.GetAsync(URLBULK).Result)
            {
                using (var stream = resp.Content.ReadAsStreamAsync().Result)
                {
                    using (var gzStream = new GZipStream(stream, CompressionMode.Decompress))
                    {
                        //TODO parallel
                        using (var sr = new StreamReader(gzStream))
                        {
                            //header flag (1st line)
                            bool header = false;

                            while (!sr.EndOfStream)
                            {
                                var line  = sr.ReadLine();
                                var match = Regex.Match(line, SplittPatt);
                                if (match.Success)
                                {
                                    if (header)
                                    {
                                        var met = new Metar(match.Groups["rep"].Value, DateTime.Parse(match.Groups["time"].Value), match.Groups["icao"].Value);
                                        metList.Add(met);
                                        if (isParse)
                                        {
                                            met.Parse();
                                        }
                                    }
                                    else
                                    {
                                        //Skip header line
                                        sr.ReadLine();
                                        header = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(metList);
        }
Exemple #7
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (MessageBox.Show("confirm this information ?" + typeTxtBx.Text + " " + DatetimeTxtBx.Text + " " + VisibilityTxtBx.Text, "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    u = App.WimeaApp.Metars.Add();

                    u.Station     = stationTxtCbx.Text;
                    u.Types       = typeTxtBx.Text;
                    u.Datetimes   = DatetimeTxtBx.Text;
                    u.Timezones   = "GMT";
                    u.Direction   = WindDirectionTxtBx.Text;
                    u.Speed       = "13";
                    u.Unit        = "KT";
                    u.Visibility  = VisibilityTxtBx.Text;
                    u.Weather     = weatherTxtBx.Text;
                    u.Cloud       = CloudTxtBx.Text;
                    u.Temperature = AirTempTxtBx.Text;
                    u.Humidity    = HumidityTxtBx.Text;
                    u.Dew         = DewTxtBx.Text;
                    u.Wet         = WetTxtBx.Text;
                    u.Stationhpa  = StationHpaTxtBx.Text;
                    u.Seahpa      = SeaHpaTxtBx.Text;
                    u.Recent      = RecentTxtBx.Text;
                    u.Users       = "test";
                    u.Days        = DateTime.Now.Date.ToString();
                    u.Sync        = "F";

                    u.Save();
                    RefreshUserList();
                    clear();
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return;
            }
        }
Exemple #8
0
        private bool TryParseVisibilityStatuteMiles(string metarText, Metar metar)
        {
            var match = VisibilityStatuteMilesRegex.Match(metarText);

            if (!match.Success)
            {
                return(false);
            }

            var numerator = match.Groups[Numerator];
            var value     = decimal.Parse(match.Groups[Value].Value);

            metar.Visibility = numerator.Success ? decimal.Parse(numerator.Value) / value : value;

            metar.VisibilityLessThan = match.Groups[LessThan].Success;
            metar.VisibilityUnit     = UnitOfLength.StatuteMiles;

            return(true);
        }
Exemple #9
0
        private bool TryParseVisibilityMeters(string metarText, Metar metar)
        {
            var match = VisibilityMetersRegex.Match(metarText);

            if (!match.Success)
            {
                return(false);
            }

            var visibility = match.Groups[Visibility].Value;

            metar.Visibility = visibility == CloudAndVisibilityOk
                ? VisibilityUnlimited
                : int.Parse(visibility);

            metar.VisibilityUnit = UnitOfLength.Meters;

            return(true);
        }
Exemple #10
0
        public override IWeatherProduct Parse()
        {
            Metar = new Metar();
            var metarText = _request.Metar.ToUpper();

            Metar.OriginalMetar = metarText;

            // Parsers add fields to the Metar and advance parserIndex to the next token
            ParseHeader(metarText);
            ParseDateTime(metarText);
            ParseAutomated(metarText);
            ParseWindVector(metarText);
            ParseVisibility(metarText);
            ParseCloudLayers(metarText);
            ParseTempAndDewpoint(metarText);
            ParseQnh(metarText);

            return(Metar);
        }
Exemple #11
0
        public Metar Parse(string metarText)
        {
            var station = GetFirstOccurrence(StationPattern, metarText);
            var time    = GetFirstOccurrence(TimePattern, metarText);
            var wind    = GetFirstOccurrence(WindPattern, metarText);
            var clouds  = GetAllOccurrences(CloudPattern, metarText);
            var temperatureAndDewpoint = GetFirstOccurrence(TemparatureAndDewpointPattern, metarText);
            var altimeter  = GetFirstOccurrence(AltimeterPattern, metarText);
            var visibility = GetFirstOccurrence(VisibilityPattern, metarText);

            var metar = new Metar()
            {
                RawText                = metarText,
                StationId              = station,
                ZuluTime               = new ZuluTime(time),
                Wind                   = new Wind(wind),
                Visibility             = new Visibility(visibility),
                TemperatureAndDewpoint = new TemperatureAndDewpoint(temperatureAndDewpoint),
                Altimeter              = new Altimeter(altimeter),
                Clouds                 = new Clouds(string.Join(" ", clouds))
            };

            return(metar);
        }
 public DecodeMetarResponse(Metar metar)
 {
     OriginalMetar = metar.OriginalMetar;
     Tokens        = metar.Tokens;
 }
Exemple #13
0
        public ParserContext()
        {
            _metar = new Metar();

            Metar = _metar;
        }