//Generates the total(entire world) sales vs target list for given period and grouped by Month.
        public static ObservableCollection <SalesVsTarget> GenerateTotalSalesVsTargetList(ObservableCollection <SalesDetail> salesDetails)
        {
            ObservableCollection <SalesVsTarget> salesVsTargetList = new ObservableCollection <SalesVsTarget>();
            var    query     = from sales in salesDetails group sales by sales.OrderDate.Month into grouping select grouping;
            Random rand      = new Random();
            double value     = 20;
            double nextvalue = 40;

            foreach (SalesDetail groupedRecord in salesDetails)
            {
                if (rand.NextDouble() > .5)
                {
                    value     += rand.NextDouble();
                    nextvalue += rand.NextDouble();
                }
                else
                {
                    value     -= rand.NextDouble();
                    nextvalue -= rand.NextDouble();
                }
                SalesVsTarget salesVsTarget = new SalesVsTarget();

                salesVsTarget.Month        = groupedRecord.OrderDate.Month;
                salesVsTarget.Date         = groupedRecord.OrderDate;
                salesVsTarget.Sales        = groupedRecord.OrderTotal * nextvalue;
                salesVsTarget.Target       = ((salesVsTarget.Sales * value) / 100) + salesVsTarget.Sales;
                salesVsTarget.SalesPercent = (salesVsTarget.Sales / salesVsTarget.Target) * 100;
                salesVsTargetList.Add(salesVsTarget);
            }

            return(salesVsTargetList);
        }
        //Generates the total sales vs target list of given continent for given period and grouped by month.
        public static ObservableCollection <SalesVsTarget> GenerateTotalSalesVsTargetListByContinent(ObservableCollection <SalesDetail> salesDetails, string continent)
        {
            ObservableCollection <SalesVsTarget> salesVsTargetList = new ObservableCollection <SalesVsTarget>();
            var    query = from sales in salesDetails where sales.Continent == continent group sales by sales.OrderDate.Month into grouping select grouping;
            Random rand  = new Random();

            foreach (IGrouping <int, SalesDetail> groupedRecord in query)
            {
                SalesVsTarget salesVsTarget = new SalesVsTarget();

                salesVsTarget.Month        = groupedRecord.Key;
                salesVsTarget.Date         = groupedRecord.ElementAt(groupedRecord.Key).OrderDate;
                salesVsTarget.Sales        = groupedRecord.Sum(s => s.OrderTotal);
                salesVsTarget.Target       = ((salesVsTarget.Sales * rand.Next(-10, 30)) / 100) + salesVsTarget.Sales;
                salesVsTarget.SalesPercent = (salesVsTarget.Sales / salesVsTarget.Target) * 100;
                salesVsTargetList.Add(salesVsTarget);
            }

            return(salesVsTargetList);
        }
Exemple #3
0
        public static ObservableCollection <ProductVsCountry> GenerateProductVsCountry(ObservableCollection <SalesDetail> salesDetails)//,ObservableCollection<SalesVsTarget> sale)
        {
            Random rand = new Random();
            ObservableCollection <ProductVsCountry> productVscountry = new ObservableCollection <ProductVsCountry>();
            ObservableCollection <Countries>        countryList      = Countries.GetCountries();
            ObservableCollection <SalesVsTarget>    sales            = GenerateTotalSalesVsTargetList(salesDetails);

            string[]  labels                       = { "Tablet", "Desktop", "Hybrid", "Laptop", "Smartphone" };
            var       query                        = from saleD in salesDetails group saleD by saleD.Country into grouping select grouping;
            Countries countries                    = new Countries();
            List <ProductVsCountry> data           = new List <ProductVsCountry>();
            SalesVsTarget           salesVsTargets = new SalesVsTarget();
            Random r            = new Random();
            float  salespercent = 0;

            for (int i = 0; i < labels.Length; i++)
            {
                salespercent = r.Next(10, 95);
            }

            foreach (IGrouping <string, SalesDetail> groupedRecord in query)
            {
                double market = r.NextDouble();
                market = Math.Round(market, 2);
                //SalesByContinet salesVsTarget = new SalesByContinet();
                sales     = SalesDetail.GenerateTotalSalesVsTargetList(salesDetails);
                countries = countryList[rand.Next(0, (countryList.Count) - 1)];
                productVscountry.Add(new ProductVsCountry
                {
                    country            = countries.Country,
                    continent          = countries.Continent,
                    MarketingVsRevenue = market,
                    SalesPercent       = salespercent
                });
            }
            return(productVscountry);
        }