示例#1
0
        public DataTable GenerateTypeTable(Earthquake.EarthquakeType type)//Enum
        {
            DataTable table = GenerateEmptyTable();

            foreach (Earthquake earthquake in earthquakes)
            {
                if (type == earthquake.Type)
                {
                    DataRow row = table.NewRow();

                    row["ID"]             = earthquake.Id;
                    row["DATE"]           = earthquake.Date;
                    row["LATITUDE"]       = earthquake.Latitude;
                    row["LONGITUDE"]      = earthquake.Longitude;
                    row["TYPE"]           = earthquake.Type;
                    row["DEPTH"]          = earthquake.Depth;
                    row["MAGNITUDE"]      = earthquake.Magnitude;
                    row["MAGNITUDE TYPE"] = earthquake.MagnitudeType;

                    table.Rows.Add(row);
                }
            }

            return(table);
        }
示例#2
0
        //Load
        public void Load(string path)
        {
            string[] info = File.ReadAllLines(path);
            System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");

            for (int i = 1; i < info.Length; i++)
            {
                //Split
                string[] dataInfo = Regex.Split(info[i], ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
                //...

                //Add
                try
                {
                    //Id
                    string id = dataInfo[16];
                    //Latitude
                    double latitude = Double.Parse(dataInfo[2], culture);
                    //Latitude
                    double longitude = Double.Parse(dataInfo[3], culture);
                    //Date
                    string[] dateInfo = dataInfo[0].Split('/');
                    string[] timeInfo = dataInfo[1].Split(':');
                    DateTime date     = new DateTime(Int32.Parse(dateInfo[2]), Int32.Parse(dateInfo[0]), Int32.Parse(dateInfo[1]), Int32.Parse(timeInfo[0]), Int32.Parse(timeInfo[1]), Int32.Parse(timeInfo[2]));
                    //Type
                    string typeS = dataInfo[4].Replace(' ', '_').ToUpper();
                    Earthquake.EarthquakeType type = (Earthquake.EarthquakeType)Enum.Parse(typeof(Earthquake.EarthquakeType), typeS);
                    //Depth
                    double depth = Double.Parse(dataInfo[5], culture);
                    //Magnitude
                    double magnitude = Double.Parse(dataInfo[8], culture);
                    //MagnitudeType
                    Earthquake.EarthquakeMagnitudeType magnitudeType = Earthquake.EarthquakeMagnitudeType.NAN;
                    if (!String.IsNullOrEmpty(dataInfo[9]))
                    {
                        magnitudeType = (Earthquake.EarthquakeMagnitudeType)Enum.Parse(typeof(Earthquake.EarthquakeMagnitudeType), dataInfo[9]);
                    }

                    Earthquake eq = new Earthquake(id, latitude, longitude, date, type, depth, magnitude, magnitudeType);
                    earthquakes.Add(eq);
                }
                catch (IndexOutOfRangeException)
                {
                    Console.WriteLine("Error en dato!");
                }
                //...
            }
        }
示例#3
0
        public double AverageMagnitude(Earthquake.EarthquakeType type)
        {
            double average = 0;

            int quanity = 0;

            foreach (Earthquake earthquake in earthquakes)
            {
                if (earthquake.Type == type)
                {
                    average += earthquake.Magnitude;
                    quanity++;
                }
            }
            average /= quanity;

            return(average);
        }