Example #1
0
        public void TestToString()
        {
            DateTime now            = DateTime.Now;
            int      windDirection  = 270;
            float    windSpeed      = 1.1f;
            float    gust           = 2.2f;
            float    waveHeight     = 3.3f;
            float    airTemp        = 4.4f;
            float    seaSurfaceTemp = 5.5f;
            BuoyInfo buoyInfo       = new BuoyInfo(now, windDirection, windSpeed, gust, waveHeight, airTemp, seaSurfaceTemp);

            Assert.AreEqual(
                String.Format("Date: {0} Wind Direction: {1} Wind Speed: {2} Gust: {3} Wave Height: {4} Air Temp: {5} Sea Surface Temp: {6}",
                              now.ToShortDateString(),
                              windDirection,
                              windSpeed,
                              gust,
                              waveHeight,
                              airTemp,
                              seaSurfaceTemp), buoyInfo.ToString());
        }
Example #2
0
        private List<BuoyInfo> getBuoyInfo()
        {



            Console.Write("Getting data from...");
            Console.WriteLine(_path);


            List<BuoyInfo> buoyDataList = new List<BuoyInfo>();

            StreamReader stream;
            try
            {
                stream = new StreamReader(_path);

                
            } catch (FileNotFoundException)
            {
                Console.WriteLine("File could not be read.");
                return buoyDataList;
            }



            string header1 = stream.ReadLine();
            string header2 = stream.ReadLine();




            string dataString = stream.ReadLine();

            while (dataString != null)
            {

                // Replace any whitespace with a comma so that we can split it

                dataString = Regex.Replace(dataString, @"\s+", ",");

                string[] data = dataString.Split(',');




                int count = 0;

                foreach (string element in data)
                {

                    if (element.Equals("MM"))
                    {
                        if (count >= 6 && count <= 14)
                        {
                            data[count] = Single.MaxValue.ToString();
                        }
                        else
                        {
                            data[count] = Int32.MaxValue.ToString();
                        }
                    }

                    count++;
                }

                int month = Int32.Parse(data[1]);
                int day = Int32.Parse(data[2]);
                int hour = Int32.Parse(data[3]);
                int minute = Int32.Parse(data[4]);
                int windDirection = Int32.Parse(data[5]);
                float windSpeed = Single.Parse(data[6]);
                float gust = Single.Parse(data[7]);
                float waveHeight = Single.Parse(data[8]);
                float airTemp = Single.Parse(data[13]);
                float seaSurfaceTemp = Single.Parse(data[14]);

                // get current year
                DateTime now = DateTime.Now;
                int year = now.Year;


                DateTime date = new DateTime(year, month, day, hour, minute, 0);

                BuoyInfo info = new BuoyInfo(date, windDirection, windSpeed, gust, waveHeight, airTemp, seaSurfaceTemp);

                buoyDataList.Add(info);
                dataString = stream.ReadLine();

            }


            // we're done reading from the file

            stream.Close();


            return buoyDataList;
        }