public void Create(ref MeasurementTool tool, List <MasterItem> items = null, List <MasterCustomer> customers = null)
        {
            int  workloadSize = 10_00;
            long maxVal       = Customers.OrderByDescending(cus => cus.ID).First().ID;

            MasterCustomer[] cusArray  = MasterCustomer.GenerateCustomers(500, "createDeNorm", maxVal).ToArray();
            MasterItem[]     itemArray = items.ToArray();

            Random   new_or_oldSelector   = new Random(4573);
            Random   customerGenSelector  = new Random(867542);
            Random   customerSelector     = new Random(456542);
            Random   satisfySelector      = new Random(2678);
            Random   storeSelector        = new Random(236786);
            Random   diffItemSelector     = new Random(83457);
            Random   quantityItemSelector = new Random(6526);
            Random   itemSelector         = new Random(572);
            Random   dateSelector         = new Random(6762);
            DateTime startDate            = new DateTime(2020, 1, 2);
            DateTime endDate = new DateTime(2020, 5, 28);
            int      range   = (endDate - startDate).Days;

            for (int i = 0; i < workloadSize; i++)
            {
                Console.WriteLine($"{i} ud af {workloadSize}");
                int      new_old  = new_or_oldSelector.Next(0, 2);
                string   title    = new_old == 0 ? "PostgreSQL,Sale,DeNorm,Create,New user" : "PostgreSQL,Sale,DeNorm,Create,Existing user";
                Customer customer = null;
                //New
                if (new_old == 0)
                {
                    MasterCustomer tmpcustomer = cusArray[customerGenSelector.Next(0, cusArray.Length)];
                    customer = new Customer
                    {
                        Age    = tmpcustomer.Age,
                        Email  = tmpcustomer.Email,
                        Gender = tmpcustomer.Gender,
                    };
                    tool.Stopwatch.Start();
                    Customers.Add(customer);
                    Console.WriteLine(customer.ID);
                    SaveChanges();
                    tool.Stopwatch.Stop();
                }
                //Exisiting
                else
                {
                    int  max    = (int)Customers.OrderByDescending(cus => cus.ID).First().ID;
                    long ranpos = (long)customerSelector.Next(1, max);
                    customer = Customers.Find(ranpos);
                }
                int satisfactorynumber = satisfySelector.Next(0, 10);
                //Item selection and Saleitem creation
                List <string> usedItems = new List <string>();
                int           diffItems = diffItemSelector.Next(1, 5);
                long?         tmpSaleId = null;
                for (int j = 0; j < diffItems; j++)
                {
                    int itemIndex = itemSelector.Next(0, itemArray.Length);
                    if (!usedItems.Contains(itemArray[itemIndex].Name))
                    {
                        // Find item
                        usedItems.Add(itemArray[itemIndex].Name);
                        int  itemQuant = quantityItemSelector.Next(1, 5);
                        Item foundItem = Items.Where(it => it.Name.Equals(itemArray[itemIndex].Name)).First();
                        //Sale creation
                        Sale sale = new Sale
                        {
                            ID                         = tmpSaleId,
                            ItemId                     = foundItem.ID,
                            ItemName                   = foundItem.Name,
                            ItemPrice                  = foundItem.Price,
                            ItemQuantity               = itemQuant,
                            CustomerId                 = customer.ID,
                            CustomerAge                = customer.Age,
                            CustomerEmail              = customer.Email,
                            CustomerGender             = customer.Gender,
                            Date                       = startDate.AddDays(dateSelector.Next(range)),
                            CouponUsed                 = false,
                            PurchaseMethod             = "Card",
                            StoreLocation              = StoreLocation.Locations[storeSelector.Next(0, 9)],
                            CustomerSatisfactoryNumber = satisfactorynumber
                        };
                        tool.Stopwatch.Start();
                        Sales.Add(sale);
                        SaveChanges();
                        tool.Stopwatch.Stop();
                        tmpSaleId = sale.ID;
                    }
                    else
                    {
                        break;
                    }
                }
                //Saves measurements every sale update
                tool.SaveAndReset(title);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Initialising");
            Console.WriteLine("Reading files");
            //Both CSV files has the properties: BuildAction=None, CopyToOutputDir=Always
            List <MasterItem> Items = ParseItem();
            List <string>     tags  = TagList(Items);

            List <MasterCustomer> Customers = MasterCustomer.GenerateCustomers(30);

            DbRunnerTest(PsqlSaleDeNormDbContext.GetTypeName().FullName, Customers, Items, tags);
            int cmd = 0;

            if (args.Length > 0)
            {
                int.TryParse(args[0], out cmd);
            }
            switch (cmd)
            {
            case 0:     // run all as default, arguments can be used when using multiple docker containers
                Console.WriteLine("Running all dbs");
                //DbRunner(MonBankDeNormDbContext.GetTypeName().FullName, Customers, Items);

                /*
                 * DbRunner(MonBankNormDbContext.GetTypeName().FullName, Customers, Items);
                 * DbRunner(MonSaleDeNormDbContext.GetTypeName().FullName, Customers, Items);
                 * DbRunner(MonSaleNormDbContext.GetTypeName().FullName, Customers, Items);
                 * DbRunner(PsqlBankDeNormDbContext.GetTypeName().FullName, Customers, Items);
                 * DbRunner(PsqlBankNormDbContext.GetTypeName().FullName, Customers, Items);
                 * DbRunner(PsqlSaleDeNormDbContext.GetTypeName().FullName, Customers, Items);
                 * DbRunner(PsqlSaleNormDbContext.GetTypeName().FullName, Customers, Items);
                 */
                break;

            case 1:
                Console.WriteLine("Running MonBankDeNormDbContext");
                DbRunner(MonBankDeNormDbContext.GetTypeName().FullName, Customers, Items, tags);
                break;

            case 2:
                Console.WriteLine("Running MonBankNormDbContext");
                DbRunner(MonBankNormDbContext.GetTypeName().FullName, Customers, Items, tags);
                break;

            case 3:
                Console.WriteLine("Running MonSaleDeNormDbContext");
                DbRunner(MonSaleDeNormDbContext.GetTypeName().FullName, Customers, Items, tags);
                break;

            case 4:
                Console.WriteLine("Running MonSaleNormDbContext");
                DbRunner(MonSaleNormDbContext.GetTypeName().FullName, Customers, Items, tags);
                break;

            case 5:
                Console.WriteLine("Running PsqlBankDeNormDbContext");
                DbRunner(PsqlBankDeNormDbContext.GetTypeName().FullName, Customers, Items, tags);
                break;

            case 6:
                Console.WriteLine("Running PsqlBankNormDbContext");
                DbRunner(PsqlBankNormDbContext.GetTypeName().FullName, Customers, Items, tags);
                break;

            case 7:
                Console.WriteLine("Running PsqlSaleDeNormDbContext");
                DbRunner(PsqlSaleDeNormDbContext.GetTypeName().FullName, Customers, Items, tags);
                break;

            case 8:
                Console.WriteLine("Running PsqlSaleNormDbContext");
                DbRunner(PsqlSaleNormDbContext.GetTypeName().FullName, Customers, Items, tags);
                break;
            }
        }