/// <summary> /// The run method with each time. /// </summary> /// <param name="invoke"> /// The invoke. /// </param> /// <param name="count"> /// The count. /// </param> /// <param name="typesOfDrawn"> /// The t drawn. /// </param> private void RunMethodWithEachTime(MethodInfo invoke, int count, Enums.TypesOfDrawn typesOfDrawn) { if (LotteryModels == null) { LotteryModels = new List <LotteryModel>(); } Console.WriteLine(typesOfDrawn.ToString()); int index = 0; while (true) { var returnedModel = (LotteryModel)invoke.Invoke(this, null); if (returnedModel == null) { continue; } if (LotteryModels.AddValueWithDetailsAndValidation(returnedModel.ValidationTuple(), typesOfDrawn)) { index++; OnLotteryModelEvent(returnedModel); } else { continue; } if (index == count) { break; } } }
/// <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); } }
/// <summary> /// The calc the five most common numbers. /// </summary> /// <returns> /// The <see cref="LotteryModel"/>. /// </returns> public LotteryModel CalcTheFiveMostCommonNumbers() { return(new LotteryModel(lotteryRule) { Numbers = LotteryModels.SelectMany(x => x.Numbers).ToList().GroupBy(n => n) .Select(n => new { MetricName = n.Key, MetricCount = n.Count() }).OrderByDescending(n => n.MetricCount).Take(lotteryRule.PiecesOfDrawNumber) .Select(x => x.MetricName).ToList() }); }
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 run method with each time. /// </summary> /// <param name="invoke"> /// The invoke. /// </param> /// <param name="count"> /// The count. /// </param> /// <param name="typesOfDrawn"> /// The t drawn. /// </param> private void RunMethodWithEachTime(MethodInfo invoke, int count, Enums.TypesOfDrawn typesOfDrawn) { if (LotteryModels == null) { LotteryModels = new List <LotteryModel>(); } Console.WriteLine(typesOfDrawn.ToString()); int index = 0; int errorCounter = 0; int skipRutinWhenReachThisNumber = 200; while (true) { var returnedModel = (LotteryModel)invoke.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) { errorCounter++; continue; } if (LotteryModels.AddValueWithDetailsAndValidation(returnedModel.ValidationTuple(), typesOfDrawn)) { index++; OnLotteryModelEvent(returnedModel); } else { continue; } if (index == count) { break; } } }
/// <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); } } }
private void LotteryHandler_OnLotteryModelEvent(object sender, LotteryModel e) { LotteryModels.Add(e); }