public static void GetKpiModel( dynamic ViewBag, SizeUpContext context, long industryId, long locationId, Core.DataLayer.Granularity granularity, Expression <Func <IndustryData, bool> > filter, Expression <Func <IndustryData, LabeledValue> > selector, string kpiName, string formatString, int numBands ) { var gran = Enum.GetName(typeof(Core.DataLayer.Granularity), granularity); var data = Kpi.GetKpiBands(context, industryId, locationId, gran, filter, selector, formatString, numBands); // probably obsolete ViewBag.BoundingEntity = context.GeographicLocations .Where(i => i.Id == locationId) .Select(i => i.LongName) .FirstOrDefault(); // current ViewBag.Area = ViewBag.BoundingEntity; ViewBag.Bands = Kpi.FormatBands(data); ViewBag.Industry = context.Industries .Where(i => i.Id == industryId) .Select(i => i.Name) .FirstOrDefault(); ViewBag.Kpi = kpiName; ViewBag.LevelOfDetail = Kpi.TranslateGranularity(granularity); ViewBag.Q = numBands.ToString(); ViewBag.ThemeUrl = System.Configuration.ConfigurationManager.AppSettings["Theme.Url"]; ViewBag.Query = string.Format( "Rank {0} in {1}, by {2} of {3} businesses, in {4} quantiles", ViewBag.LevelOfDetail, ViewBag.Area, ViewBag.Kpi, ViewBag.Industry, ViewBag.Q ); }
public ActionResult Bands( int variableId, long boundingGeographicLocationId, int bands, Core.DataLayer.Granularity granularity, string contentType = "*/*") { using (var context = ContextFactory.SizeUpContext) { if ("text/html".Equals(contentType)) { var variable = context.ConsumerExpenditureVariables .Where(i => i.Id == variableId) .FirstOrDefault(); var gran = Enum.GetName(typeof(Core.DataLayer.Granularity), granularity); int granularityId = 0; if (granularity == Core.DataLayer.Granularity.ZipCode) { granularityId = 1; } else if (granularity == Core.DataLayer.Granularity.City) { granularityId = 2; } else if (granularity == Core.DataLayer.Granularity.County) { granularityId = 3; } else if (granularity == Core.DataLayer.Granularity.Place) { granularityId = 4; } else if (granularity == Core.DataLayer.Granularity.Metro) { granularityId = 5; } else if (granularity == Core.DataLayer.Granularity.State) { granularityId = 6; } else if (granularity == Core.DataLayer.Granularity.Nation) { granularityId = 7; } var data = context.ConsumerExpenditures .Where(i => i.Year == CommonFilters.TimeSlice.ConsumerExpenditures.Year && i.Quarter == CommonFilters.TimeSlice.ConsumerExpenditures.Quarter) .Where(i => i.GeographicLocation.Granularity.Name == gran) .Where(i => i.GeographicLocation.GeographicLocations.Any(g => g.Id == boundingGeographicLocationId)); int count = data.ToList().Count(); var output = GetPayloads(variable.Variable, granularityId, boundingGeographicLocationId) .NTileDescending(i => i.Value, bands) .Select(i => new Kpi.Band { Min = string.Format("${0}", Kpi.Format(i.Min(v => v.Value))), Max = string.Format("${0}", Kpi.Format(i.Max(v => v.Value))), Items = i.Select(v => v.Name).ToList() }) .ToList(); ViewBag.Area = context.GeographicLocations .Where(i => i.Id == boundingGeographicLocationId) .Select(i => i.LongName) .FirstOrDefault(); ViewBag.Bands = Kpi.FormatBands(output); ViewBag.Expenditure = variable; ViewBag.LevelOfDetail = Kpi.TranslateGranularity(granularity); ViewBag.Q = bands.ToString(); ViewBag.ThemeUrl = System.Configuration.ConfigurationManager.AppSettings["Theme.Url"]; ViewBag.Query = string.Format( "Rank {0} in {1}, by {2} Consumer Spending on {3}, in {4} quantiles", ViewBag.LevelOfDetail, ViewBag.Area, variable.Variable.StartsWith("X") ? "Average" : "Total", variable.Description, ViewBag.Q ); return(View("Heatmap")); } else { var output = Core.DataLayer.ConsumerExpenditures.Bands(context, variableId, boundingGeographicLocationId, bands, granularity); return(Json(output, JsonRequestBehavior.AllowGet)); } } }