예제 #1
0
        private static void AddLongToteDescription(Models.Tote tote, StringBuilder sb)
        {
            var allBets           = tote.Options.SelectMany(a => a.Bets).ToList();
            var participantsCount = allBets.Select(a => a.User).Distinct().Count();
            var betsCount         = allBets.Count;

            var totalSum = allBets?.Sum(a => a.Amount);
            var total    = decimal.Round(totalSum.GetValueOrDefault(), 2);

            sb
            .AppendLine($"==ТОТАЛИЗАТОР от <@{tote.Owner}>: *{tote.Description}* ==")
            .AppendLine(ToteStatus(tote))
            .Append($"{participantsCount} {ParticipantsDecl(participantsCount)}, ")
            .AppendLine($"{betsCount} {Declination(betsCount, "ставка", "ставки", "ставок")}")
            .AppendLine();

            foreach (var option in tote.Options)
            {
                AddToteOption(option, tote, sb);
            }

            sb
            .AppendLine($"Всего поставлено: {total} {tote.Currency}")
            .AppendLine();
        }
예제 #2
0
        private static StringBuilder GetToteDescriptionMrkdwn(Models.Tote tote, StringBuilder sb)
        {
            AddLongToteDescription(tote, sb);
            if (tote.State == ToteState.Created)
            {
                AppendAddToteOption(sb);
                if (tote.Options.Length > 0)
                {
                    AppendRemoveToteOption(sb);
                }

                AppendCancelTote(sb);
            }

            return(sb);
        }
예제 #3
0
        private static void AddToteOption(ToteOption option, Models.Tote tote,
                                          StringBuilder sb)
        {
            var participantsCount = option.Bets.Select(a => a.User).Distinct().Count();

            sb.Append(
                $"*{option.Name}* ");
            if (participantsCount > 0)
            {
                var sum = option.Bets.Sum(a => a.Amount);
                sum = Decimal.Round(sum, 2);
                sb.Append(
                    $"сделано ставок на {sum} {tote.Currency} от {participantsCount} {ParticipantsDecl(participantsCount)}");
            }

            sb.AppendLine();
        }
예제 #4
0
        private static string ToteStatus(Models.Tote tote)
        {
            switch (tote.State)
            {
            case ToteState.Cancelled:
                return("Отменён");

            case ToteState.Created:
                return("Ещё не запущен");

            case ToteState.Finished:
                return("Завершён");

            case ToteState.Started:
                return("Открыт приём ставок!");

            case ToteState.Closed:
                return("ПРИЁМ СТАВОК ЗАКРЫТ, ждём результатов");
            }

            return("Ошибка, да");
        }
예제 #5
0
        public static List <IBlock> ToteDetails(Models.Tote tote, StringBuilder sb = null)
        {
            sb ??= new StringBuilder();
            var desc   = GetToteDescriptionMrkdwn(tote, sb);
            var blocks = new List <IBlock>();

            blocks.Add(new SectionBlock
            {
                block_id = "tote_head",
                text     = new Text
                {
                    type = TextTypes.Markdown,
                    text = desc.ToString()
                }
            });
            if (tote.State == ToteState.Started)
            {
                blocks.Add(new ActionsBlock
                {
                    block_id = "tote_actions",
                    elements = new IElement[]
                    {
                        new ButtonElement
                        {
                            text = new Text
                            {
                                type = TextTypes.PlainText,
                                text = "Хочу сделать ставку!"
                            },
                            action_id = $"start_bet:{tote.Id}"
                        }
                    }
                });
            }

            return(blocks);
        }
        public FinishedToteRewards CalcRewards(Models.Tote tote, string winningOptionId)
        {
            var bets     = tote.Options.SelectMany(a => a.Bets);
            var totalSum = bets.Sum(a => a.Amount);

            var ownerPercent = totalSum / 20; //5% more fun than 1%
            var winningFund  = totalSum - ownerPercent;

            ToteOption winningOption  = tote.Options.FirstOrDefault(a => a.Id == winningOptionId);
            var        winningBets    = winningOption.Bets;
            var        winningBetsSum = winningBets.Sum(a => a.Amount);

            var ama = winningBets.Select(a => new AccountWithAmount(new Account(a.User, tote.Currency), a.Amount));
            var agg = ama.AggregateOperations();

            // var proportions = agg.Select(a => new AccountWithAmount(a.Account, a.Amount / winningBetsSum));

            AccountWithAmount[] proportionalReward = agg.Select(a =>
                                                                new AccountWithAmount(a.Account, ((a.Amount * winningFund) / winningBetsSum).Trim())).ToArray();

            ownerPercent = AdjustRemainderToOwner(proportionalReward, winningFund, ownerPercent);

            return(new FinishedToteRewards(proportionalReward, winningOption, ownerPercent));
        }
예제 #7
0
 public static StringBuilder WelcomeToTote(Models.Tote tote, in decimal balanceAmount)