示例#1
0
        public void ShuffleStreamable1ColumnarSmallBatch()
        {
            var savedScheduler = Config.StreamScheduler;

            Config.StreamScheduler = StreamScheduler.OwnedThreads(2);
            var gameInput = new[]
            {
                StreamEvent.CreateStart(9900, new GameData {
                    EventType = 0, GameId = 10, UserId = 100
                }),                                                                                       // start game
                StreamEvent.CreateStart(10000, new GameData {
                    EventType = 1, GameId = 10, UserId = 100, NumKills = 1
                }),
                StreamEvent.CreateStart(10020, new GameData {
                    EventType = 1, GameId = 10, UserId = 100, NumKills = 1
                }),
                StreamEvent.CreateStart(10025, new GameData {
                    EventType = 1, GameId = 10, UserId = 100, NumKills = 30
                }),
                StreamEvent.CreateStart(10030, new GameData {
                    EventType = 1, GameId = 10, UserId = 100
                }),                                                                                        // end game
                StreamEvent.CreateStart(10040, new GameData {
                    EventType = 2, GameId = 10
                })
            }.ToObservable().ToStreamable();

            // clip each game event to end at the time of game completion
            var clippedGameInput =
                gameInput.Where(e => e.EventType < 2).ClipEventDuration(gameInput.Where(e => e.EventType == 2), e => e.GameId, e => e.GameId);

            var result =
                clippedGameInput
                .GroupApply(
                    e => new { e.GameId, e.UserId },
                    str => StreamableInternal.ComputeSignalChangeStream(str.Sum(e => e.NumKills)),
                    (g, c) => new { g.Key.GameId, g.Key.UserId, FromKills = c.Item1, ToKills = c.Item2 }) // count #kills per {game,user} combination
            ;

            var finalResultSequence = result
                                      .ToStreamEventObservable()
                                      .ToEnumerable()
                                      .ToList();
            var finalResult = finalResultSequence.First();

            Assert.IsTrue(finalResultSequence.Count() == 1 &&
                          finalResult.IsPunctuation && finalResult.SyncTime == StreamEvent.InfinitySyncTime);

            Config.StreamScheduler.Stop();
            Config.StreamScheduler = savedScheduler;
        }
示例#2
0
        public void Group2ColumnarSmallBatch()
        {
            var gameInput = new[]
            {
                StreamEvent.CreateStart(9900, new GameData {
                    EventType = 0, GameId = 10, UserId = 100
                }),                                                                                       // start game
                StreamEvent.CreateStart(10000, new GameData {
                    EventType = 1, GameId = 10, UserId = 100, NumKills = 1
                }),
                StreamEvent.CreateStart(10020, new GameData {
                    EventType = 1, GameId = 10, UserId = 100, NumKills = 1
                }),
                StreamEvent.CreateStart(10025, new GameData {
                    EventType = 1, GameId = 10, UserId = 100, NumKills = 30
                }),
                StreamEvent.CreateStart(10030, new GameData {
                    EventType = 1, GameId = 10, UserId = 100
                }),                                                                                        // end game
                StreamEvent.CreateStart(10040, new GameData {
                    EventType = 2, GameId = 10
                })
            }.ToObservable().ToStreamable();

            var thresholdInput = new[]
            {
                StreamEvent.CreateStart(9000, new ThresholdData {
                    Threshold = 2, Medal = 43
                }),
                StreamEvent.CreateStart(9000, new ThresholdData {
                    Threshold = 10, Medal = 53
                }),
                StreamEvent.CreateStart(9000, new ThresholdData {
                    Threshold = 20, Medal = 63
                }),
                StreamEvent.CreateEnd(10010, 9000, new ThresholdData {
                    Threshold = 2, Medal = 43
                }),
                StreamEvent.CreateStart(10010, new ThresholdData {
                    Threshold = 3, Medal = 43
                })                                                                              // at time 10010, we change threshold for medal 43, from 2 to 3
            }.ToObservable().ToStreamable();

            // clip each game event to end at the time of game completion
            var clippedGameInput =
                gameInput.Where(e => e.EventType < 2).ClipEventDuration(gameInput.Where(e => e.EventType == 2), e => e.GameId, e => e.GameId);

            var result =
                clippedGameInput
                .GroupApply(e => new { e.GameId, e.UserId }, str => StreamableInternal.ComputeSignalChangeStream(str.Sum(e => e.NumKills)), (g, c) => new { g.Key.GameId, g.Key.UserId, FromKills = c.Item1, ToKills = c.Item2 }) // count #kills per {game,user} combination
            ;

            var finalResultSequence = result
                                      .ToStreamEventObservable()
                                      .ToEnumerable();
            var finalResult = finalResultSequence.First();

            Assert.IsTrue(finalResultSequence.Count() == 1 &&
                          finalResult.IsPunctuation && finalResult.SyncTime == StreamEvent.InfinitySyncTime);

            // Result interpretation:
            // 1. we award user 100 with medal 43 at timestamp 10030 (3rd kill)
            // 2. the event ends at 10040 because the game ends at that timestamp (due to clip)
        }