Example #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Playback playback = new Playback();

            playback.AddTextTrace(@"..\..\sorted.csv");
            IObservable<PartitionEvent> all = playback.GetObservable<PartitionEvent>();

            all.ObserveOn(this)
                .Subscribe(evt=>
                {
                    double x = (evt.Timeflag-startTime).TotalHours;
                    double y = PartitionY(evt.PartitionId);
                    AddPoint(evt.PartitionId, x, y);
                });

            #region outage detection

            var grouped = (from a in all.GroupByUntil(
                                    evt => evt.PartitionId,
                                    g => Observable.Timer(TimeSpan.FromMinutes(10), playback.Scheduler))
                           from Count in a.Count()
                           where Count > 100
                           select new
                           {
                               PartitionId = a.Key,
                               Count
                           })
                          .Timestamp(playback.Scheduler);


            _subscription = grouped.ObserveOn(this).Subscribe(evt =>
                {
                    double x = (evt.Timestamp - startTime).TotalHours;
                    double y = PartitionY(evt.Value.PartitionId);
                    _detected.Points.AddXY(x, y);
                });

            #endregion

            #region
            //all.Throttle(TimeSpan.FromMinutes(1), playback.Scheduler) // <-- Playback virtual time!
            //    .ObserveOn(this)
            //    .Subscribe(evt =>
            //        {
            //            double horizon = (evt.Timeflag - startTime).TotalHours - 2;
            //            CleanTo(horizon);
            //        });
            #endregion

            playback.Start();
        }