public void CalculateAccuracyTest() { var truth = new[] { new[] { 1.0, 1.0 }, new[] { 1.0, 0.0 } }; var predictions = new[] { new[] { 1.0, 1.0 }, new[] { 0.0, 0.0 } }; var results = new[, ] { { 1.0, 0.0 }, { 0.5, 0.5 } }; for (var i = 0; i < truth.Length; i++) { for (var j = 0; j < predictions.Length; j++) { Assert.AreEqual( StatisticsCalculator.CalculateAccuracy(truth[i], predictions[j]), results[i, j]); } } }
public void AngleBetweenWeightVectors2DTest() { var list1 = new[] { new[] { 10.0, 10.0 }, new[] { 10.0, 15.0 }, new[] { 15.0, 10.0 }, new[] { 15.0, 15.0 } }; var list2 = new[] { new[] { 14.92, 14.82 }, new[] { 14.99, 14.82 } }; var results = new[, ] { { 0.003362462, 0.005702722 }, { 0.200758022, 0.203098282 }, { 0.194033098, 0.191692837 }, { 0.003362462, 0.005702722 } }; for (var i = 0; i < results.GetLength(0); i++) { for (var j = 0; j < results.GetLength(1); j++) { Assert.AreEqual( Math.Round(StatisticsCalculator.AngleBetweenVectors(list1[i], list2[j]), 9), results[i, j]); } } }
public void TestSumNoNumbers() { var calculator = new StatisticsCalculator(); var sum = calculator.Sum(); Assert.Equal(0, sum); }
public void AngleBetweenWeightVectors3DTest() { var list1 = new[] { new[] { 10.0, 10.0, 10 }, new[] { 10.0, 15.0, 10 }, new[] { 15.0, 10.0, 10 }, new[] { 15.0, 15.0, 10 } }; var list2 = new[] { new[] { 14.92, 14.82, 10 }, new[] { 14.99, 14.82, 10 } }; var results = new[, ] { { 0.171629101, 0.172589753 }, { 0.189056835, 0.19135961 }, { 0.183431982, 0.181833547 }, { 0.004533724, 0.005707512 } }; for (var i = 0; i < results.GetLength(0); i++) { for (var j = 0; j < results.GetLength(1); j++) { Assert.AreEqual( Math.Round(StatisticsCalculator.AngleBetweenVectors(list1[i], list2[j]), 9), results[i, j]); } } }
public void TestDivisionNoNumbers() { var calculator = new StatisticsCalculator(); var result = calculator.Divide(); Assert.Equal(1, result); }
public Engine() { _timerTracker = new TimerTracker(); _nodeCreationService = new NodeCreationService(_timerTracker); _calculator = new StatisticsCalculator(); _CSVWriteService = new CSVWriteService(); }
public async Task <IActionResult> GetGoalsStatistics() { IActionResult loResult = BadRequest(); var calculator = new StatisticsCalculator(); using (var db = new CouponAdminContext()) { var model = new List <TeamGoalsModel>(); foreach (var league in leagues) { try { var statsTables = db.StatisticsTables.Where(t => t.CompetitionId == league).Select(t => new TeamGoalsModel() { Position = t.Position, TeamName = t.TeamName, TeamID = t.TeamId }) .ToList(); foreach (var team in statsTables) { var teamMatches = await(db.StatisticsMatches .Where(m => m.CompentitionId == league && (m.HomeId == team.TeamID || m.AwayId == team.TeamID) && m.Finished).Select(m => new MatchModel() { AwayID = m.AwayId, AwayGoals = m.AwayPoints, AwayName = m.AwayName, HomeID = m.HomeId, HomeGoals = m.HomePoints, HomeName = m.HomeName })).ToListAsync(); team.TotalGames = teamMatches.Count; if (team.TotalGames == 0) { continue; } team.ZeroToTwoPercentage = calculator.CalculateZeroToTwoGoalsPercentage(teamMatches); team.ThreePlusPercentage = calculator.CalculateThreePlusGoalsPercentage(teamMatches); team.OneToThreeGoals = calculator.CalculateGoalsRange(teamMatches, 1, 3); team.TwoToThreeGoals = calculator.CalculateGoalsRange(teamMatches, 2, 3); team.TwoToFourGoals = calculator.CalculateGoalsRange(teamMatches, 2, 4); team.OneToThreeGoalsPercentage = team.OneToThreeGoals * 100 / team.TotalGames; team.TwoToThreeGoalsPercentage = team.TwoToThreeGoals * 100 / team.TotalGames; team.ZeroThreeToFive = calculator.CalculateZeroAndGoalsRange(teamMatches, team.TeamID, 3, 5); team.ZeroTwoToFive = calculator.CalculateZeroAndGoalsRange(teamMatches, team.TeamID, 2, 5); team.TwoToFourGoalsPercentage = team.TwoToFourGoals * 100 / team.TotalGames; model.Add(team); } } catch (Exception e) { Console.WriteLine(e); throw e; } } return(Ok(model)); } }
public void AttackCurrentMonster() // This is an On Click Event in xaml.cs { if (_gameSession.CurrentWeapon == null) { _gameSession.NullWeaponSelectionNotification(); } //Initiative Calculation (Happens each round) int PlayerInitiative = RandomNumberGenerator.NumberBetween(0, 20) + StatisticsCalculator.AbilityScoreCalculator(_gameSession.CurrentPlayer.Dexterity); int monsterInitiative = RandomNumberGenerator.NumberBetween(0, 20) + StatisticsCalculator.AbilityScoreCalculator(_gameSession.CurrentMonster.Dexterity); //Player's Accuracy Calculations _gameSession.CurrentPlayer.ToHit(RandomNumberGenerator.NumberBetween(0, 20) + StatisticsCalculator.AbilityScoreCalculator(_gameSession.CurrentPlayer.Dexterity), _gameSession.CurrentMonster.ArmorClass); // The Condition where the player can hit monster if (_gameSession.CurrentPlayer.AttackSuccess) { ViewModels.AttackSuccess(); if (_gameSession.CurrentMonster.IsDead) { _gameSession.CurrentPlayer.AddExperience(_gameSession.CurrentMonster.RewardExperiencePoints); _gameSession.CurrentPlayer.ReceiveGold(_gameSession.CurrentMonster.Gold); foreach (GameItem gameItem in _gameSession.CurrentMonster.Inventory) { _gameSession.CurrentPlayer.AddItemToInventory(gameItem); } _gameSession.GetMonsterAtLocation(); return; } else { _gameSession.MonsterAttackSuccess(); } } else { _gameSession.PlayerAttackFailureNotification(_gameSession.CurrentWeapon.Name); _gameSession.CurrentMonster.ToHit(RandomNumberGenerator.NumberBetween(0, 20), _gameSession.CurrentPlayer.ArmorClass); if (_gameSession.CurrentMonster.AttackSuccess) { _gameSession.MonsterAttackSuccess(); } else { _gameSession.MonsterAttackFailureNotification(_gameSession.CurrentMonster.Name); } } }
public async Task <IActionResult> GetStatistics() { IActionResult loResult = BadRequest(); var calculator = new StatisticsCalculator(); using (var db = new CouponAdminContext()) { var model = new List <StatisticsMatchModel>(); foreach (var league in leagues) { var matches = db.StatisticsMatches.Where(l => l.CompentitionId == league); var tables = db.StatisticsTables.Where(l => l.CompetitionId == league); var matchPlayed = await tables.FirstOrDefaultAsync(); var round = await matches.OrderBy(r => r.StartTime).FirstOrDefaultAsync(r => r.Finished == false); if (round != null) { var match = await matches.Where(r => r.EventGroupName == round.EventGroupName).Select(a => new StatisticsMatchModel { HomeName = a.HomeName, AwayName = a.AwayName, HomeGoalsScored = tables.Where(t => t.TeamId == a.HomeId).Sum(b => b.TotalGoalsScored), AwayGoalsScored = tables.Where(t => t.TeamId == a.AwayId).Sum(b => b.TotalGoalsScored), HomeGoalsAgaints = tables.Where(t => t.TeamId == a.HomeId).Sum(b => b.TotalGoalsAgaints), AwayGoalsAgaints = tables.Where(t => t.TeamId == a.AwayId).Sum(b => b.TotalGoalsAgaints), MatchPlayed = matchPlayed.MatchesPlayed, HomeThreePlus = calculator.CalculateThreePlusGoalsPercentage (matches.Where(m => (m.HomeId == a.HomeId || m.AwayId == a.HomeId) && m.Finished).Select(m => new MatchModel() { AwayID = m.AwayId, AwayGoals = m.AwayPoints, AwayName = m.AwayName, HomeID = m.HomeId, HomeGoals = m.HomePoints, HomeName = m.HomeName }).ToList()), AwayThreePlus = calculator.CalculateThreePlusGoalsPercentage (matches.Where(m => (m.HomeId == a.AwayId || m.AwayId == a.AwayId) && m.Finished).Select(m => new MatchModel() { AwayID = m.AwayId, AwayGoals = m.AwayPoints, AwayName = m.AwayName, HomeID = m.HomeId, HomeGoals = m.HomePoints, HomeName = m.HomeName }).ToList()) }).ToListAsync(); model.AddRange(match); } } return(Ok(model)); } }
public void TestDivisionOneNumber() { var calculator = new StatisticsCalculator(); calculator.Add(6); var result = calculator.Divide(); Assert.Equal(6, result); }
public void MeanTest() { StatisticsCalculator statsCal = new StatisticsCalculator(); int[] values = { 1, 2 }; var mean = statsCal.Mean(values); Assert.AreEqual(1.5, mean); }
public void AttackSuccess() { int weaponDamage = RandomNumberGenerator.NumberBetween(_gameSession.CurrentWeapon.MinimumDamage, _gameSession.CurrentWeapon.MaximumDamage); int damageDealtToMonster = weaponDamage + StatisticsCalculator.AbilityScoreCalculator(_gameSession.CurrentPlayer.Strength); _gameSession.PlayerAttackSuccessNotification(_gameSession.CurrentMonster.Name, damageDealtToMonster); _gameSession.CurrentMonster.TakeDamage(damageDealtToMonster); }
public void TestNoInput() { var statisticsCalculator = new StatisticsCalculator(); var actualTxt = statisticsCalculator.GetStatsText(); var n = Environment.NewLine; var expectedTxt = ""; Assert.AreEqual(expectedTxt, actualTxt); }
public async Task <List <TeamStat> > GetTeamStatsResultsAsync() { // Get all the data sources for ranking data var rankingDataSource = await _wpbService.GetRankingDataSources(); var statData = new List <TeamStat>(); foreach (var result in rankingDataSource) { var rankStat = ParseDataSource.ParseRankingSource(result, result.ClassNameNode); foreach (var stat in rankStat) { try { var team = await _wpbService.GetTeamByTeamName(stat.TeamName); if (team != null) { var newStat = new TeamStat() { TeamName = team.TeamName, TeamId = team.Id, TeamCode = team.TeamCode, SubDivisionId = team.SubDivisionId, Position = stat.Position, GamesPlayed = stat.GamesPlayed, GamesWon = stat.GamesWon, GamesLost = stat.GamesLost, BasketsFor = stat.BasketsFor, BasketsAganist = stat.BasketsAganist, PointsDifference = stat.PointsDifference, Points = stat.Points, WinPercentage = StatisticsCalculator.WinPercentage(stat.GamesWon, stat.GamesPlayed).ToString(), LossPercentage = StatisticsCalculator.LossPercentage(stat.GamesLost, stat.GamesPlayed).ToString(), BasketsPerGame = StatisticsCalculator.BasketsPerGame(stat.BasketsFor, stat.GamesPlayed).ToString(), WinLossPercent = StatisticsCalculator.WinLossPercentage(stat.GamesWon, stat.GamesLost).ToString(), WinsOver500 = StatisticsCalculator.WinsOver50(stat.GamesWon, stat.GamesLost).ToString(), WPyth = StatisticsCalculator.WPyth(stat.BasketsFor, stat.BasketsAganist).ToString(), }; statData.Add(newStat); } else { throw new System.ArgumentException( "Detected null values in either team variable!"); } } catch (Exception err) { var msg = err.ToString(); } } } return(statData); }
public void OneBacklogItem_OneDay() { var scheduleData = new[] { new ScheduleData(1, Create.WorkItem.ForBacklogItem("US1").WorkOnComponent("A")) }; var statistics = new StatisticsCalculator().Calculate(scheduleData); Assert.That(statistics, Is.EqualTo(new Statistics(1, 1))); }
public SummaryPage() { InitializeComponent(); //Show statistics in Datagrids and TextBlock statisticsCalculator = new StatisticsCalculator(); dgCandidatesResults.ItemsSource = statisticsCalculator.namesCounts; dgPartiesResults.ItemsSource = statisticsCalculator.partiesCounts; tbNullResults.Text = "Null votes count: " + statisticsCalculator.NullVotes; }
public void BestBuyerByNetIncomeTest() { var target = new StatisticsCalculator(_exampleData.Clients, _exampleData.Products, _exampleData.Invoices); Client expected = null; // TODO: Initialize to an appropriate value Client actual; actual = target.BestBuyerByNetIncome(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void ClientsWithNoInvoicesTest() { var target = new StatisticsCalculator(_exampleData.Clients, _exampleData.Products, _exampleData.Invoices); IEnumerable <Client> expected = null; // TODO: Initialize to an appropriate value IEnumerable <Client> actual; actual = target.ClientsWithNoInvoices(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void TotalTaxesTest() { var target = new StatisticsCalculator(_exampleData.Clients, _exampleData.Products, _exampleData.Invoices); Decimal expected = new Decimal(); // TODO: Initialize to an appropriate value Decimal actual; actual = target.TotalTaxes(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void TestSumTwoNumbers() { var calculator = new StatisticsCalculator(); calculator.Add(5); calculator.Add(7); var sum = calculator.Sum(); Assert.Equal(12, sum); }
public void TestDivisionByZero() { var calculator = new StatisticsCalculator(); calculator.Add(10); calculator.Add(0); var result = calculator.Divide(); Assert.Equal(1, result); }
public void Test1() { var statisticsCalculator = new StatisticsCalculator(); statisticsCalculator.Count("aabc"); var actualTxt = statisticsCalculator.GetStatsText(); var n = Environment.NewLine; var expectedTxt = $"a - 2{n}b - 1{n}c - 1{n}"; Assert.AreEqual(expectedTxt, actualTxt); }
public void SalesByDateTest() { var target = new StatisticsCalculator(_exampleData.Clients, _exampleData.Products, _exampleData.Invoices); DateTime date = new DateTime(); // TODO: Initialize to an appropriate value IEnumerable <SalesByDateSummary> expected = null; // TODO: Initialize to an appropriate value IEnumerable <SalesByDateSummary> actual; actual = target.SalesByDate(date); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void TestDivisionMultipleNumbers() { var calculator = new StatisticsCalculator(); calculator.Add(10); calculator.Add(5); calculator.Add(2); var result = calculator.Divide(); Assert.Equal(1, result); }
public void IdleWorkInTheMiddle() { var scheduleData = new[] { new ScheduleData(1, Create.WorkItem.ForBacklogItem("US1").WorkOnComponent("A")), new ScheduleData(2, Create.WorkItem.ForBacklogItem("US1").NoWork()), new ScheduleData(3, Create.WorkItem.ForBacklogItem("US1").WorkOnComponent("B")) }; var statistics = new StatisticsCalculator().Calculate(scheduleData); Assert.That(statistics, Is.EqualTo(new Statistics(1 / 3m, 3))); }
public void BestBuyerByTotalTest() { IEnumerable <Client> clients = null; // TODO: Initialize to an appropriate value IEnumerable <Product> products = null; // TODO: Initialize to an appropriate value IEnumerable <Invoice> invonces = null; // TODO: Initialize to an appropriate value StatisticsCalculator target = new StatisticsCalculator(clients, products, invonces); // TODO: Initialize to an appropriate value Client expected = null; // TODO: Initialize to an appropriate value Client actual; actual = target.BestBuyerByTotal(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void TwoBacklogItems_TwoDaysEach() { var scheduleData = new[] { new ScheduleData(1, Create.WorkItem.ForBacklogItem("US1").WorkOnComponent("A")), new ScheduleData(2, Create.WorkItem.ForBacklogItem("US1").WorkOnComponent("A")), new ScheduleData(1, Create.WorkItem.ForBacklogItem("US2").WorkOnComponent("B")), new ScheduleData(2, Create.WorkItem.ForBacklogItem("US2").WorkOnComponent("B")) }; var statistics = new StatisticsCalculator().Calculate(scheduleData); Assert.That(statistics, Is.EqualTo(new Statistics(1, 2))); }
public void SalesInTest() { IEnumerable <Client> clients = null; // TODO: Initialize to an appropriate value IEnumerable <Product> products = null; // TODO: Initialize to an appropriate value IEnumerable <Invoice> invonces = null; // TODO: Initialize to an appropriate value StatisticsCalculator target = new StatisticsCalculator(clients, products, invonces); // TODO: Initialize to an appropriate value DateTime date = new DateTime(); // TODO: Initialize to an appropriate value SalesByDateSummary expected = null; // TODO: Initialize to an appropriate value SalesByDateSummary actual; actual = target.SalesIn(date); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void SalesByClientTest() { var target = new StatisticsCalculator(_exampleData.Clients, _exampleData.Products, _exampleData.Invoices); var from = DateTime.Parse("2011-12-05"); var to = DateTime.Parse("2011-12-08"); var client = _exampleData.IcazaClient; var expectedClient = _exampleData.IcazaClient; var expectedInvoiceNumbers = new[] { 7, 8, 10, 15 }; var actual = target.SalesByClient(client, from, to); Assert.AreEqual(expectedClient, actual.Client); Assert.IsTrue(actual.InvoiceNumbers.SequenceEqual(expectedInvoiceNumbers)); Assert.Inconclusive("test actual.Items"); }
public async Task <IActionResult> GetDoubleChanceStatistics() { IActionResult loResult = BadRequest(); var calculator = new StatisticsCalculator(); using (var db = new CouponAdminContext()) { var model = new List <DoubleChanceModel>(); foreach (var league in leagues) { var statsTables = db.StatisticsTables.Where(t => t.CompetitionId == league).Select(t => new DoubleChanceModel() { Position = t.Position, TeamName = t.TeamName, TeamID = t.TeamId }).ToList(); foreach (var team in statsTables) { var teamMatches = await(db.StatisticsMatches .Where(m => m.CompentitionId == league && (m.HomeId == team.TeamID || m.AwayId == team.TeamID) && m.Finished).Select(m => new MatchModel() { AwayID = m.AwayId, AwayGoals = m.AwayPoints, AwayName = m.AwayName, HomeID = m.HomeId, HomeGoals = m.HomePoints, HomeName = m.HomeName })).ToListAsync(); team.TotalGames = teamMatches.Count; team.ZeroTwoToThreeGoals = calculator.CalculateZeroAndGoalsRange(teamMatches, team.TeamID, 2, 3); team.ZeroTwoToFourGoals = calculator.CalculateZeroAndGoalsRange(teamMatches, team.TeamID, 2, 4); team.TwoTwoToFourGoals = calculator.CalculateTwoAndGoalsRange(teamMatches, team.TeamID, 2, 4); team.TwoTwoToThreeGoals = calculator.CalculateTwoAndGoalsRange(teamMatches, team.TeamID, 2, 3); team.NotTwoAndThreeGoals = calculator.CalculateNotTwoAndGoalsRange(teamMatches, team.TeamID, 3); team.NotTwoAndTwoGoals = calculator.CalculateNotTwoAndGoalsRange(teamMatches, team.TeamID, 2); team.GGThreePlusPercentage = calculator.CalculateGGThreePlusPercentage(teamMatches); team.GGorThreePlusPercentage = calculator.CalculateGGorThreePlusPercentage(teamMatches); model.Add(team); } } return(Ok(model)); } }