Esempio n. 1
0
        protected override async void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            ToolTipService.ShowDurationProperty.OverrideMetadata(
                typeof(DependencyObject), new FrameworkPropertyMetadata(int.MaxValue));   // Tooltip opened indefinitly until mouse is moved

            serviceProvider = Sidekick.Startup.InitializeServices(this);

            Legacy.Initialize(serviceProvider);

            Legacy.ViewLocator.Open <Windows.SplashScreen>();

            await RunAutoUpdate();

            EnsureSingleInstance();

            await serviceProvider.GetService <IInitializer>().Initialize();

            // Overlay.
            OverlayController.Initialize();

            // League Overlay
            LeagueOverlayController.Initialize();

            EventsHandler.Initialize();

            // Price Prediction
            PredictionController.Initialize();
        }
Esempio n. 2
0
        public void GetPrediction_With_Date_Supplied()
        {
            //Arrange
            //date is in September
            string date       = "2020-09-14";
            var    controller = new PredictionController(MockWeatherEngine);

            //Act
            IHttpActionResult actionResult = controller.Get(date);
            var contentResult = actionResult as OkNegotiatedContentResult <RainfallResultViewModel>;

            //Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(MockRainfallResultViewModel1.MeanPrcp, contentResult.Content.MeanPrcp);
            Assert.AreEqual(MockRainfallResultViewModel1.StdDev, contentResult.Content.StdDev);

            //Arrange
            //date is in January
            date = "01-31-2021";

            //Act
            actionResult  = controller.Get(date);
            contentResult = actionResult as OkNegotiatedContentResult <RainfallResultViewModel>;

            //Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(MockRainfallResultViewModel2.MeanPrcp, contentResult.Content.MeanPrcp);
            Assert.AreEqual(MockRainfallResultViewModel2.StdDev, contentResult.Content.StdDev);
        }
Esempio n. 3
0
        public void SeparateEntriesForCreatedCards()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
                "Alleycat"
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            opponent.KnownCards = CardList(new List <string> {
                "Alleycat"
            });
            opponent.KnownCards[0].IsCreated = true;
            var info = GetPredictionInfo(controller);

            Assert.AreEqual(2, info.PredictedCards.Count);
            var originalCardInfo = info.PredictedCards[0];

            Assert.AreEqual(0, originalCardInfo.NumPlayed);
            Assert.AreEqual(1, originalCardInfo.Card.Count);
            Assert.IsFalse(originalCardInfo.Card.IsCreated);
            var createdCardInfo = info.PredictedCards[1];

            Assert.AreEqual(1, createdCardInfo.NumPlayed);
            Assert.AreEqual(1, createdCardInfo.Card.Count);
            Assert.IsTrue(createdCardInfo.Card.IsCreated);
        }
Esempio n. 4
0
        private PredictionInfo GetPredictionInfo(PredictionController controller)
        {
            PredictionInfo info = null;

            controller.OnPredictionUpdate.Add(p => info = p);
            controller.UpdatePrediction();
            return(info);
        }
Esempio n. 5
0
 protected override void OnExit(ExitEventArgs e)
 {
     trayIcon?.Dispose();
     serviceProvider.Dispose();
     OverlayController.Dispose();
     PredictionController.Dispose();
     base.OnExit(e);
 }
Esempio n. 6
0
        public static List <double> CalculateAverageRMSE(string dirWithFiles, IEnumerable <IPredictionAlgorithm> algorithms, out double averagePredictionNum, out double averageActualPrice)
        {
            List <double> rmseValues = new List <double>();

            List <List <double> > rmseLists = InitRmseLists(algorithms.Count());

            string[] filesPath = System.IO.Directory.GetFiles(dirWithFiles);

            //IEnumerable<BasicDataset> predicted = PredictionController.Predict(filesPath[0], new MovingAverage, out IEnumerable<BasicDataset> datasets);

            int fileNum = 1;

            averagePredictionNum = 0; averageActualPrice = 0;

            foreach (string filePath in filesPath)
            {
                int alghNum = 0;

                try
                {
                    foreach (IPredictionAlgorithm algorithm in algorithms)
                    {
                        IEnumerable <BasicDataset> predicted = PredictionController.Predict(filePath, algorithm, out IEnumerable <BasicDataset> datasets);

                        datasets = datasets.OrderBy(a => a.Date);

                        averagePredictionNum += predicted.Count();

                        ++fileNum;

                        SplitSet(datasets, out IEnumerable <BasicDataset> trainingSet, out IEnumerable <BasicDataset> controlSet);

                        averageActualPrice += controlSet.Select(a => (double)a.Close).Average();

                        double rmse = GetRMSEAnother(controlSet, predicted);

                        rmseLists[alghNum++].Add(rmse);
                    }
                }
                catch
                {
                }
            }

            foreach (List <double> rmseList in rmseLists)
            {
                rmseValues.Add(rmseList.Average());
            }

            averagePredictionNum /= fileNum;
            averageActualPrice   /= fileNum;

            return(rmseValues);
        }
Esempio n. 7
0
        public void CardPlayedNotInMetaDecksIsMarkedOffMeta()
        {
            var opponent = new MockOpponent("Hunter");

            opponent.KnownCards = CardList(new List <string> {
                "Alleycat"
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());
            var info       = GetPredictionInfo(controller);

            Assert.IsTrue(info.PredictedCards[0].OffMeta);
        }
Esempio n. 8
0
        public void OnOpponentHandDiscard_CallsOnPredictionUpdate()
        {
            var opponent   = new MockOpponent("Hunter");
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            bool called = false;

            controller.OnPredictionUpdate.Add(prediction => called = true);
            controller.OnOpponentHandDiscard(null);

            Assert.IsTrue(called);
        }
Esempio n. 9
0
        public void CardPlayabilityAboveAvailableManaForNextTurn()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
                "Deadly Shot"
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());
            var info       = GetPredictionInfo(controller);

            Assert.AreEqual(PlayableType.AboveAvailableMana, info.PredictedCards[0].Playability);
        }
Esempio n. 10
0
        public void UpdatesWithNoDeckIfClassMismatch()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Mage", new List <string> {
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            var info = GetPredictionInfo(controller);

            Assert.AreEqual(0, info.NumPossibleDecks);
        }
Esempio n. 11
0
        public void GetPrediction_With_Invalid_Date_Supplied()
        {
            //Arrange
            string date       = "2020-02-30";
            var    controller = new PredictionController(MockWeatherEngine);

            // Act
            IHttpActionResult actionResult = controller.Get(date);

            // Assert
            Assert.AreEqual(actionResult.ToString(), "System.Web.Http.Results.BadRequestErrorMessageResult");
            Console.WriteLine(actionResult);
        }
Esempio n. 12
0
        public void UpdatesWithMetaDeck()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
                "Deadly Shot"
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            var info = GetPredictionInfo(controller);

            Assert.AreEqual(1, info.NumPossibleDecks);
        }
Esempio n. 13
0
        public void OnOpponentDraw_SecondTimeDoesNotCallOnPredictionUpdate()
        {
            var opponent   = new MockOpponent("Hunter");
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            controller.OnOpponentDraw();

            bool called = false;

            controller.OnPredictionUpdate.Add(prediction => called = true);
            controller.OnOpponentDraw();

            Assert.IsFalse(called);
        }
Esempio n. 14
0
        public void JoustedCardCanBeOffMeta()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
            });
            opponent.KnownCards = CardList(new List <string> {
                "Alleycat"
            });
            opponent.KnownCards[0].Jousted = true;
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());
            var info       = GetPredictionInfo(controller);

            Assert.IsTrue(info.PredictedCards[0].OffMeta);
        }
Esempio n. 15
0
        public void JoustedCardsAreAddedButPlayedCountIsZero()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
            });
            opponent.KnownCards = CardList(new List <string> {
                "Alleycat"
            });
            opponent.KnownCards[0].Jousted = true;
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());
            var info       = GetPredictionInfo(controller);

            Assert.AreEqual(0, info.PredictedCards[0].NumPlayed);
        }
Esempio n. 16
0
        public static void Process()
        {
            while (instance.pInputQueue.Count > 0)
            {
                DataMessage msg = instance.pInputQueue.Dequeue();

                if (msg.dataType == DATAMESSAGE_TYPE.LATENCY_CHECK)
                {
                    PredictionController.Instance().Process(msg as LatencyCheckMessage);
                }
                else
                {
                    GameManager.RecieveMessage(msg);
                }
            }
        }
Esempio n. 17
0
        public void MarksCardsAlreadyPlayed()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
                "Alleycat"
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            opponent.KnownCards = CardList(new List <string> {
                "Alleycat"
            });
            var info = GetPredictionInfo(controller);

            Assert.AreEqual(1, info.PredictedCards[0].NumPlayed);
        }
Esempio n. 18
0
        public void UpdatesWithFullCardList()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
                "Deadly Shot", "Alleycat", "Bear Trap"
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            var info = GetPredictionInfo(controller);

            CollectionAssert.AreEqual(CardList(new List <string> {
                "Deadly Shot", "Alleycat", "Bear Trap"
            }),
                                      CardsFromInfo(info));
        }
Esempio n. 19
0
        public void BetShouldReturnViewWIthValidModel()
        {
            //Arrange
            var userManager = UserManagerMock.New;

            userManager.Setup(u => u.GetUserId(It.IsAny <ClaimsPrincipal>()))
            .Returns(userId);

            var predictionService = new Mock <IPredictionService>();

            predictionService.Setup(p => p.GetActiveMatches(userId))
            .Returns(new List <MatchServiceModel>()
            {
                firstMatch, secondMatch
            }.AsQueryable());

            predictionService.Setup(r => r.GetActiveRoundNumber()).
            Returns(RoundNumber);

            predictionService.Setup(p => p.IsCurrentRoundPredicted(userId))
            .Returns(false);

            var controller = new PredictionController(predictionService.Object, userManager.Object);

            Mapper.Initialize();

            //Act
            var result = controller.Bet();

            //Assert
            result.Should().BeOfType <ViewResult>();

            var model = result.As <ViewResult>().Model;

            model.Should().BeOfType <ActiveRoundViewModel>();

            var formModel = model.As <ActiveRoundViewModel>();

            formModel.AlreadyPredicted.Should().Be(false);
            formModel.Matches.Count.Should().Be(1);
            formModel.StartedMatches.Count.Should().Be(1);
            formModel.Matches.First().HomeTeam.Should().Be(firstMatch.HomeTeam);
            formModel.Matches.First().AwayTeam.Should().Be(firstMatch.AwayTeam);
            formModel.StartedMatches.First().HomeTeam.Should().Be(secondMatch.HomeTeam);
            formModel.StartedMatches.First().AwayTeam.Should().Be(secondMatch.AwayTeam);
            formModel.RoundNumber.Should().Be(RoundNumber);
        }
Esempio n. 20
0
        public void SortEntriesByCreated()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
                "Bear Trap"
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            opponent.KnownCards = CardList(new List <string> {
                "Bear Trap", "Bear Trap"
            });
            opponent.KnownCards[0].IsCreated = true;
            var info = GetPredictionInfo(controller);

            Assert.IsFalse(info.PredictedCards[0].Card.IsCreated);
        }
Esempio n. 21
0
        public void SortEntriesByManaCost()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
                "Alleycat"
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            opponent.KnownCards = CardList(new List <string> {
                "Bear Trap"
            });
            opponent.KnownCards[0].IsCreated = true;
            var info = GetPredictionInfo(controller);

            Assert.AreEqual("Alleycat", info.PredictedCards[0].Card.Name);
        }
Esempio n. 22
0
        public void SecondOffMetaCardIncludedInPrediction()
        {
            AddMetaDeck("Hunter", new List <string> {
                "Alleycat"
            });
            var opponent = new MockOpponent("Hunter");

            opponent.KnownCards = CardList(new List <string> {
                "Alleycat"
            }, new List <int> {
                2
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());
            var info       = GetPredictionInfo(controller);

            Assert.AreEqual(2, info.PredictedCards[0].Card.Count);
        }
Esempio n. 23
0
        public void GetPrediction_No_Date_Supplied()
        {
            //Arrange
            var controller = new PredictionController(MockWeatherEngine);

            // Act
            IHttpActionResult actionResult = controller.Get();
            var contentResult = actionResult as OkNegotiatedContentResult <RainfallResultViewModel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);

            //since current date varies, we will just assert that we have some values for mean and std
            Assert.IsTrue(contentResult.Content.MeanPrcp > 0);
            Assert.IsTrue(contentResult.Content.StdDev > 0);
        }
Esempio n. 24
0
        public void AddsInCardsNotInMetaDecks()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter", new List <string> {
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            opponent.KnownCards = CardList(new List <string> {
                "Alleycat"
            });
            var info = GetPredictionInfo(controller);

            CollectionAssert.AreEqual(CardList(new List <string> {
                "Alleycat"
            }), CardsFromInfo(info));
            Assert.AreEqual(1, info.PredictedCards[0].NumPlayed);
        }
Esempio n. 25
0
        public void OnTurnStart_DoesNotUpdateAvailableManaOnOpponentTurn()
        {
            var opponent = new MockOpponent("Hunter");

            opponent.Mana = 1;
            AddMetaDeck("Hunter", new List <string> {
                "Alleycat"
            });
            AddMetaDeck("Hunter", new List <string> {
                "Alleycat", "Bear Trap"
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            opponent.Mana = 2;
            controller.OnTurnStart(ActivePlayer.Opponent);

            var info = GetPredictionInfo(controller);

            Assert.AreEqual(1, info.PredictedCards.Count);
        }
Esempio n. 26
0
        public void BetPostSuccessfulySavedScoreAndRedirectToGetBet()
        {
            // Arrange
            ActiveRoundViewModel model = GetActiveRoundViewModel(ResultEnum.DRAW);
            string successMessage      = null;
            var    tempData            = new Mock <ITempDataDictionary>();

            tempData
            .SetupSet(t => t[WebConstants.TempDataSuccessMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => successMessage = message as string);

            var userManager = UserManagerMock.New;

            userManager.Setup(u => u.GetUserId(It.IsAny <ClaimsPrincipal>()))
            .Returns(userId);

            var predictionService = new Mock <IPredictionService>();

            predictionService.Setup(p => p.GetCurrentActiveMatchesIds())
            .Returns(new List <int>()
            {
                firstMatch.Id, secondMatch.Id
            });

            predictionService.Setup(p => p.AddPrediction(null, null));
            var controller = new PredictionController(predictionService.Object, userManager.Object);

            controller.TempData = tempData.Object;

            // Act
            var result = controller.Bet(model);

            // Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            redirectToActionResult.ControllerName.Should().Be(null);
            redirectToActionResult.ActionName.Should().BeEquivalentTo("Bet");
            successMessage.Should().Be(MessageResources.msgSuccessfulPredictions);
        }
Esempio n. 27
0
        public void BetPostReturnViewWithModelWhenAnyNonPredictedMatch()
        {
            // Arrange
            string errorMessage        = null;
            ActiveRoundViewModel model = GetActiveRoundViewModel();
            var tempData = new Mock <ITempDataDictionary>();

            tempData
            .SetupSet(t => t[WebConstants.TempDataErrorMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => errorMessage = message as string);


            var controller = new PredictionController(null, null);

            controller.TempData = tempData.Object;
            // Act
            var result = controller.Bet(model);

            // Assert
            result.Should().BeOfType <ViewResult>();

            var viewModel = result.As <ViewResult>().Model;

            viewModel.Should().BeOfType <ActiveRoundViewModel>();

            var formModel = viewModel.As <ActiveRoundViewModel>();

            formModel.AlreadyPredicted.Should().Be(false);
            formModel.Matches.Count.Should().Be(2);
            formModel.Matches.First().HomeTeam.Should().Be(firstMatch.HomeTeam);
            formModel.Matches.First().AwayTeam.Should().Be(firstMatch.AwayTeam);
            formModel.Matches.Last().HomeTeam.Should().Be(secondMatch.HomeTeam);
            formModel.Matches.Last().AwayTeam.Should().Be(secondMatch.AwayTeam);
            formModel.RoundNumber.Should().Be(RoundNumber);

            errorMessage.Should().Be(MessageResources.msgBetAllMatches);
        }
Esempio n. 28
0
        public void UpdatesWithMultipleCopies()
        {
            var opponent = new MockOpponent("Hunter");

            AddMetaDeck("Hunter",
                        new List <string> {
                "Alleycat", "Deadly Shot", "Bear Trap"
            },
                        new List <int> {
                1, 2, 1
            });
            var controller = new PredictionController(opponent, _metaDecks.AsReadOnly());

            var info             = GetPredictionInfo(controller);
            var expectedCardList = CardList(
                new List <string> {
                "Alleycat", "Deadly Shot", "Bear Trap"
            },
                new List <int> {
                1, 2, 1
            });

            CollectionAssert.AreEqual(expectedCardList, CardsFromInfo(info));
        }
Esempio n. 29
0
        private static IEnumerable <BasicDataset> GetPrediction(FileTransferRequest request)
        {
            IPredictionAlgorithm algorithm = ChosePredictionAlgorithm(request.SelectedAlgortihms);

            return(PredictionController.Predict(request.FileBytes, algorithm));
        }