public static string UserActivityReportsScenario(SetupAll setup, int minUserReports, int maxUserReports, DateTime minDate, DateTime maxDate)
        {
            var timestampRnd   = new RndBuilder <DateTime>(new DateTimeRnd()).Min(minDate).Max(maxDate).Build();
            var countRnd       = new RndBuilder <int>().Min(minUserReports).Max(maxUserReports).Build();
            var granularityRnd = new RndBuilder <ReportGranularity>(new EnumRnd <ReportGranularity>()).Build();

            var actions = new List <UserActivityReportScenarioElement>();
            var no      = 0;

            foreach (var user in setup.UsersSetup.Users)
            {
                var reportsCount = countRnd.Next();
                for (int i = 0; i < reportsCount; i++)
                {
                    var firstDate   = timestampRnd.Next();
                    var secondDate  = timestampRnd.Next();
                    var granularity = (int)granularityRnd.Next();

                    var to   = firstDate > secondDate ? firstDate : secondDate;
                    var from = secondDate > firstDate ? firstDate : secondDate;

                    actions.Add(new UserActivityReportScenarioElement {
                        No = (no++).ToString(), UserId = user.Id, Granularity = granularity, TimestampFrom = from, TimestampTo = to
                    });
                }
            }

            var shuffled = actions.OrderBy(elem => Guid.NewGuid()).Select(a => JsonConvert.SerializeObject(a));

            return(string.Join("|", shuffled));
        }
コード例 #2
0
        static CardDTO[] Cards(AccountDTO[] accounts)
        {
            var countRnd = new RndBuilder <int>()
                           .DistributionValues(new[] { 0, 1, 2 })
                           .DistributionProbabilities(new[] { 50, 40, 10 })
                           .Build();

            return(ValuesGenerator.CreateCards(accounts, countRnd).ToArray());
        }
        public static SetupAll Generate(int usersCount, DateTime minDate, DateTime maxDate)
        {
            var users = ValuesGenerator.CreateUsers(usersCount).ToArray();

            foreach (var user in users)
            {
                user.Business = true;
            }

            var accounts     = Accounts(users);
            var recipientRnd = new RndBuilder <string>().DistributionValues(accounts.Select(a => a.Id)).Build();
            var timestampRnd = new RndBuilder <DateTime>().Min(minDate).Max(maxDate).Build();

            var cards            = Cards(accounts);
            var activePayments   = ActivePayments(accounts, recipientRnd, timestampRnd);
            var loansAndPayments = ActiveLoans(accounts, recipientRnd);

            var accountsTransactions = AccountsTransactions(accounts, recipientRnd, timestampRnd);
            var loansTransactions    = LoansTransactions(loansAndPayments.Select(lp => lp.loan).ToArray(), loansAndPayments.Select(lp => lp.payment).ToArray());
            var cardsTransactions    = CardsTransactions(cards, recipientRnd, timestampRnd);
            var paymentsTransactions = PaymentsTransactions(activePayments);

            var allTransactions = accountsTransactions
                                  .Concat(loansTransactions)
                                  .Concat(cardsTransactions)
                                  .Concat(paymentsTransactions)
                                  .ToArray();

            var setupall = new SetupAll
            {
                AccountsSetup = new AccountsSetup {
                    Accounts = accounts
                },
                CardsSetup = new CardsSetup {
                    Cards = cards
                },
                LoansSetup = new LoansSetup {
                    Loans = loansAndPayments.Select(x => x.loan).ToArray()
                },
                PaymentsSetup = new PaymentsSetup {
                    Payments = loansAndPayments.Select(x => x.payment).Concat(activePayments).ToArray()
                },
                UsersSetup = new UsersSetup {
                    Users = users
                },
                TransactionsSetup = new TransactionsSetup {
                    Transactions = allTransactions
                },
            };

            return(setupall);
        }
コード例 #4
0
        static AccountDTO[] Accounts(UserDTO[] users)
        {
            var countRnd = new RndBuilder <int>()
                           .DistributionValues(new[] { 1, 2, 3, 4 })
                           .DistributionProbabilities(new[] { 45, 30, 15, 10 })
                           .Build();

            var amountRnd = new RndBuilder <float>(new CurrencyRnd())
                            .Min(500)
                            .Max(50000)
                            .DistributionValues(new float[] { 3000, 5000, 10000, 15000, 20000, 35000 })
                            .DistributionProbabilities(new int[] { 20, 25, 20, 15, 10, 5, 5 })
                            .Build();

            return(ValuesGenerator.CreateAccounts(users, countRnd, amountRnd).ToArray());
        }
        public static string[] IndividualUserScenario(SetupAll setup, int clients, int actionsPerGroup, int requesters)
        {
            var users = setup.UsersSetup.Users.Where(u => !u.Business)
                        .Select((u, i) => new { index = i, user = u })
                        .ToArray();
            var usersDict     = users.ToDictionary(k => k.user.Id, v => v.user);
            var groups        = users.GroupBy(u => u.index % clients);
            var cardsAccounts = setup.CardsSetup.Cards.GroupBy(c => c.AccountId).ToDictionary(k => k.Key, v => v.First());
            var accounts      = setup.AccountsSetup.Accounts.Where(a => cardsAccounts.ContainsKey(a.Id))
                                .GroupBy(a => a.UserId)
                                .ToDictionary(k => k.Key, v => v.ToArray());

            var amountRnd = new RndBuilder <float>(new CurrencyRnd()).Min(5).Max(5000)
                            .DistributionValues(new float[] { 20, 100, 300, 500, 1000, 2000, 3000 })
                            .DistributionProbabilities(new[] { 35, 30, 20, 5, 5, 2, 1, 1 })
                            .Build(); //dystrybuanta - max bardzo rzadko, min bardzo często

            var actions = new List <IndividualUserScenarioElement>(actionsPerGroup * clients);
            var no      = 0;

            foreach (var group in groups)
            {
                var groupAccounts = group.Where(g => accounts.ContainsKey(g.user.Id)).SelectMany(g => accounts[g.user.Id]).ToArray();
                var usersAccounts = groupAccounts.GroupBy(a => a.UserId).ToDictionary(k => k.Key, v => v.ToArray());

                for (int i = 0; i < actionsPerGroup; i++)
                {
                    var amount    = (float)Math.Round(amountRnd.Next(), 2);
                    var sender    = GetSender(amount, usersAccounts);
                    var accountId = usersAccounts[sender.UserId].OrderBy(a => Guid.NewGuid()).First().Id;
                    var card      = cardsAccounts[sender.Id];
                    var user      = usersDict[sender.UserId].Login;
                    var recipient = groupAccounts.ElementAt(rand.Next(0, groupAccounts.Length));
                    actions.Add(new IndividualUserScenarioElement {
                        No = (no++).ToString(), Group = group.Key, User = user, Amount = amount, CardId = card.Id, Recipient = recipient.Id, AccountId = accountId
                    });

                    sender.Balance    -= amount;
                    recipient.Balance += amount;
                }
            }

            return(actions.GroupBy(a => a.Group % requesters).Select(g => JsonConvert.SerializeObject(g)).ToArray());
        }
コード例 #6
0
        static PaymentDTO[] ActivePayments(AccountDTO[] accounts, IRnd <string> recipientRnd, IRnd <DateTime> timestampRnd)
        {
            var titleRnd = (TitleRnd) new RndBuilder <string>(new TitleRnd()).Build();
            var countRnd = new RndBuilder <int>()
                           .DistributionValues(new[] { 0, 1, 2 })
                           .DistributionProbabilities(new[] { 50, 40, 10 })
                           .Build();

            var amountRnd = new RndBuilder <float>(new CurrencyRnd()).Min(20).Max(20000)
                            .DistributionValues(new float[] { 500, 1000, 3000, 8000, 15000 })
                            .DistributionProbabilities(new[] { 30, 20, 30, 10, 7, 3 })
                            .Build(); //dystrybuanta
            var startDateRnd = timestampRnd;

            var intervalRnd = new RndBuilder <TimeSpan>()
                              .DistributionValues(new[] { TimeSpan.FromDays(30), TimeSpan.FromDays(90), TimeSpan.FromDays(180), TimeSpan.FromDays(365), })
                              .DistributionProbabilities(new[] { 75, 10, 10, 5 })
                              .Build();

            return(ValuesGenerator.CreatePayments(accounts, PaymentStatus.ACTIVE, recipientRnd, countRnd, amountRnd, startDateRnd, () => DateTime.UtcNow, intervalRnd, titleRnd).ToArray());
        }
        public static string OverallReportScenario(int min, int max, DateTime minDate, DateTime maxDate, TimeSpan maxRange)
        {
            var firstDateRnd         = new RndBuilder <DateTime>(new DateTimeRnd()).Min(minDate).Max(maxDate - maxRange).Build();
            var secondDateRnd        = new DateTimeRnd();
            var countRnd             = new RndBuilder <int>().Min(min).Max(max).Build();
            var granularityRnd       = new RndBuilder <ReportGranularity>(new EnumRnd <ReportGranularity>()).Build();
            var subjectRnd           = new RndBuilder <ReportSubject>(new EnumRnd <ReportSubject>()).Build();
            var aggregationsCountRnd = new RndBuilder <int>().Min(1).Max(6).Build();

            var reportsCount = countRnd.Next();
            var actions      = new List <OverallReportScenarioElement>();
            var no           = 0;

            for (int i = 0; i < reportsCount; i++)
            {
                var firstDate = firstDateRnd.Next();
                secondDateRnd.Min = firstDate;
                secondDateRnd.Max = firstDate + maxRange;
                var secondDate        = secondDateRnd.Next();
                var granularity       = (int)granularityRnd.Next();
                var subject           = (int)subjectRnd.Next();
                var aggregationsCount = aggregationsCountRnd.Next();
                var aggregations      = GetAggregations(aggregationsCount);

                var to   = firstDate > secondDate ? firstDate : secondDate;
                var from = secondDate > firstDate ? firstDate : secondDate;

                actions.Add(new OverallReportScenarioElement {
                    No = (no++).ToString(), Aggregations = aggregations, Subject = subject, Granularity = granularity, TimestampFrom = from, TimestampTo = to
                });
            }

            var shuffled = actions.OrderBy(elem => Guid.NewGuid()).Select(a => JsonConvert.SerializeObject(a));

            return(string.Join("|", shuffled));
        }
        public static string[] BusinessUserScenario(SetupAll setup, int clients, int actionsPerGroup, int minTransactions, int maxTransacitons, int requesters)
        {
            var users = setup.UsersSetup.Users.Where(u => u.Business)
                        .Select((u, i) => new { index = i, user = u })
                        .ToArray();
            var usersDict = users.ToDictionary(k => k.user.Id, v => v.user);
            var groups    = users.GroupBy(u => u.index % clients);
            var accounts  = setup.AccountsSetup.Accounts
                            .GroupBy(a => a.UserId)
                            .ToDictionary(k => k.Key, v => v.ToArray());

            var minAmount = 50;
            var amountRnd = new RndBuilder <float>(new CurrencyRnd()).Min(minAmount).Max(10000)
                            .DistributionValues(new float[] { 300, 500, 1500, 2500, 5000, 8000 })
                            .DistributionProbabilities(new[] { 2, 15, 20, 30, 25, 5, 3 })
                            .Build();
            var titelRnd             = new TitleRnd();
            var transactionsCountRnd = new RndBuilder <int>().Min(minTransactions).Max(maxTransacitons).Build();

            var allActions = new List <BusinessUserScenarioElement>();
            var no         = 0;

            foreach (var group in groups)
            {
                var groupCount    = group.Count();
                var groupAccounts = group.Where(g => accounts.ContainsKey(g.user.Id)).SelectMany(g => accounts[g.user.Id]).ToArray();
                var usersAccounts = groupAccounts.GroupBy(a => a.UserId).ToDictionary(k => k.Key, v => v.ToArray());

                for (int actions = 0; actions < actionsPerGroup; actions++)
                {
                    var user              = group.ElementAt(rand.Next(0, groupCount)).user;
                    var userAccounts      = usersAccounts[user.Id];
                    var transactionsCount = transactionsCountRnd.Next();
                    var userActions       = new List <BusinessUserTransaction>();

                    for (int i = 0; i < transactionsCount; i++)
                    {
                        if (userAccounts.All(a => a.Balance < minAmount))
                        {
                            continue;
                        }
                        var amount    = GetAmount(userAccounts, amountRnd);
                        var sender    = GetSender(amount, userAccounts);
                        var recipient = groupAccounts.ElementAt(rand.Next(0, groupAccounts.Length));

                        userActions.Add(new BusinessUserTransaction {
                            Amount = amount, AccountId = sender.Id, Recipient = recipient.Id, Title = titelRnd.Next()
                        });

                        sender.Balance    -= amount;
                        recipient.Balance += amount;
                    }

                    allActions.Add(new BusinessUserScenarioElement {
                        No = (no++).ToString(), Group = group.Key, UserId = user.Id, User = user.Login, Transactions = userActions.ToArray()
                    });
                }
            }

            return(allActions.GroupBy(a => a.Group % requesters).Select(g => JsonConvert.SerializeObject(g)).ToArray());
        }