/// <summary> /// Generates random data and populates the specified list. /// </summary> private void GenerateData(List <Sale> list) { DataTable table = this.GeoData.Table; int rowCount = table.Rows.Count; int[] years = new int[] { 2009, 2010, 2011, 2012, 2013, 2014 }; int[] sizes = new int[] { 800, 1150, 1250, 1800, 1200, 1500 }; for (int i = 0; i < years.Length; i++) { int year = years[i]; int size = sizes[i]; DateTime minDate = new DateTime(year, 1, 1); DateTime maxDate = year == DateTime.Today.Year ? new DateTime(year, DateTime.Today.Month, 1) : new DateTime(year, 12, 31); int processed = 0; while (processed < size) { processed += 1; int rowIndex = Randomizer.Random(0, rowCount - 1); DataRow row = table.Rows[rowIndex]; string zipCode = row["ZipCode"] as string; if (SalesData.IsZipValid(zipCode) == false) { continue; } string city = row["City"] as string; if (string.IsNullOrEmpty(city)) { continue; } string state = row["State"] as string; HoodieStyle style = Randomizer.RandomStyle(); DateTime date = Randomizer.Random(minDate, maxDate); int priceIndex = Randomizer.Random(0, SalesData.priceRange.Length); decimal price = priceRange[priceIndex]; Sale sale = new Sale(date, style, price, zipCode, city, state); list.Add(sale); } } }
/// <summary>Creates a new instance.</summary> public OlapData(SalesData salesData, Control sync) { this.salesData = salesData; this.sync = sync; }
/// <summary>Creates a new instance.</summary> public SalesSummaryData(SalesData salesData, DateFilter[] filters) { Dictionary <int, Dictionary <HoodieStyle, decimal> > data = new Dictionary <int, Dictionary <HoodieStyle, decimal> >(); // First pass: create the outer table foreach (Sale sale in salesData) { int year = sale.Year; int index = year - SalesData.MinDate.Year; DateFilter filter = index < filters.Length ? filters[index] : null; if (filter != null && filter.IsFilteredIn() == false) { continue; } Dictionary <HoodieStyle, decimal> summary = null; if (data.TryGetValue(year, out summary) == false) { summary = new Dictionary <HoodieStyle, decimal>(); data.Add(year, summary); } } // Second pass: aggregate summaries foreach (Sale sale in salesData) { int index = sale.Year - SalesData.MinDate.Year; int quarter = DateFilter.GetQuarter(sale.Date); DateFilter filter = index < filters.Length ? filters[index] : null; if (filter != null && filter.IsFilteredIn(quarter) == false) { continue; } Dictionary <HoodieStyle, decimal> summary = null; if (data.TryGetValue(sale.Year, out summary) == false) { continue; } decimal total = 0m; if (summary.TryGetValue(sale.Style, out total) == false) { summary.Add(sale.Style, 0m); } summary[sale.Style] += sale.Price; } // Create SalesSummary instances for each year this.List = new List <SalesSummary>(data.Count); decimal min = decimal.MaxValue; decimal max = 0m; foreach (KeyValuePair <int, Dictionary <HoodieStyle, decimal> > pair in data) { SalesSummary summary = new SalesSummary(pair.Key, pair.Value); this.List.Add(summary); min = Math.Min(min, summary.Minimum); max = Math.Max(max, summary.Maximum); } // Set the min/max this.Minimum = min; this.Maximum = max; // Sort the list by year this.List.Sort(new Sorter()); }