public static EarthQuakeData EarthQuakeStrong(bool hard, float duration, float frequency)
        {
            EarthQuakeData data = new EarthQuakeData();

            data.hard      = hard;
            data.duration  = duration;
            data.frequency = frequency;
            data.direction = float.NaN;
            data.amplitude = 10f;
            return(data);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens the read completed for CSV file.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Net.OpenReadCompletedEventArgs"/> instance containing the event data.</param>
        private void OpenReadCompletedCsv(object sender, OpenReadCompletedEventArgs e)
        {
            _isBusy = false;

            if (!e.Cancelled && e.Error == null)
            {
                using (var reader = new StreamReader(e.Result))
                {
                    int skipFirstLines = 0; // isFirstTwoLines = true;
                    var escapes        = new[] { '\"', };
                    var listEqd        = new List <EarthQuakeData>();
                    while (reader.Peek() >= 0)
                    {
                        if (skipFirstLines < 2)
                        {
                            // CSV order
                            // Src,Eqid,Version,Datetime(weekday, month data, year hour utc),Lat,Lon,Magnitude,Depth,NST,Region
                            skipFirstLines++;
                            reader.ReadLine();
                        }
                        else
                        {
                            string   s   = reader.ReadLine();
                            string[] csv = s.Split(new[] { ',' });

                            string id    = String.Format("{0}:{1}:{2}", UsGovId, csv[0], csv[1]);
                            string title = csv[11].Trim(escapes);
                            title = title.ToTitle();
                            DateTime updated = DateTime.Parse(String.Format("{0}{1}{2}",
                                                                            csv[3].Trim(escapes), csv[4].Trim(escapes), csv[5]).Trim(escapes).Replace(" UTC", ""),
                                                              CultureInfo.InvariantCulture,
                                                              DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
                            var    link      = new Uri(String.Format(EarthquakesLink, csv[0], csv[1]));
                            double latitude  = Convert.ToDouble(csv[6], CultureInfo.InvariantCulture);
                            double longitude = Convert.ToDouble(csv[7], CultureInfo.InvariantCulture);
                            double depth     = Convert.ToDouble(csv[9], CultureInfo.InvariantCulture) * 1000;
                            double magnitude = Convert.ToDouble(csv[8], CultureInfo.InvariantCulture);
                            var    data      = new EarthQuakeData(id,
                                                                  title,
                                                                  updated,
                                                                  link,
                                                                  latitude,
                                                                  longitude,
                                                                  depth,
                                                                  magnitude);
                            listEqd.Add(data);
                        }
                    }
                    NewEarthquakesRecieved(listEqd);
                }
            }
        }
Exemplo n.º 3
0
        public static EarthQuakes ProcessEarthQuakes(ShapefileConverter shapefile)
        {
            var earthQuakes = new EarthQuakes();

            foreach (ShapefileRecord record in shapefile)
            {
                var item = new EarthQuakeData();
                if (record.Fields != null)
                {
                    // get geo-location from shape file (SHP)
                    //location.Longitude = record.Points[0][0].X;
                    //location.Latitude = record.Points[0][0].Y;
                    // get data about a location from database file (DBF)
                    //if (record.Fields.ContainsKey("lon")) item.Longitude = (double)(record.Fields["lon"]);
                    //if (record.Fields.ContainsKey("lat")) item.Latitude = (double)(record.Fields["lat"]);

                    //if (record.Fields.ContainsKey("eqid")) item.Id = (string)(record.Fields["eqid"]);
                    //if (record.Fields.ContainsKey("depth")) item.Depth = (double)(record.Fields["depth"]);
                    //if (record.Fields.ContainsKey("magnitude")) item.Magnitude = (double)(record.Fields["magnitude"]);
                    //if (record.Fields.ContainsKey("region")) item.Region = (string)(record.Fields["region"]);
                    //if (record.Fields.ContainsKey("datetime")) item.Description = (string)(record.Fields["datetime"]);
                    // TODO-MT parse date time
                    //location.Updated = (System.DateTime)(record.Fields["datetime"]); // Sun Jun 13 00:00:00 -0400 2010

                    item.Longitude   = record.Fields.GetValue <double>("lon");
                    item.Latitude    = record.Fields.GetValue <double>("lat");
                    item.Code        = record.Fields.GetValue <string>("eqid");
                    item.Depth       = record.Fields.GetValue <double>("depth");
                    item.Magnitude   = record.Fields.GetValue <double>("magnitude");
                    item.Region      = record.Fields.GetValue <string>("region");
                    item.Description = record.Fields.GetValue <string>("datetime");

                    item.Label = "Earthquake: " + item.Magnitude + Environment.NewLine + item.Region
                                 //  + Environment.NewLine + "Longitude: " + String.Format("{0:0.0}", item.Longitude)
                                 //  + Environment.NewLine + "Latitude: " + String.Format("{0:0.0}", item.Latitude)
                                 + Environment.NewLine + "Location: " + String.Format("{0:0.0}", item.Longitude) + ", "
                                 + String.Format("{0:0.0}", item.Latitude);

                    // update countries stats
                    earthQuakes.Magnitude.Update(item.Magnitude);
                    earthQuakes.Depth.Update(item.Depth);

                    // add an item to data collection
                    earthQuakes.Add(item);
                }
            }

            return(earthQuakes);
        }
Exemplo n.º 4
0
 private bool IsFilterMatch(EarthQuakeData e)
 {
     return(e.Magnitude >= MinMagnitude && e.Magnitude <= MaxMagnitude && _selectedRegions.Contains(e.Region));
 }
Exemplo n.º 5
0
        private void NewEarthquakesRecieved(List <EarthQuakeData> result)
        {
            EarthQuakeData latestEarthquake = LatestEarthquake;

            if (!_firstDataLoaded)
            {
                _firstDataLoaded = true;

                if (result.Count > 0)
                {
                    //Assign a region
                    foreach (EarthQuakeData earthquake in result)
                    {
                        earthquake.Region = _continentsList.FindRegion(new Point(earthquake.Longitude, earthquake.Latitude)) ?? "Other";
                    }
                    //Order from newer to older
                    result.Sort((x, y) => - (Comparer <DateTime> .Default.Compare(x.Updated, y.Updated)));
                    latestEarthquake = result[0];
                }
                _allEarthquakes = result;
            }
            else
            {
                //Remove older entries that are not reported now
                int i = 0;
                while (i < _allEarthquakes.Count)
                {
                    if (result.Contains(_allEarthquakes[i]))
                    {
                        ++i;
                    }
                    else
                    {
                        _allEarthquakes.RemoveAt(i);
                    }
                }

                //Add newer entries that are not in the _allEarthquakes list preserving the newer to older order
                foreach (EarthQuakeData earthquake in result)
                {
                    i = 0;
                    bool isNew = true;
                    while (i < _allEarthquakes.Count)
                    {
                        if (earthquake.Updated > _allEarthquakes[i].Updated)
                        {
                            break;
                        }
                        if (earthquake.Equals(_allEarthquakes[i]))
                        {
                            isNew = false;
                            break;
                        }
                        ++i;
                    }

                    if (isNew)
                    {
                        //Assign a region
                        earthquake.Region = _continentsList.FindRegion(new Point(earthquake.Longitude, earthquake.Latitude)) ?? "Other";

                        _allEarthquakes.Insert(i, earthquake);
                        if (i == 0)
                        {
                            latestEarthquake = earthquake;
                        }
                    }
                }
            }

            LastUpdated = DateTime.UtcNow;
            UpdateEarthquakes();
            LatestEarthquake = latestEarthquake;
        }