public void MarkAsComplete(BetOption betOption, Bettor bettor) { if (betOption == null) { throw new ArgumentNullException(nameof(betOption)); } if (betOption.Id == default(int)) { throw new ArgumentException(nameof(betOption)); } if (bettor == null) { throw new ArgumentNullException(nameof(bettor)); } if (bettor.Id == default(int)) { throw new ArgumentException(nameof(bettor)); } if (betOption.Bet.Complete) { throw new Exception("Bet Already Complete"); } _betRepository.MarkComplete(betOption.Bet, bettor); _betRepository.MarkCorrect(betOption); _betRepository.AddPointsToSuccessfulGuess(betOption, 100); }
public void Add(Bet bet, Bettor bettor, Brother brother) { bet.Brother = _context.Brothers.Find(brother.Id); bet.Creator = _context.Bettors.Find(bettor.Id); _context.Bets.Add(bet); _context.SaveChanges(); }
public static Embed MineBets(IEnumerable <Bet> bets, ulong userId) { if (!bets.Any()) { return(BetHelp()); } IEnumerable <EmbedFieldBuilder> fields = bets.Select(bet => { List <string> options = bet.Options.Select(option => { int betted = bet.Bettors .Where(b => b.BetOptionId == option.Id) .Aggregate(0, (total, b) => total + b.Amount); return($"[{option.Id}] ({option.Odds:F}) {option.Name} with the weight of {betted} coins."); }).ToList(); Bettor bettor = bet.Bettors.FirstOrDefault(b => b.UserId == userId); BetOption bettorsOption = bet.Options.FirstOrDefault(o => o.Id == bettor.BetOptionId); options.Add($"\nYou placed {bettor.Amount} Attarcoin on option \"{bettorsOption.Name}\". {(bettor.Released ? "(Released)" : "")}"); return(new EmbedFieldBuilder() .WithIsInline(false) .WithName($"{bet.Name} ({(bet.Resolved ? "Inactive" : "Active")})") .WithValue(options.Count == 0 ? "No options added yet." : string.Join("\n", options))); }); return(new EmbedBuilder() .WithTitle("Your bets") .WithColor(Color.Green) .WithFields(fields) .Build()); }
public void TakeBet(Bettor bettor, BetOption outcome, Brother brother) { if (bettor == null) { throw new ArgumentNullException(nameof(bettor)); } if (bettor.Id == default(int)) { throw new ArgumentException(nameof(bettor)); } if (outcome == null) { throw new ArgumentNullException(nameof(outcome)); } if (outcome.Id == default(int)) { throw new ArgumentException(nameof(outcome)); } if (brother == null) { throw new ArgumentNullException(nameof(brother)); } if (brother.Id == default(int)) { throw new ArgumentException(nameof(brother)); } _betRepository.TakeBet(bettor, outcome, brother); }
public async void Initialize(MainWindow mainWindow, MenuWindowController menuWindow, Season selectedSeason, Bettor bettor) { _view = new MatchesWindow(); _bettorClient = new BettorClientServiceClient(); _mainWindow = mainWindow; _menuWindow = menuWindow; _selectedSeason = selectedSeason; _bettor = bettor; #region View and ViewModel // Check if service is available if (!await BettorClientHelper.IsAvailable(_bettorClient)) { return; } _viewModel = new MatchesWindowViewModel { SelectedSeason = _selectedSeason, Matches = LoadModels(), SelectedMatch = SortedMatches().FirstOrDefault(), SelectedMatchCommand = new RelayCommand(ExecuteSelectedMatchCommand), BackCommand = new RelayCommand(ExecuteBackCommand) }; _view.DataContext = _viewModel; #endregion _mainWindow.Content = _view; }
public void MarkComplete(Bet bet, Bettor bettor) { bet = _context.Bets.Find(bet.Id); bet.Complete = true; bet.MarkedCompleteBy = _context.Bettors.Find(bettor.Id); _context.SaveChanges(); }
public WcfBettor(Bettor bettor) { this.Id = bettor.Id; this.Nickname = bettor.Nickname; this.Firstname = bettor.Firstname; this.Lastname = bettor.Lastname; }
public Bet[] ParseBettorBets(Bettor bettor, string html) { var t = html.GetIdNode("usertable"); var tt = t.QuerySelectorAll("tbody > tr[class*=\"bgr\"]").ToList(); return(tt.Select(ConvertToBettorBets).ToArray()); }
public async Task <Bettor> PlaceBet(ulong userId, int amount, int betOptionId, string betName) { Bet bet = await _repository.GetBetByName(betName); if (bet == null || bet.Resolved || !bet.Options.Any(o => o.Id == betOptionId) || IsPlacingMultipleBetOptions(userId, bet, betOptionId)) { return(null); } Bettor bettor = bet.Bettors.FirstOrDefault(b => b.UserId == userId && b.BetOptionId == betOptionId); if (bettor != null) { bettor.Amount += amount; } else { bettor = new Bettor { UserId = userId, Amount = amount, BetOptionId = betOptionId, Released = false }; bet.Bettors = bet.Bettors.Concat(new[] { bettor }); } await _repository.UpdateBet(bet); await _repository.SaveAsync(); return(bettor); }
public void Initialize(MainWindow mainWindow, Bettor bettor) { _view = new MenuWindow(); _bettorClient = new BettorClientServiceClient(); _mainWindow = mainWindow; _bettor = bettor; // Get all seasons var seasons = _bettorClient.GetSeasons(); #region View and ViewModel _viewModel = new MenuWindowViewModel { Bettor = _bettor, Seasons = new ObservableCollection <Season>(seasons.ToList()), SelectedSeason = _selectedSeason ?? seasons.FirstOrDefault(), BettorRankingCommand = new RelayCommand(ExecuteBettorRankingCommand), MatchesCommand = new RelayCommand(ExecuteMatchesCommand), TeamsCommand = new RelayCommand(ExecuteTeamsCommand), }; _selectedSeason = _selectedSeason != null ? _viewModel.SelectedSeason : seasons.FirstOrDefault(); _view.DataContext = _viewModel; #endregion _mainWindow.Content = _view; _mainWindow.Width = 800; _mainWindow.Height = 600; }
private Bettor ConvertToBettor(HtmlNode node) { var bettor = new Bettor(); var nodes = node.ChildNodes.Where(x => x.Name != "#text").ToList(); var rankStr = nodes[0].InnerText; bettor.Rank = int.Parse(rankStr); var nameNode = nodes[1]; bettor.Name = nameNode.InnerText.SkipLastN(3); var linkParamsStr = nameNode.FirstChild.Attributes.FirstOrDefault(x => x.Name == "onclick").Value; var temp = linkParamsStr.TakeBetween("'", "'),").Split(new char[] { '\'', ',', '\'' }).Where(q => !string.IsNullOrEmpty(q)).ToArray(); bettor.Cid = temp[1]; bettor.Uid = temp[0]; var profitStr = nodes[2].InnerText; var profitValue = profitStr.SkipFirstAndLast(); bettor.Profit = double.Parse(profitValue); var totalBetsStr = nodes[3].InnerText; bettor.TotalBets = int.Parse(totalBetsStr); var stats = nodes[4].InnerText.Split('/').ToList(); var winStr = stats[0]; var lostStr = stats[1]; var drawStr = stats[2]; bettor.Win = int.Parse(winStr); bettor.Lost = int.Parse(lostStr); bettor.Draw = int.Parse(drawStr); var avgKoefStr = nodes[5].InnerText; bettor.AvgKoef = double.Parse(avgKoefStr); var avgTotalBetStr = nodes[6].InnerText; bettor.AvgTotalBet = int.Parse(avgTotalBetStr); var winPercentageStr = nodes[7].InnerText; var sbstr = winPercentageStr.Substring(0, winPercentageStr.Length - 1); bettor.WinPercentage = int.Parse(sbstr); var roiStr = nodes[8].InnerText; bettor.Roi = double.Parse(roiStr.SkipFirstAndLast()); bettor.Created = DateTime.UtcNow; bettor.Updated = DateTime.UtcNow; return(bettor); }
public Bet GetBet(Match match, Bettor bettor) { lock (StaticLock) { var bets = _betPersistenceService.GetAll(); var betsOfMatch = bets.FindAll(x => x.Bettor.Equals(bettor) && x.Match.Equals(match)); return(betsOfMatch.Count != 1 ? null : betsOfMatch.First()); } }
public void PredictBetBernoulliTimes() { var archive = new Archive(); var threeCons = 0; var fourCons = 0; var fiveCons = 0; var sixCons = 0; //var games = 511; //for (var i = 1; i <= games; i++) //{ // var resultArray = simulator.GenerateGameResult(); // archive.AddSequence(resultArray, i); //} var bet = archive.PredictSequence(); for (int i = 1; i < Editions; i++) { var sequence = simulator.GenerateGameResult(); //if (i % 10 == 0) //{ bet = archive.PredictSequenceWithBernoulli(i); //} var result = Bettor.CheckResult(bet, sequence); archive.AddSequence(sequence, i); switch (result) { case 3: threeCons++; break; case 4: fourCons++; break; case 5: fiveCons++; break; case 6: sixCons++; break; default: break; } } var winsCount = threeCons + fourCons + fiveCons + sixCons; Console.WriteLine($"Total plays: {Editions}, total wins: {winsCount}, total loses: {Editions - winsCount}, win times: {Math.Round((double)winsCount / (double)Editions, 8) * 100}%"); Console.WriteLine($"3 wons {threeCons}, times from total wins: {Math.Round((double)threeCons / (double)winsCount, 8) * 100}%, chance to win: {Math.Round((double)threeCons / (double)Editions, 8) * 100}%"); Console.WriteLine($"4 wons {fourCons}, times from total wins: {Math.Round((double)fourCons / (double)winsCount, 8) * 100}%, chance to win: {Math.Round((double)fourCons / (double)Editions, 8) * 100}%"); Console.WriteLine($"5 wons {fiveCons}, times from total wins: {Math.Round((double)fiveCons / (double)winsCount, 8) * 100}%, chance to win: {Math.Round((double)fiveCons / (double)Editions, 8) * 100}%"); Console.WriteLine($"6 wons {sixCons}, times from total wins: {Math.Round((double)sixCons / (double)winsCount, 8) * 100}%, chance to win: { Math.Round((double)sixCons / (double)Editions, 8) * 100}% "); }
public List <Bet> GetBets(Bettor bettor) { lock (StaticLock) { var bets = _betPersistenceService.GetAll(); var findAll = bets.FindAll(x => x.Bettor.Equals(bettor)); return(findAll); } }
public void PredictEightBetsEachTenTimes() { var archive = new Archive(); var betsToPlayOnce = 42; var bets = archive.PredictSequences(betsToPlayOnce); var threeCons = 0; var fourCons = 0; var fiveCons = 0; var sixCons = 0; for (int i = 0; i < Editions; i++) { var sequence = simulator.GenerateGameResult(); //if (i % 1 == 0) //{ bets = archive.PredictSequences(betsToPlayOnce); //} archive.AddSequence(sequence, i); for (int b = 0; b < betsToPlayOnce; b++) { var res = Bettor.CheckResult(bets[b], sequence); switch (res) { case 3: threeCons++; break; case 4: fourCons++; break; case 5: fiveCons++; break; case 6: sixCons++; break; default: break; } } } var winsCount = threeCons + fourCons + fiveCons + sixCons; Console.WriteLine($"Total plays: {Editions}, total wins: {winsCount}, total loses: {Editions - winsCount}, win times: {Math.Round((double)winsCount / (double)Editions, 8) * 100}%"); Console.WriteLine($"3 wons {threeCons}, times from total wins: {Math.Round((double)threeCons / (double)winsCount, 8) * 100}%, chance to win: {Math.Round((double)threeCons / (double)Editions, 8) * 100}%"); Console.WriteLine($"4 wons {fourCons}, times from total wins: {Math.Round((double)fourCons / (double)winsCount, 8) * 100}%, chance to win: {Math.Round((double)fourCons / (double)Editions, 8) * 100}%"); Console.WriteLine($"5 wons {fiveCons}, times from total wins: {Math.Round((double)fiveCons / (double)winsCount, 8) * 100}%, chance to win: {Math.Round((double)fiveCons / (double)Editions, 8) * 100}%"); Console.WriteLine($"6 wons {sixCons}, times from total wins: {Math.Round((double)sixCons / (double)winsCount, 8) * 100}%, chance to win: { Math.Round((double)sixCons / (double)Editions, 8) * 100}% "); }
public void Check_Amount_More_Than_Zero() { // Arrange var guy = new Bettor(); // Act var actual = guy.PlaceTheBet(10, 1); // Assert Assert.IsTrue(!actual); }
public static IEnumerable <Embed> BetPlaced(Bet bet, Bettor bettor, IUser author) { var builder = new EmbedBuilder() .WithAuthor(author) .WithTitle($"Bet placed") .WithDescription($"{MentionUtils.MentionUser(bettor.UserId)} placed new bet on '{bet.Name}' option '{BetOptionNameById(bet, bettor.BetOptionId)}' for {bettor.Amount} Attarcoins.") .AddField("Withdraw or release bet", $"$bet-release \"{bet.Name}\"") .WithColor(Color.Green); return(WithBettors(bet, builder)); }
public void Check_Bet_Placed() { // Arrange var bettor = new Bettor(); // Act var actual = bettor.PlaceABet(50, 1); // Assert Assert.AreEqual(false, actual); }
public void Not_Enough_Cash_Message() { // Arrange var guy = new Bettor(); // Act var actual = guy.Betting(1, 1); // Assert Assert.AreEqual(false, actual); }
public void Error_Message_Due_To_Not_Enough_Cash() { // Arrange var guy = new Bettor(); // Act var actual = guy.PlaceBid(100, 0); // Assert Assert.AreEqual(false, actual); }
public bool DeleteBettor(Bettor bettor) { lock (StaticLock) { var bets = _betPersistenceService.GetAll(); var findAll = bets.FindAll(x => x.Bettor.Equals(bettor)); // if the user has any current bets, all of them will be deleted findAll.ForEach(x => _betPersistenceService.Delete(x)); // finally the user will be deleted return(_bettorPersistenceService.Delete(bettor)); } }
public static void AddBet(Bettor bettor, Match match, int homeTeamScore, int awayTeamScore, DateTime date) { Bet bet = new Bet(); bet.Date = DateTime.Now; bet.HomeTeamScore = homeTeamScore; bet.AwayTeamScore = awayTeamScore; bet.Match = match; bet.Date = date; bet.BettorId = bettor.Id; mBetRepository.Save(bet); }
public static bool DeleteBettor(Bettor bettor) { if (bettor.Bets == null || bettor.Bets.Count() == 0) { mBettorRepository.Delete(bettor); return(true); } else { return(false); } }
public bool UpdateBettor(Bettor bettor) { lock (StaticLock) { var bettors = _bettorPersistenceService.GetAll(); var searchedBettors = bettors.FindAll(x => x.Nickname.ToUpper().Equals(bettor.Nickname.ToUpper()) && x.Id != bettor.Id); if (searchedBettors.Any()) { return(false); } return(_bettorPersistenceService.Update(bettor)); } }
public void AddBet(Bet bet, Bettor bettor, Brother betTarget, string[] predictedOutcomes) { if (bet == null) { throw new ArgumentNullException(nameof(bet)); } if (bet.Id != default(int)) { throw new ArgumentException(nameof(bet)); } if (bettor == null) { throw new ArgumentNullException(nameof(bettor)); } if (bettor.Id == default(int)) { throw new ArgumentException(nameof(bettor)); } if (betTarget == null) { throw new ArgumentNullException(nameof(betTarget)); } if (betTarget.Id == default(int)) { throw new ArgumentException(nameof(betTarget)); } if (predictedOutcomes == null) { throw new ArgumentNullException(nameof(predictedOutcomes)); } if (bet.Expiration < DateTime.Today.AddDays(2)) { throw new Exception( $"Come on, you need to give more time than that! Set the date to at least {DateTime.Today.AddDays(2).ToShortDateString()}"); } var betOutcomes = predictedOutcomes .Where(o => !string.IsNullOrWhiteSpace(o)) .Select(o => new BetOption() { Outcome = o, Bet = bet }); bet.BetOptions = new List <BetOption>(betOutcomes); if (bet.BetOptions.Count < 2) { throw new Exception("Bets must have at least two outcomes"); } _betRepository.Add(bet, bettor, betTarget); }
/* -----------Add Bettor------------*/ public async Task <IActionResult> AddBettor(string bettorName) { if (HttpContext.Session.GetString("isAdmin") != "true") { return(View(nameof(LoginView))); } Bettor bettor = new Bettor { Name = bettorName }; _context.Bettor.Add(bettor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(LaborDayMainView))); }
public void InitTest() { _testBettor = new Bettor { Nickname = "Juergen173", Firstname = "Jürgen", Lastname = "Eisele" }; _testBettor2 = new Bettor { Nickname = "Test " + DateTime.Now, Lastname = "Test", Firstname = "Test" }; }
public static void AddBettor(string firstname, string lastname, string nickname) { if (mBettorRepository.GetByPropertyIgnoreCase("Nickname", nickname).Count == 0) { Bettor newBettor = new Bettor(); newBettor.Firstname = firstname; newBettor.Lastname = lastname; newBettor.Nickname = nickname; mBettorRepository.Save(newBettor); } else { Console.WriteLine("Bettor existiert bereits"); } }
public async void Initialize(MainWindow mainWindow, MenuWindowController menuWindow, Season selectedSeason, Bettor bettor) { _view = new BettorRankingWindow(); _bettorClient = new BettorClientServiceClient(); _mainWindow = mainWindow; _menuWindow = menuWindow; _selectedSeason = selectedSeason; _bettor = bettor; #region View and ViewModel // Check if service is available if (!await BettorClientHelper.IsAvailable(_bettorClient)) { return; } var matches = await _bettorClient.GetMatchesAsync(_selectedSeason); // get rankedbettors var rankedBettors = await _bettorClient.GetAllRankedBettorsAsync(_selectedSeason); // set list for match days var matchDays = new ObservableCollection <string> { "Aktuell" }; if (matches.Any()) { // find max match day var max = matches.Max(x => x.MatchDay); for (var i = 1; i <= max; i++) { matchDays.Add("Spieltag: " + i); } } _viewModel = new BettorRankingWindowViewModel { Bettors = rankedBettors.ToList(), SelectedMatchDay = matchDays.FirstOrDefault(), MatchDays = matchDays, BackCommand = new RelayCommand(ExecuteBackCommand) }; _viewModel.SelectionMatchDayChanged += UpdateMatchDay; // set view of Window _view.DataContext = _viewModel; #endregion _mainWindow.Content = _view; }
public void EightBetsRetryManyTimes() { var betsToPlayOnce = 8; var bets = simulator.GenerateBets(betsToPlayOnce); var threeCons = 0; var fourCons = 0; var fiveCons = 0; var sixCons = 0; for (int i = 0; i < Editions; i++) { var gameRes = simulator.GenerateGameResult(); for (int b = 0; b < betsToPlayOnce; b++) { var res = Bettor.CheckResult(bets[b], gameRes); switch (res) { case 3: threeCons++; break; case 4: fourCons++; break; case 5: fiveCons++; break; case 6: sixCons++; break; default: break; } } } var winsCount = threeCons + fourCons + fiveCons + sixCons; Console.WriteLine($"Total plays: {Editions}, total wins: {winsCount}, total loses: {Editions - winsCount}, win times: {Math.Round((double)winsCount / (double)Editions, 8) * 100}%"); Console.WriteLine($"3 wons {threeCons}, times from total wins: {Math.Round((double)threeCons / (double)winsCount, 8) * 100}%, chance to win: {Math.Round((double)threeCons / (double)Editions, 8) * 100}%"); Console.WriteLine($"4 wons {fourCons}, times from total wins: {Math.Round((double)fourCons / (double)winsCount, 8) * 100}%, chance to win: {Math.Round((double)fourCons / (double)Editions, 8) * 100}%"); Console.WriteLine($"5 wons {fiveCons}, times from total wins: {Math.Round((double)fiveCons / (double)winsCount, 8) * 100}%, chance to win: {Math.Round((double)fiveCons / (double)Editions, 8) * 100}%"); Console.WriteLine($"6 wons {sixCons}, times from total wins: {Math.Round((double)sixCons / (double)winsCount, 8) * 100}%, chance to win: { Math.Round((double)sixCons / (double)Editions, 8) * 100}% "); }