Ejemplo n.º 1
0
        private List <DateTimeValues> DoMovingAverage(List <DateTimeValues> values)
        {
            myMovingAvFilteredDataResult = new List <DateTimeValues>();

            DateTimeValues myResultData;

            double[] _values = new double[values.Count];

            for (int i = 0; i < _values.Length / 2; i++)
            {
                for (int j = 0; j < (int)numMAverage.Value; j++)
                {
                    _values[i] += values[j + i].values;
                }
                _values[i] /= (int)numMAverage.Value;
            }

            for (int i = _values.Length - 1; i >= _values.Length / 2; i--)
            {
                for (int j = 0; j < (int)numMAverage.Value; j++)
                {
                    _values[i] += values[i - j].values;
                }
                _values[i] = _values[i] / (int)numMAverage.Value;
            }


            for (int i = 0; i < _values.Length; i++)
            {
                myResultData = new DateTimeValues
                {
                    dateTime = values[i].dateTime,
                    values   = _values[i]
                };

                myMovingAvFilteredDataResult.Add(myResultData);
            }

            return(myMovingAvFilteredDataResult);
        }
Ejemplo n.º 2
0
        private List <DateTimeValues> DoPolynomialRegression(List <DateTimeValues> values)
        {
            DateTimeValues myResultData;

            myPolyFilteredDataResult = new List <DateTimeValues>();

            TimeSpan timeSpan = values[values.Count - 1].dateTime - values[0].dateTime;

            double[] _values = new double[values.Count];
            double[] _time   = new double[values.Count];

            for (int i = 0; i < values.Count; i++)
            {
                _time[i]   = i * (Math.Round(timeSpan.TotalSeconds) / values.Count);
                _values[i] = values[i].values;
            }

            double[] p = Fit.Polynomial(_time, _values, (int)numRank.Value, MathNet.Numerics.LinearRegression.DirectRegressionMethod.QR);

            for (int i = 0; i < timeSpan.TotalSeconds - 1; i++)
            {
                myResultData = new DateTimeValues
                {
                    dateTime = values[0].dateTime.AddSeconds(i),

                    values = p[0]
                };

                for (int z = 1; z < p.Length; z++)
                {
                    myResultData.values += p[z] * Math.Pow(i, z);
                }

                myPolyFilteredDataResult.Add(myResultData);
            }

            return(myPolyFilteredDataResult);
        }
Ejemplo n.º 3
0
        public void GetData(string _dataFile)
        {
            StreamReader sr = new StreamReader(_dataFile);

            string[] separators = { "!", "?", ";", ",", "\t" };



            while (!sr.EndOfStream)
            {
                myData = new DateTimeValues();

                string[] _values;

                _values = sr.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);

                if (_values.Length != 0)
                {
                    if (DateTime.TryParse(_values[0], out DateTime dateValue))
                    {
                        myData.dateTime = dateValue;
                        myData.values   = Convert.ToDouble(_values[1]);
                        myValues.Add(myData);
                    }
                    else if (DateTime.TryParse(_values[0], CultureInfo.CreateSpecificCulture("en-US"), DateTimeStyles.AssumeLocal, out dateValue))
                    {
                        myData.dateTime = dateValue;
                        myData.values   = Convert.ToDouble(_values[1]);
                        myValues.Add(myData);
                    }
                }
            }

            // Zeitdifferenz setzen wenn benötigt
            //tideData.dateTime = tideData.dateTime.AddHours(2);
        }