public void Scenario1()
    {
        var scheduler = new TestScheduler();
        var live      = scheduler.CreateHotObservable <Timestamped <int> >(
            OnNext(100, Timestamped.Create(1, new DateTimeOffset(100, TimeSpan.Zero))),
            OnNext(101, Timestamped.Create(1, new DateTimeOffset(200, TimeSpan.Zero))),
            OnNext(102, Timestamped.Create(2, new DateTimeOffset(300, TimeSpan.Zero))),
            OnNext(103, Timestamped.Create(2, new DateTimeOffset(400, TimeSpan.Zero))),
            OnNext(104, Timestamped.Create(3, new DateTimeOffset(450, TimeSpan.Zero))),
            OnNext(105, Timestamped.Create(3, new DateTimeOffset(455, TimeSpan.Zero))),
            OnCompleted <Timestamped <int> >(105)
            );

        var windows = live.WindowByTimestamp(
            x => x.Timestamp.Ticks,
            TimeSpan.FromTicks(200));

        var numberedWindows = windows.SelectMany((x, i) =>
                                                 x.Select(y => new {
            WindowNumber = i,
            Timestamp    = y.Timestamp,
            Value        = y.Value
        }));

        numberedWindows.Subscribe(x => Console.WriteLine(
                                      "Window: {0}, Time: {1} Value: {2}",
                                      x.WindowNumber, x.Timestamp.Ticks, x.Value));

        scheduler.Start();
    }
Exemple #2
0
 static IObservable <Timestamped <bool> > GetTimestampedDigitalInput(IObservable <HarpMessage> source, byte eventMask, byte bitmask)
 {
     return(GetTimestampedState(source).Where(state => (state.Value & eventMask) == eventMask).Select(state =>
     {
         return Timestamped.Create((state.Value & bitmask) == bitmask, state.Seconds);
     }));
 }
Exemple #3
0
        public void Timestamped_Create()
        {
            var o  = DateTimeOffset.UtcNow;
            var ti = Timestamped.Create(42, o);

            Assert.AreEqual(42, ti.Value);
            Assert.AreEqual(o, ti.Timestamp);
        }
 static IObservable <Timestamped <Mat> > GetTimestampedPhotodiodes(IObservable <HarpMessage> source)
 {
     return(source.Event(Registers.Photodiodes).Select(input =>
     {
         var payload = input.GetTimestampedPayloadArray <ushort>();
         return Timestamped.Create(FromPayloadArray(payload.Value), payload.Seconds);
     }));
 }
Exemple #5
0
 static IObservable <Timestamped <double> > GetTimestampedTemperature(IObservable <HarpMessage> source)
 {
     return(source.Event(Registers.Temperature).Select(input =>
     {
         var payload = input.GetTimestampedPayloadUInt16();
         return Timestamped.Create(FromRawTemperature(payload.Value), payload.Seconds);
     }));
 }
Exemple #6
0
        public void HistoricalScheduler()
        {
            // Arrange
            var baseTime = DateTimeOffset.Now;

            var scheduler = new HistoricalScheduler(baseTime);

            var expectedValues = new[]
            {
                Timestamped.Create(0L, baseTime + TimeSpan.FromSeconds(10)),
                Timestamped.Create(1L, baseTime + TimeSpan.FromSeconds(20)),
                Timestamped.Create(4L, baseTime + TimeSpan.FromSeconds(30)),
                Timestamped.Create(9L, baseTime + TimeSpan.FromSeconds(40)),
                Timestamped.Create(16L, baseTime + TimeSpan.FromSeconds(50)),
                Timestamped.Create(25L, baseTime + TimeSpan.FromSeconds(60))
            };

            var actualValues = new List <Timestamped <long> >();

            var source = Observable
                         .Interval(TimeSpan.FromSeconds(10), scheduler)
                         .Select(x => x * x)
                         .Take(6);

            var testSource = source
                             .Timestamp(scheduler)
                             .Do(x => actualValues.Add(x));

            // Act
            testSource.Subscribe();
            scheduler.Start();

            // Assert
            if (expectedValues.SequenceEqual(actualValues, TestDataEqualityComparer.Instance))
            {
                Console.WriteLine("The test was successful");
            }
            else
            {
                Console.WriteLine("The test failed");
            }
        }
    void Start()
    {
        var shortcut = new KeyCode[] { KeyCode.LeftControl, KeyCode.A };

        var tabPressed = gameObject.UpdateAsObservable()
                         .Where(_ => Input.GetKeyDown(KeyCode.A))
                         .Select(_ => KeyCode.A);

        var ctrlPressed = gameObject.UpdateAsObservable()
                          .Where(_ => Input.GetKey(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                          .Select(_ => KeyCode.LeftControl);

        IObservable <KeyCode> observableKeyPresses =
            shortcut.ToObservable()
            .SelectMany(
                keycode => gameObject.UpdateAsObservable()
                .Where(_ => Input.GetKey(keycode) || Input.GetKeyDown(keycode))
                .Select(_ => keycode)
                );

        observableKeyPresses
        .Scan(new List <Timestamped <KeyCode> >()
        {
        }, (x, y) => { x.Add(Timestamped.Create(y, DateTimeOffset.Now)); return(x); })
        .Where(_ => _.Count >= shortcut.Length && _.Select(ç => ç.Value).ToList().GetRange(_.Count - shortcut.Length, shortcut.Length).SequenceEqual(shortcut))
        .Where(_ => _[_.Count - shortcut.Length].Timestamp.AddMilliseconds(100) >= DateTimeOffset.Now)
        .Subscribe(_ => Debug.Log("Shortcut pressed"));


        //ctrlPressed
        //  .Merge(tabPressed)
        //  .Scan(new List<KeyCode>() { }, (x, y) => { x.Add(y); return x; })
        //  .Where(_ => _.Count >= shortcut.Length && _.GetRange(_.Count - shortcut.Length, shortcut.Length).SequenceEqual(shortcut))
        //  .Subscribe(_ => Debug.Log("Ctrl a pressed"));

        //ctrlPressed
        //    .Merge(tabPressed)
        //    .Pairwise()
        //    .Where(_ => _.Previous == KeyCode.LeftControl && _.Current == KeyCode.A)
        //    .TimeInterval()
        //    .Subscribe(_ => Debug.Log("Ctrl a pressed"));
    }
Exemple #8
0
            private Task <T> ProcessRequestAsync <T>(object arg0, object arg1 = null, object arg2 = null, [CallerMemberName] string methodName = null)
            {
                var request = new LuisRequest
                {
                    Method    = methodName,
                    Arguments = new[] { arg0, arg1, arg2 },
                };

                this.RequestsInternal.Add(Timestamped.Create(request));

                this.OnRequest?.Invoke(request);

                var response = this.OnRequestResponse?.Invoke(request);

                if (response == null && IsTrainingStatusRequest(request))
                {
                    response = Array.Empty <ModelTrainingInfo>();
                }

                return(Task.FromResult((T)response));
            }