Exemple #1
0
 public HistorianInputQueue(Func <ClientDatabaseBase <HistorianKey, HistorianValue> > getDatabase)
 {
     m_syncWrite       = new object();
     m_blocks          = new IsolatedQueue <PointData>();
     m_pointStream     = new StreamPoints(m_blocks, 1000);
     m_getDatabase     = getDatabase;
     m_worker          = new ScheduledTask(ThreadingMode.DedicatedForeground);
     m_worker.Running += WorkerDoWork;
 }
Exemple #2
0
        /// <summary>
        /// Get custom lengths of split data
        /// </summary>
        /// <param name="SplitDistance">in kilometers as distance is!</param>
        /// <returns></returns>
        public List <MAFStream> GetCustomSplits(float SplitDistance)
        {
            List <MAFStream> data  = new List <MAFStream>();
            MAFStream        split = new MAFStream();

            for (int ind = 0; ind < StreamPoints.Count(); ind++)
            {
                // Get instance of current sample
                MAFStream c = StreamPoints[ind];

                // Skip empty data sets
                if (c.Distance <= 0 || c.Time < new TimeSpan(0, 0, 1))
                {
                    continue;
                }

                // Need to split from this data sample
                if (split.Distance + c.Distance >= SplitDistance)
                {
                    // Calculate distance to take into account
                    var dist = SplitDistance - split.Distance;

                    // Sanity checking
                    if (c.Distance < 0 || c.Time < new TimeSpan(0, 0, 0) || dist > c.Distance)
                    {
                        int k = 2 + 2;
                    }
                    if (dist < 0)
                    {
                        dist = SplitDistance;
                    }

                    // Add to current split
                    split.Altitude    = (c.Altitude * dist + split.Altitude * split.Distance) / (dist + split.Distance);
                    split.Cadence     = (c.Cadence * dist + split.Cadence * split.Distance) / (dist + split.Distance);
                    split.Grade       = (c.Grade * dist + split.Grade * split.Distance) / (dist + split.Distance);
                    split.Heartrate   = (c.Heartrate * dist + split.Heartrate * split.Distance) / (dist + split.Distance);
                    split.Temperature = (c.Temperature * dist + split.Temperature * split.Distance) / (dist + split.Distance);
                    split.Velocity    = (c.Velocity * dist + split.Velocity * split.Distance) / (dist + split.Distance);

                    if (c.Moving == true)
                    {
                        split.Moving = true;
                    }

                    // Add only weighted fraction of the time to this split
                    split.Time     = TimeSpan.FromMilliseconds(((float)c.Time.TotalMilliseconds * dist + (float)split.Time.TotalMilliseconds * split.Distance) / (dist + split.Distance));
                    split.Distance = dist + split.Distance;

                    // Save data
                    data.Add(split);

                    // Add remainder to a new split(s)
                    // Add also full splits if sample distance is larger than desired subset length
                    do
                    {
                        split          = new MAFStream();
                        split.Altitude = c.Altitude;
                        split.Cadence  = c.Cadence;

                        // Calculate remaining length of the split
                        var d = c.Distance - dist;
                        if (d > SplitDistance)
                        {
                            d = SplitDistance;
                        }

                        // Calculate time spent to this split
                        TimeSpan timeSpent = TimeSpan.FromMilliseconds(c.Time.TotalMilliseconds * d / c.Distance);
                        split.Distance    = d;
                        split.Grade       = c.Grade;
                        split.Heartrate   = c.Heartrate;
                        split.Moving      = c.Moving;
                        split.Temperature = c.Temperature;
                        split.Time        = c.Time - timeSpent; // TimeSpan.FromMilliseconds(((float)c.Time.TotalMilliseconds * c.Distance + (float)split.Time.TotalMilliseconds * split.Distance) / (c.Distance + split.Distance));
                        split.Velocity    = c.Velocity;

                        // Decrease c-distance with the amount used already for this split
                        c.Distance -= d;
                        c.Time     -= timeSpent;
                        dist        = d;

                        if (d >= SplitDistance)
                        {
                            //Console.WriteLine(" Split needs extra round");
                            // Save this data before next lap
                            data.Add(split);

                            int k = 2 + 2;
                        }
                    } while (c.Distance >= SplitDistance);
                }
                else
                {
                    // Weighted ratio of current data set vs data already accumulated in the split

                    // Add to current split
                    split.Altitude    = (c.Altitude * c.Distance + split.Altitude * split.Distance) / (c.Distance + split.Distance);
                    split.Cadence     = (c.Cadence * c.Distance + split.Cadence * split.Distance) / (c.Distance + split.Distance);
                    split.Grade       = (c.Grade * c.Distance + split.Grade * split.Distance) / (c.Distance + split.Distance);
                    split.Heartrate   = (c.Heartrate * c.Distance + split.Heartrate * split.Distance) / (c.Distance + split.Distance);
                    split.Temperature = (c.Temperature * c.Distance + split.Temperature * split.Distance) / (c.Distance + split.Distance);
                    split.Velocity    = (c.Velocity * c.Distance + split.Velocity * split.Distance) / (c.Distance + split.Distance);

                    if (c.Moving == true)
                    {
                        split.Moving = true;
                    }

                    split.Time     = c.Time + split.Time;
                    split.Distance = c.Distance + split.Distance;
                }
            }

            // Add remainder of data
            data.Add(split);

            //
            return(data);
        }