Ejemplo n.º 1
0
        public void KeyedCollection()
        {
            List <TimestampValue> _list = new List <TimestampValue>();

            DateTime Start = DateTime.Now;

            int n = 100000;

            for (int i = 0; i < n; i++)
            {
                _list.Add(new TimestampValue(Start.AddSeconds(i), i));
            }

            Stopwatch sw = new Stopwatch();

            TimestampSeries ts = new TimestampSeries();

            sw.Reset();
            sw.Start();
            for (int i = n - 1; i > 0; i--)
            {
                ts.AddValue(_list[i].Time, _list[i].Value);
            }
            sw.Stop();
            Console.WriteLine("TimestampSeries:" + sw.Elapsed);

            TimestampSeries2 ts2 = new TimestampSeries2();

            sw.Reset();
            sw.Start();
            for (int i = n - 1; i > 0; i--)
            {
                ts2.AddValue(_list[i].Time, _list[i].Value);
            }
            sw.Stop();
            Console.WriteLine("TimestampSeries2:" + sw.Elapsed);


            sw.Reset();
            sw.Start();
            for (int i = n - 1; i > 0; i--)
            {
                ts2.GetValue(Start.AddSeconds(i));
            }
            sw.Stop();


            sw.Reset();
            sw.Start();
            for (int i = n - 1; i > 0; i--)
            {
                ts.GetValue(Start.AddSeconds(i));
            }
            sw.Stop();
        }
Ejemplo n.º 2
0
    public void KeyedCollection()
    {
      List<TimestampValue> _list = new List<TimestampValue>();

      DateTime Start = DateTime.Now;

      int n = 100000;

      for (int i = 0; i < n; i++)
      {
        _list.Add(new TimestampValue(Start.AddSeconds(i), i));
      }

      Stopwatch sw = new Stopwatch();

      TimestampSeries ts = new TimestampSeries();
      sw.Reset();
      sw.Start();
      for (int i = n - 1; i > 0; i--)
      {
        ts.AddValue(_list[i].Time, _list[i].Value);
      }
      sw.Stop();
      Console.WriteLine("TimestampSeries:" + sw.Elapsed);

      TimestampSeries2 ts2 = new TimestampSeries2();
      sw.Reset();
      sw.Start();
      for (int i = n - 1; i > 0; i--)
      {
        ts2.AddValue(_list[i].Time, _list[i].Value);
      }
      sw.Stop();
      Console.WriteLine("TimestampSeries2:" + sw.Elapsed);


      sw.Reset();
      sw.Start();
      for (int i = n - 1; i > 0; i--)
      {
        ts2.GetValue(Start.AddSeconds(i));
      }
      sw.Stop();


      sw.Reset();
      sw.Start();
      for (int i = n - 1; i > 0; i--)
      {
        ts.GetValue(Start.AddSeconds(i));
      }
      sw.Stop();

    }
Ejemplo n.º 3
0
        public void AddValue()
        {
            TimestampSeries ts = new TimestampSeries();

            ts.AddValue(new DateTime(2010, 1, 2), 1);
            ts.AddValue(new DateTime(2010, 1, 1), 0);
            ts.AddValue(new DateTime(2010, 1, 3), 2);
            ts.AddValue(new DateTime(2010, 1, 4), 3);

            Assert.AreEqual(4, ts.Items.Count);
            Assert.AreEqual(0, ts.Items[0].Value);
            Assert.AreEqual(1, ts.Items[1].Value);
            Assert.AreEqual(2, ts.Items[2].Value);
            Assert.AreEqual(3, ts.Items[3].Value);

            ts.AddValue(new DateTime(2010, 1, 1, 12, 0, 0), 0.5);  //testing isert

            Assert.AreEqual(5, ts.Items.Count);
            Assert.AreEqual(0, ts.Items[0].Value);
            Assert.AreEqual(0.5, ts.Items[1].Value);
            Assert.AreEqual(1, ts.Items[2].Value);
            Assert.AreEqual(2, ts.Items[3].Value);
            Assert.AreEqual(3, ts.Items[4].Value);

            ts.AddValue(new DateTime(2010, 1, 3, 0, 0, 0), 77);  // testing overwrite

            Assert.AreEqual(5, ts.Items.Count);
            Assert.AreEqual(0, ts.Items[0].Value);
            Assert.AreEqual(0.5, ts.Items[1].Value);
            Assert.AreEqual(1, ts.Items[2].Value);
            Assert.AreEqual(77, ts.Items[3].Value);
            Assert.AreEqual(3, ts.Items[4].Value);
        }
Ejemplo n.º 4
0
        public void PropertyChangedEvent()
        {
            TimestampSeries timeSeries = new TimestampSeries();

            timeSeries.Unit = new HydroNumerics.Core.Unit("liter/sec", 0.001, 0.0, "liters pr. second");
            timeSeries.AddValue(new DateTime(2010, 1, 1, 0, 0, 0), 5.0);
            timeSeries.AddValue(new DateTime(2010, 1, 2, 0, 0, 0), 5.0);
            timeSeries.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(timeSeries_PropertyChanged);
            propertyChanged             = false;
            timeSeries.Name             = "something else";
            Assert.IsTrue(propertyChanged);

            propertyChanged           = false;
            timeSeries.Items[0].Value = 7.3;
            Assert.IsTrue(propertyChanged);

            propertyChanged      = false;
            timeSeries.IsVisible = false;
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("IsVisible", changedProperty);

            //TODO: implement test like above for the remaining properties
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Reads all station data from the text stream
        /// </summary>
        /// <param name="SR"></param>
        public void ReadEntryFromText(StreamReader SR)
        {
            string[] line = SR.ReadLine().Split(':');
            if (line.Length != 1)
            {
                int.TryParse(line[1].Trim(), out _dmuStationsNr);
            }

            line = SR.ReadLine().Split(':');
            if (line.Length != 1)
            {
                int.TryParse(line[1].Trim(), out _dmuStedNr);
            }

            _dmuMaalerNr = SR.ReadLine().Split(':')[1].Trim();

            _name = SR.ReadLine().Split(':')[1].Trim();

            line  = SR.ReadLine().Split(',');
            _uTMX = double.Parse(line[0].Split('=')[1].Trim());
            _uTMY = double.Parse(line[1].Split('=')[1].Trim());

            line  = SR.ReadLine().Split(':');
            _area = double.Parse(line[1].Trim().Split(' ')[0].Trim());

            SR.ReadLine();
            SR.ReadLine();

            line = SR.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            while (line.Length != 0 & !SR.EndOfStream)
            {
                DateTime d = new DateTime(int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2]), int.Parse(line[3]), int.Parse(line[4]), 0);
                Discharge.AddValue(d, double.Parse(line[5]));

                line = SR.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            }
        }
Ejemplo n.º 6
0
    public void TestMethod1()
    {

      List<TimestampValue> _list = new List<TimestampValue>();

      DateTime Start = DateTime.Now;

      int n=100000;

      for (int i = 0; i < n; i++)
      {
        _list.Add(new TimestampValue(Start.AddSeconds(i), i));
      }

      Stopwatch sw = new Stopwatch();

      SortedList<DateTime, double> _sortedList = new SortedList<DateTime, double>();

      sw.Start();
      for (int i = n - 1; i > 0; i--)
      {
        _sortedList.Add(_list[i].Time, _list[i].Value);
      }
      sw.Stop();
      Console.WriteLine("SortedList:" + sw.Elapsed);

      SortedDictionary<DateTime, double> _sortedDictionary = new SortedDictionary<DateTime, double>();

      sw.Reset();
      sw.Start();
      for (int i = n - 1; i > 0; i--)
      {
        _sortedDictionary.Add(_list[i].Time, _list[i].Value);
      }

      sw.Stop();
      Console.WriteLine("SortedDictionary:" + sw.Elapsed);

      TimestampSeries ts = new TimestampSeries();
      sw.Reset();
      sw.Start();
      for (int i = n-1; i >0; i--)
      {
        ts.AddValue(_list[i].Time, _list[i].Value);
      }
      sw.Stop();
      Console.WriteLine("TimestampSeries:" + sw.Elapsed);


      List<TimestampValue> _listAndSort = new List<TimestampValue>();
      sw.Reset();
      sw.Start();
      for (int i = n - 1; i > 0; i--)
      {
        _listAndSort.Add(_list[i]);
      }
      _listAndSort.Sort((var,var2) => var.Time.CompareTo(var2.Time));

      sw.Stop();
      Console.WriteLine("_listAndSort:" + sw.Elapsed);

      sw.Reset();
      sw.Start();
      _listAndSort.Sort((var, var2) => var.Time.CompareTo(var2.Time));

      sw.Stop();

      Console.WriteLine("Sort sorted list:" + sw.Elapsed);


    }
Ejemplo n.º 7
0
        public void TestMethod1()
        {
            List <TimestampValue> _list = new List <TimestampValue>();

            DateTime Start = DateTime.Now;

            int n = 100000;

            for (int i = 0; i < n; i++)
            {
                _list.Add(new TimestampValue(Start.AddSeconds(i), i));
            }

            Stopwatch sw = new Stopwatch();

            SortedList <DateTime, double> _sortedList = new SortedList <DateTime, double>();

            sw.Start();
            for (int i = n - 1; i > 0; i--)
            {
                _sortedList.Add(_list[i].Time, _list[i].Value);
            }
            sw.Stop();
            Console.WriteLine("SortedList:" + sw.Elapsed);

            SortedDictionary <DateTime, double> _sortedDictionary = new SortedDictionary <DateTime, double>();

            sw.Reset();
            sw.Start();
            for (int i = n - 1; i > 0; i--)
            {
                _sortedDictionary.Add(_list[i].Time, _list[i].Value);
            }

            sw.Stop();
            Console.WriteLine("SortedDictionary:" + sw.Elapsed);

            TimestampSeries ts = new TimestampSeries();

            sw.Reset();
            sw.Start();
            for (int i = n - 1; i > 0; i--)
            {
                ts.AddValue(_list[i].Time, _list[i].Value);
            }
            sw.Stop();
            Console.WriteLine("TimestampSeries:" + sw.Elapsed);


            List <TimestampValue> _listAndSort = new List <TimestampValue>();

            sw.Reset();
            sw.Start();
            for (int i = n - 1; i > 0; i--)
            {
                _listAndSort.Add(_list[i]);
            }
            _listAndSort.Sort((var, var2) => var.Time.CompareTo(var2.Time));

            sw.Stop();
            Console.WriteLine("_listAndSort:" + sw.Elapsed);

            sw.Reset();
            sw.Start();
            _listAndSort.Sort((var, var2) => var.Time.CompareTo(var2.Time));

            sw.Stop();

            Console.WriteLine("Sort sorted list:" + sw.Elapsed);
        }
Ejemplo n.º 8
0
        public void Paste()
        {
            try
            {
                string clipboardText = Clipboard.GetText();

                string[] strings = clipboardText.Split(new char[2] {
                    '\r', '\n'
                });

                List <string> clipStrings = new List <string>();

                foreach (string str in strings)
                {
                    if (str.Length > 0)
                    {
                        clipStrings.Add(str);
                    }
                }

                bool stringsAreTabSeperatedTimeValues = false;
                foreach (string str in clipStrings)
                {
                    if (str.Contains("\t"))
                    {
                        stringsAreTabSeperatedTimeValues = true;
                    }
                }

                if (stringsAreTabSeperatedTimeValues)
                {
                    List <TimestampValue> tvList = new List <TimestampValue>();

                    foreach (string str in clipStrings)
                    {
                        string[] tvstrings = str.Split(new char[1] {
                            '\t'
                        });

                        DateTime dateTime = Convert.ToDateTime(tvstrings[0]);
                        double   value    = Convert.ToDouble(tvstrings[1]);


                        tvList.Add(new TimestampValue(dateTime, value));
                    }

                    foreach (TimestampValue tv in tvList)
                    {
                        //timeSeriesData.TimeValuesList.Add(tv);
                        timeSeriesData.AddValue(tv.Time, tv.Value);
                    }
                }
                else
                {
                    int selectedRecord = dataGridView1.SelectedCells[0].RowIndex;

                    for (int i = 0; i < clipStrings.Count; i++)
                    {
                        if (selectedRecord + i < timeSeriesData.Items.Count)
                        {
                            timeSeriesData.Items[selectedRecord + i].Value = Convert.ToDouble(clipStrings[i]);
                        }
                        else
                        {
                            timeSeriesData.AppendValue(Convert.ToDouble(clipStrings[i]));
                        }
                    }
                }
                dataGridView1.Refresh();
            }
            catch (Exception e)
            {
                MessageBox.Show("Paste operation failed. Details: " + e.Message);
            }
        }