/// <summary> /// The run method with each time and get the best numbers. /// </summary> /// <param name="action"> /// The action. /// </param> /// <param name="count"> /// The count. /// </param> /// <param name="typesOfDrawn"> /// The t drawn. /// </param> public void RunMethodWithEachTimeAndGetTheBestNumbers(MethodInfo action, int count, Enums.TypesOfDrawn typesOfDrawn) { if (LotteryModels == null) { LotteryModels = new List <LotteryModel>(); } Dictionary <int, int> numbersDictionary = new Dictionary <int, int>(); Console.WriteLine($"{typesOfDrawn} {count} Times"); int index = 0; int errorCounter = 0; int skipRutinWhenReachThisNumber = 200; while (index != count) { LotteryModel returnedModel = (LotteryModel)action.Invoke(this, null); if (skipRutinWhenReachThisNumber == errorCounter) { Console.WriteLine("You cant genreate numbers with this method, because numbers dosent right for it"); break; } if (returnedModel == null || !returnedModel.ValidationTuple().Item1) { errorCounter++; continue; } index++; foreach (var returnedModelNumber in returnedModel.Numbers) { if (numbersDictionary.Count > 0 && numbersDictionary.ContainsKey(returnedModelNumber)) { numbersDictionary[returnedModelNumber]++; } else { numbersDictionary.Add(returnedModelNumber, 1); } } } var sortedDic = numbersDictionary.OrderByDescending(x => x.Value).Take(lotteryRule.PiecesOfDrawNumber); LotteryModel resultLotteryModel = new LotteryModel(lotteryRule); foreach (KeyValuePair <int, int> keyValuePair in sortedDic) { resultLotteryModel.Numbers.Add(keyValuePair.Key); } if (LotteryModels.AddValueWithDetailsAndValidation(resultLotteryModel.ValidationTuple(), typesOfDrawn)) { OnLotteryModelEvent(resultLotteryModel); } }
public void RunMethodWithEachTimeAndGetTheMostCommonSeries(MethodInfo action, int count, Enums.TypesOfDrawn typesOfDrawn) { if (LotteryModels == null) { LotteryModels = new List <LotteryModel>(); } Dictionary <string, int> numbersDictionary = new Dictionary <string, int>(); Console.WriteLine($"{typesOfDrawn} {count} Times"); int index = 0; while (index != count) { LotteryModel returnedModel = (LotteryModel)action.Invoke(this, null); if (returnedModel == null || !returnedModel.ValidationTuple().Item1) { continue; } index++; if (numbersDictionary.Count > 0 && numbersDictionary.ContainsKey(returnedModel.ToString())) { numbersDictionary[returnedModel.ToString()]++; } else { numbersDictionary.Add(returnedModel.ToString(), 1); } } KeyValuePair <string, int> sortedDic = numbersDictionary.OrderByDescending(x => x.Value).ToList()[0]; LotteryModel resultLotteryModel = new LotteryModel(lotteryRule); var numbers = sortedDic.Key.Split(", "); foreach (string number in numbers) { resultLotteryModel.Numbers.Add(Convert.ToInt32(number)); } if (LotteryModels.AddValueWithDetailsAndValidation(resultLotteryModel.ValidationTuple(), typesOfDrawn, Enums.GenerateType.MostCommonSeries)) { OnLotteryModelEvent(resultLotteryModel); } }
/// <summary> /// The use earlier week percentage for numbers draw. /// </summary> /// <param name="typesOfDrawn"> /// The t drawn. /// </param> public void UseEarlierWeekPercentageForNumbersDraw(Enums.TypesOfDrawn typesOfDrawn) { List <SaveNumber> getLotteryDrawing = this.SaveNumbers.Where(x => x.WeekOfPull == this.lotteryCollection.Last().WeekOfLotteryDrawing).ToList(); //if (getLotteryDrawing.Count == 0) //{ // throw new InvalidOperationException("You haven't earlier week result"); //} if (LotteryModels == null) { throw new InvalidOperationException("You didn't generate numbers from which I can calculate"); } Console.WriteLine("Calculated From earlier week"); var lmt = LotteryModels.Clone(); foreach (LotteryModel lotteryModel in lmt) { foreach (SaveNumber saveNumber in getLotteryDrawing) { LotteryModel lm = new LotteryModel(lotteryRule); if (saveNumber.Message != lotteryModel.Message) { continue; } for (int i = 0; i < lotteryRule.PiecesOfDrawNumber; i++) { double calculatedNumber = lotteryModel.Numbers[i] * saveNumber.DifferentInPercentage[i]; lm.Numbers.Add((int)calculatedNumber); } LotteryModels.AddValueWithDetailsAndValidation(lm.ValidationTuple(), typesOfDrawn); } } }