public void test_Balance_Calculation_Multiple_Divisions()
        {
            Dictionary <Team, List <Player> > pitcherDataByTeam = new Dictionary <Team, List <Player> >();

            setupTestTeams(pitcherDataByTeam);

            Dictionary <String, List <Player> > pitcherDataByBalance = SOMTeamReportFile.organizePitcherByBalance(pitcherDataByTeam);
            SOMTeamReportFile teamReportFile = new SOMTeamReportFile(pitcherDataByBalance, pitcherDataByTeam);

            IUsageCalculator calculator = CalculatorFactory.getCalculator(CalculatorFactory.CalculatorType.SP_SCHEDULE, teamReportFile, buildTeam("TEST1", IN_DIVISION));

            calculator.setOptions(CalculatorOptions.OPTION_IN_DIVISION_GAMES, 26);
            calculator.setOptions(CalculatorOptions.OPTION_OUT_DIVISION_GAMES, 14);

            List <Dictionary <int, int> > results = calculator.calculate();

            verifyBasicLineupStructure(results);

            // Test L-1R
            runLineupTest(results, createTestTeamLineup("L", "1R", "1R"), 11);

            // Test L 9L->9R
            runLineupTest(results, createTestTeamLineup("L", "9L", "9R"), 158);

            // Test R 9R->9R
            runLineupTest(results, createTestTeamLineup("R", "9L", "9R"), 483);

            // Test R E
            runLineupTest(results, createTestTeamLineup("R", "E", "E"), 62);

            // Test R 6R-9R
            runLineupTest(results, createTestTeamLineup("R", "6R", "9R"), 25);
        }
        private void CB_LIST_OF_TEAMS_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dialogInitialized)
            {
                if (CB_LIST_OF_TEAMS.SelectedItem is Team)
                {
                    currentlySelectedTeam = (Team)CB_LIST_OF_TEAMS.SelectedItem;

                    TeamLineup selectedTeamLineup = LineupPersistence.lookupTeamLineup(engine.StoredLineups, currentlySelectedTeam);
                    System.Console.WriteLine(currentlySelectedTeam.Abrv + " contains " + selectedTeamLineup.Lineups.Count + " lineups.");

                    List <Player> players = engine.TeamReportFile.getTeamBatters(currentlySelectedTeam);
                    batterInfo.setPlayers(players);
                    IUsageCalculator calculator = CalculatorFactory.getCalculator(USAGE_CALCULATOR, engine.TeamReportFile, currentlySelectedTeam);
                    calculator.setOptions(CalculatorOptions.OPTION_IN_DIVISION_GAMES, engine.TeamLineupData.InDivisionGameCount);
                    calculator.setOptions(CalculatorOptions.OPTION_OUT_DIVISION_GAMES, engine.TeamLineupData.OutofDivisionGameCount);
                    //TODO: Add UI element for Target At Bats
                    calculator.setOptions(CalculatorOptions.OPTION_TARGET_AT_BAT, 615);

                    engine.BalanceAtBats = balanceUsage.buildTable(calculator);

                    updateWorkbook(currentlySelectedTeam, players);

                    fillBoxesWithSavedDataData();

                    BTN_MANAGE_LINEUPS.IsEnabled = true;
                }
            }
        }
        public void test_SP_Straight_Calculation()
        {
            Dictionary <Team, List <Player> > pitcherDataByTeam = new Dictionary <Team, List <Player> >();

            setupTestTeams(pitcherDataByTeam);

            Dictionary <String, List <Player> > pitcherDataByBalance = SOMTeamReportFile.organizePitcherByBalance(pitcherDataByTeam);
            SOMTeamReportFile teamReportFile = new SOMTeamReportFile(pitcherDataByBalance, pitcherDataByTeam);

            IUsageCalculator calculator           = CalculatorFactory.getCalculator(CalculatorFactory.CalculatorType.SP_BASIC, teamReportFile, buildTeam("TEST1", IN_DIVISION));
            List <Dictionary <int, int> > results = calculator.calculate();

            verifyBasicLineupStructure(results);

            // Test L-1R
            runLineupTest(results, createTestTeamLineup("L", "1R", "1R"), 11);

            // Test L 9L->9R
            runLineupTest(results, createTestTeamLineup("L", "9L", "9R"), 152);

            // Test R 9R->9R
            runLineupTest(results, createTestTeamLineup("R", "9L", "9R"), 473);

            // Test R E
            runLineupTest(results, createTestTeamLineup("R", "E", "E"), 61);

            // Test R 6R-9R
            runLineupTest(results, createTestTeamLineup("R", "6R", "9R"), 24);

            // Test L 6R-8R
            runLineupTest(results, createTestTeamLineup("L", "6R", "8R"), 0);
        }
Exemplo n.º 4
0
        public List <Dictionary <int, int> > buildTable(IUsageCalculator calculator)
        {
            if (InfoGrid != null)
            {
                clearInfoTable(InfoGrid);
            }

            return(calculator.calculate(createRow));
        }
Exemplo n.º 5
0
        public MainWindowViewModel(IModule module, IUsageCalculator usageCalculator)
        {
            SearchText              = "";
            SearchResults           = new ObservableCollection <ISelectable>();
            _autoCompleteDataSource = module.Examples.Select(ex => ex.Value.Title).ToList();

            WithTrait <AutoCompleteSearchBehaviour>();
            WithTrait <InitializationBehaviour>();

            _hideSearchCommand = new ActionCommand(() =>
            {
                SearchText = null;
            });

            _showSettingsCommand = new ActionCommand(() =>
            {
                IsSettingsShow     = true;
                BlurOnSearchParams = _blurredParams;
            });

            _hideSettingsCommand = new ActionCommand(() =>
            {
                IsSettingsShow     = false;
                BlurOnSearchParams = _defaultParams;
            });

            _exportCommand = new ActionCommand(() =>
            {
                _hideSettingsCommand.Execute(null);
                DeveloperModManager.Manage.IsDeveloperMode = false;
                TimedMethod.Invoke(() => HtmlExportHelper.ExportExampleToHtml(SelectedExample)).After(1000).Go();
            }, () => SelectedExample != null);

            _exportAllHtmlCommand = new ActionCommand(() =>
            {
                _hideSettingsCommand.Execute(null);
                DeveloperModManager.Manage.IsDeveloperMode = false;
                TimedMethod.Invoke(() => HtmlExportHelper.ExportExamplesToHtml(module)).After(1000).Go();
            }, () => SelectedExample != null);

            _exportAllSolutionsCommand = new ActionCommand(() =>
            {
                _hideSettingsCommand.Execute(null);
                ExportExampleHelper.ExportExamplesToSolutions(module);
            }, () => SelectedExample != null);

            _gcCollectCommand = new ActionCommand(() =>
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForFullGCApproach();
            });
        }
Exemplo n.º 6
0
        private Navigator()
        {
            _usageCalculator = ServiceLocator.Container.Resolve <IUsageCalculator>();
            _history         = new NavigationHistory();

            _mainFrame             = new MainFrame();
            _examplesFrame         = new ExamplesFrame();
            _goBackCommand         = new ActionCommand(GoBack, () => CanGoBack);
            _goForwardCommand      = new ActionCommand(GoForward, () => CanGoForward);
            _navigateToHomeCommand = new ActionCommand(() => Instance.GoToHome(), () => Instance.CurrentPage == null || Instance.CurrentPage.PageId != AppPage.HomePageId);
        }
        public void test_Balance_Calculation_Multiple_Divisions_On_Original_Spreadsheet()
        {
            Dictionary <Team, List <Player> > pitcherDataByTeam = new Dictionary <Team, List <Player> >();

            setupTestTeams(pitcherDataByTeam);

            Dictionary <String, List <Player> > pitcherDataByBalance = SOMTeamReportFile.organizePitcherByBalance(pitcherDataByTeam);
            SOMTeamReportFile teamReportFile = new SOMTeamReportFile(pitcherDataByBalance, pitcherDataByTeam);

            IUsageCalculator calculator = CalculatorFactory.getCalculator(CalculatorFactory.CalculatorType.SP_SCHEDULE, teamReportFile, buildTeam("TEST1", IN_DIVISION));

            calculator.setOptions(CalculatorOptions.OPTION_IN_DIVISION_GAMES, 26);
            calculator.setOptions(CalculatorOptions.OPTION_OUT_DIVISION_GAMES, 14);

            List <Dictionary <int, int> > results = calculator.calculate();

            verifyBasicLineupStructure(results);

            int idx = 0;

            for (int i = 8; i >= 0; i--)
            {
                int[] expectedLLeft  = { 0, 0, 0, 0, 0, 0, 20, 11, 34 };
                int[] expectedLRight = { 8, 0, 14, 0, 11, 0, 8, 96, 94 };

                // Test L-1R
                runLineupTest(results, createTestTeamLineup("L", (i + 1) + "L", (i + 1) + "L"), expectedLLeft[idx]);
                runLineupTest(results, createTestTeamLineup("R", (i + 1) + "L", (i + 1) + "L"), expectedLRight[idx]);
                idx++;
            }

            int expectedELeft  = 17;
            int expectedERight = 62;

            runLineupTest(results, createTestTeamLineup("L", "E", "E"), expectedELeft);
            runLineupTest(results, createTestTeamLineup("R", "E", "E"), expectedERight);

            for (int i = 0; i <= 8; i++)
            {
                int[] expectedRLeft  = { 11, 25, 12, 0, 0, 0, 0, 0, 28 };
                int[] expectedRRight = { 29, 57, 34, 45, 0, 19, 0, 6, 0 };

                // Test L-1R
                runLineupTest(results, createTestTeamLineup("L", (i + 1) + "R", (i + 1) + "R"), expectedRLeft[i]);
                runLineupTest(results, createTestTeamLineup("R", (i + 1) + "R", (i + 1) + "R"), expectedRRight[i]);
            }
        }
        public void test_SP_Straight_Based_On_Original_Spreadsheet()
        {
            Dictionary <Team, List <Player> > pitcherDataByTeam = new Dictionary <Team, List <Player> >();

            setupTestTeams(pitcherDataByTeam);

            Dictionary <String, List <Player> > pitcherDataByBalance = SOMTeamReportFile.organizePitcherByBalance(pitcherDataByTeam);
            SOMTeamReportFile teamReportFile = new SOMTeamReportFile(pitcherDataByBalance, pitcherDataByTeam);

            IUsageCalculator calculator           = CalculatorFactory.getCalculator(CalculatorFactory.CalculatorType.SP_BASIC, teamReportFile, buildTeam("TEST1", IN_DIVISION));
            List <Dictionary <int, int> > results = calculator.calculate();

            verifyBasicLineupStructure(results);

            int idx = 0;

            for (int i = 8; i >= 0; i--)
            {
                int[] expectedLLeft  = { 0, 0, 0, 0, 0, 0, 19, 10, 33 };
                int[] expectedLRight = { 7, 0, 13, 0, 10, 0, 7, 95, 94 };

                // Test L-1R
                runLineupTest(results, createTestTeamLineup("L", (i + 1) + "L", (i + 1) + "L"), expectedLLeft[idx]);
                runLineupTest(results, createTestTeamLineup("R", (i + 1) + "L", (i + 1) + "L"), expectedLRight[idx]);
                idx++;
            }

            int expectedELeft  = 16;
            int expectedERight = 61;

            runLineupTest(results, createTestTeamLineup("L", "E", "E"), expectedELeft);
            runLineupTest(results, createTestTeamLineup("R", "E", "E"), expectedERight);

            for (int i = 0; i <= 8; i++)
            {
                int[] expectedRLeft  = { 11, 25, 11, 0, 0, 0, 0, 0, 27 };
                int[] expectedRRight = { 29, 56, 34, 43, 0, 18, 0, 6, 0 };

                // Test L-1R
                runLineupTest(results, createTestTeamLineup("L", (i + 1) + "R", (i + 1) + "R"), expectedRLeft[i]);
                runLineupTest(results, createTestTeamLineup("R", (i + 1) + "R", (i + 1) + "R"), expectedRRight[i]);
            }
        }
Exemplo n.º 9
0
 public SyncUsageHelper(IUsageCalculator usageCalculator, IUsageServiceClient client)
 {
     _usageCalculator = usageCalculator;
     _client          = client;
     userId           = System.Guid.NewGuid().ToString();
 }