Exemplo n.º 1
0
        public async Task <Dictionary <int, Dictionary <Month, decimal> > > GetCalculatedBankValuesByBetAsync(
            CalculateBankValuesOptions options,
            DateTimeOffset?lowerBound = null, DateTimeOffset?upperBound = null)
        {
            return(await Task.Run(() =>
            {
                var result = new Dictionary <int, Dictionary <Month, decimal> >();

                List <ForecastJson> forecasts = _dataService.GetResults(new FilterParameters
                {
                    LowerBound = lowerBound,
                    UpperBound = upperBound
                }, false);

                foreach (var group in forecasts.GroupBy(x => x.GameAt.Year))
                {
                    Dictionary <Month, decimal> bankValues = CalculateBankValues(group.ToList(), options)
                                                             .ToDictionary(x => x.Key, y => y.Value.Bank);

                    result[group.Key] = bankValues;
                }

                return result;
            }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CalculateBankValueAsync(SettingsViewModel model)
        {
            CalculateBankValuesOptions options = _mapper.Map <SettingsViewModel, CalculateBankValuesOptions>(model);

            decimal bankValue = await _algorithmService.GetBankValueByBetAndMethodAsync(options,
                                                                                        model.CalculationMethod, model.LowerBound, model.UpperBound);

            return(Json(bankValue));
        }
Exemplo n.º 3
0
        public async Task <decimal> GetBankValueByBetAndMethodAsync(CalculateBankValuesOptions options, CalculationMethod calculationMethod,
                                                                    DateTimeOffset?lowerBound = null, DateTimeOffset?upperBound = null)
        {
            return(await Task.Run(() =>
            {
                List <ForecastJson> forecasts = _dataService.GetResults(new FilterParameters
                {
                    LowerBound = lowerBound,
                    UpperBound = upperBound
                }, false);

                return GetBankValueByMethod(forecasts, options, calculationMethod, out long?_);
            }));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetBankValuesByYearsAsync(decimal bet, double coefficientBankReserve,
                                                                    int threadNumbers, DateTimeOffset?lowerBound, DateTimeOffset?upperBound)
        {
            var options = new CalculateBankValuesOptions
            {
                ThreadNumbers          = threadNumbers,
                CoefficientBankReserve = coefficientBankReserve,
                Bet = bet
            };

            Dictionary <int, Dictionary <Month, decimal> > model =
                await _algorithmService.GetCalculatedBankValuesByBetAsync(options, lowerBound, upperBound);

            return(PartialView("_BankValuesByYearsPartial", model));
        }
Exemplo n.º 5
0
        private decimal GetBankValueByMethod(List <ForecastJson> forecasts,
                                             CalculateBankValuesOptions options, CalculationMethod calculationMethod, out long?forecastId)
        {
            Dictionary <Month, CalculateBankValueResult> bankValues = CalculateBankValues(forecasts, options);

            decimal bank;

            switch (calculationMethod)
            {
            case CalculationMethod.Average:
                bank       = bankValues.Average(x => x.Value.Bank);
                forecastId = null;
                break;

            case CalculationMethod.Min:
                bank = bankValues.Min(x => x.Value.Bank);
                break;

            case CalculationMethod.SecondMax:
                decimal?bankResult = bankValues.OrderByDescending(x => x.Value.Bank)
                                     .FirstOrDefault(x => x.Value.Bank < bankValues.Max(y => y.Value.Bank)).Value?.Bank;

                bank = bankResult ?? bankValues.FirstOrDefault().Value?.Bank ?? 0;
                break;

            default:
                bank = bankValues.Max(x => x.Value.Bank);
                break;
            }

            if (calculationMethod == CalculationMethod.Average)
            {
                forecastId = null;
            }
            else
            {
                forecastId = bankValues.FirstOrDefault(x => x.Value.Bank == bank).Value?.ForecastId;
            }

            return(Math.Ceiling(bank));
        }
Exemplo n.º 6
0
        private decimal CalculateBetValue(CalculateBetValueOptions options)
        {
            List <ForecastJson> forecasts = _dataService.GetResults(new FilterParameters
            {
                LowerBound = options.LowerBound,
                UpperBound = options.UpperBound
            }, false);

            if (forecasts == null || !forecasts.Any())
            {
                return(options.InitialBet);
            }

            var bankOptions = new CalculateBankValuesOptions
            {
                ThreadNumbers          = options.ThreadNumbers,
                Bet                    = options.InitialBet + options.IncreaseBetStep,
                CoefficientBankReserve = options.CoefficientBankReserve
            };

            decimal bank = GetBankValueByMethod(forecasts, bankOptions,
                                                options.CalculationMethod, out long?forecastId);

            if (bank > options.Bank)
            {
                return(options.InitialBet);
            }

            forecasts = GetForecastsLoseSeries(forecasts, forecastId, bankOptions.ThreadNumbers);

            do
            {
                options.InitialBet += options.IncreaseBetStep;

                bankOptions.Bet += options.IncreaseBetStep;
                bank             = CalculateBankValue(forecasts, bankOptions.Bet, bankOptions.CoefficientBankReserve,
                                                      bankOptions.ThreadNumbers).Bank;
            } while (bank <= options.Bank);

            return(options.InitialBet);
        }
Exemplo n.º 7
0
        private Dictionary <Month, CalculateBankValueResult> CalculateBankValues(List <ForecastJson> forecasts, CalculateBankValuesOptions options)
        {
            var results = new Dictionary <Month, CalculateBankValueResult>();

            CalculateBankValueResult result = CalculateBankValue(forecasts, options.Bet, options.CoefficientBankReserve, options.ThreadNumbers);

            results[Month.All] = result;

            foreach (var group in forecasts.GroupBy(x => x.GameAt.Month))
            {
                result = CalculateBankValue(group.ToList(), options.Bet, options.CoefficientBankReserve, options.ThreadNumbers);

                results[(Month)group.Key] = result;
            }

            return(results);
        }