Exemplo n.º 1
0
        /**
         *      \param count Number of users to generate
         *      \param database DB to use in query.
         *      \return Generated SQL query.
         *      \brief Generates the number of given users using random pieces of data, for random looking users (User, Address, UserToTag)
         */
        public static string GenerateUsers(int count, string database)
        {
            string result         = "USE " + database + ";\n";
            int    startAddressID = GetAutoIncrementID(database, "Address");
            int    startUserID    = GetAutoIncrementID(database, "User");

            if (startAddressID < 0)
            {
                startAddressID = 1;
            }
            if (startUserID < 0)
            {
                startUserID = 1;
            }

            // Container for different tables / insert statement groups
            List <List <string> > addresses   = CustomGenerator.GetAddresses(count);
            List <List <string> > users       = CustomGenerator.GetUsers(count, startAddressID);
            List <string>         categoryIDs = Database.GetRows(count, Database.DB_MAIN, "Category", "ID", Database.FORMAT_NUMBER);
            List <List <string> > userTags    = CustomGenerator.GetTags(count, 4, categoryIDs);

            // Format lists into query statements
            result += PrepareOutput(count, "Address", addresses, new bool[] { true, true, false, true });
            result += PrepareOutput(count, "User", users, new bool[] { false, true, true, true, true, true });
            result += PrepareOutputTags("UserToTag", userTags, startUserID);

            //result += CompactQueries("Address", addresses.ToArray(), new bool[] { true, true, false, true });
            //result += CompactQueries("User", users.ToArray(), new bool[] { false, true, true, true, true, true });
            //result += PrepareOutputTags("UserToTag", userTags, startUserID);

            return(result);
        }
Exemplo n.º 2
0
        /**
         *      \param count Number of events to generate
         *      \param database DB to insert into.
         *      \return string The SQL query.
         *      \brief Generates the number of requested events, randomly selecting data where needed to create random data (Product, Event, ProductToTag, ProductToEvent, SellerToEvent).
         */
        public static string GenerateEvents(int count, string database)
        {
            string result         = "USE " + database + ";\n";
            int    startProductID = GetAutoIncrementID(database, "Product");
            int    startEventID   = GetAutoIncrementID(database, "Event");

            if (startProductID < 0)
            {
                startProductID = 1;
            }
            if (startEventID < 0)
            {
                startEventID = 1;
            }

            // Container for different tables / insert statement groups
            // List of users (sellers)
            List <string> sellerIDs = Database.GetRows(count, Database.DB_MAIN, "User", "ID", Database.FORMAT_NUMBER);

            // Product
            List <List <string> > products         = CustomGenerator.GetProducts(count, sellerIDs, startEventID, startProductID);
            List <string>         categoryIDsEvent = Database.GetRows(count, Database.DB_MAIN, "Category", "ID", Database.FORMAT_NUMBER);

            // Loop through and create a categoryID for each product set
            // (one item for each product, needed so that events have the same product types, ex. (1, 1, 5, 3, 3, 3, 2, 2))
            List <string> categoryIDsProduct = new List <string>();
            List <string> currentBiddingIDs  = new List <string>();
            int           j           = 0;
            string        prevEventID = "";

            for (int i = 0; i < products[0].Count(); i++)
            {
                string currEventID = products[5][i];

                if (i != 0 && prevEventID != currEventID)
                {
                    j++;
                }

                // Track first product in each event
                if (prevEventID != currEventID)
                {
                    currentBiddingIDs.Add((i + startProductID).ToString());
                }

                categoryIDsProduct.Add(categoryIDsEvent[j]);
                prevEventID = currEventID;
            }
            List <List <string> > productTags = CustomGenerator.GetTags(products[0].Count(), 1, categoryIDsProduct);

            List <string> productsFirstTagID = new List <string>();

            for (int i = 0; i < productTags.Count(); i++)
            {
                productsFirstTagID.Add(productTags[i][0]);
            }

            // Event
            List <List <string> > events = CustomGenerator.GetEvents(count, currentBiddingIDs, categoryIDsEvent);

            // Update products to have the correct images
            List <string> productImages = CustomGenerator.GetRowsByFilterID(products[0].Count(), productsFirstTagID, DB_SAMPLES, "ProductImages", "Value", "TagID", "Tag");

            products.Insert(3, productImages);

            // Set the event image to the first product image
            List <string> eventImages = new List <string>();

            prevEventID = "";
            for (int i = 0; i < products[0].Count(); i++)
            {
                string currEventID = products[6][i];

                // Track first product in each event
                if (prevEventID != currEventID)
                {
                    eventImages.Add(products[3][i]);
                }

                prevEventID = currEventID;
            }
            events.Insert(4, eventImages);

            // Product to Events
            List <List <string> > productsToEvents = new List <List <string> >();
            List <string>         eventIDs         = products[products.Count() - 2];
            List <string>         productIDs       = products[products.Count() - 1];

            productsToEvents.Add(eventIDs);
            productsToEvents.Add(productIDs);

            // Seller to Events
            List <List <string> > sellerToEvents        = new List <List <string> >();
            List <string>         sellerToEventEventIDs = new List <string>();

            for (int i = 0; i < count; i++)
            {
                string eventIDSingle = (i + startEventID).ToString();
                sellerToEventEventIDs.Add(eventIDSingle);
            }
            sellerToEvents.Add(sellerIDs);
            sellerToEvents.Add(sellerToEventEventIDs);


            // Remove temporary data holders (productId, eventId)
            products.RemoveAt(products.Count() - 1);
            products.RemoveAt(products.Count() - 1);

            // Format lists into query statements
            int fullCount = products[0].Count();

            result += PrepareOutput(fullCount, "Product", products, new bool[] { true, false, true, true, false, false });
            result += PrepareOutput(count, "Event", events, new bool[] { true, true, true, true, true, false, false });
            //result += PrepareOutputTags("ProductToTag", productTags, startProductID);
            //result += PrepareOutput(fullCount, "ProductToEvent", productsToEvents, new bool[] { false, false });
            //result += PrepareOutput(count, "SellerToEvent", sellerToEvents, new bool[] { false, false });

            //result += CompactQueries("Product", products.ToArray(), new bool[] { true, false, true, true, false, false });
            //result += CompactQueries("Event", events.ToArray(), new bool[] { true, true, true, true, true, false });
            result += PrepareOutputTags("ProductToTag", productTags, startProductID);
            result += CompactQueries("ProductToEvent", productsToEvents.ToArray(), new bool[] { false, false });
            result += CompactQueries("SellerToEvent", sellerToEvents.ToArray(), new bool[] { false, false });

            return(result);
        }