Exemplo n.º 1
0
 public ActionResult Bands(long industryId, long boundingGeographicLocationId, int bands, Core.DataLayer.Granularity granularity, string contentType = "*/*")
 {
     // contentType arg should also be checked for application/json and application/javascript,
     // but those seem to be inferred by other code like APIContext.IsJsonp, alluded to in
     // Controller.Json, and etc. For now we'll leave those alone and just check for:
     if ("text/html".Equals(contentType))
     {
         using (var context = ContextFactory.SizeUpContext)
         {
             Expression <Func <SizeUp.Data.IndustryData, bool> >             filter = i => i.AverageRevenue != null;
             Expression <Func <SizeUp.Data.IndustryData, Kpi.LabeledValue> > selector;
             selector = i => new Kpi.LabeledValue
             {
                 Label = i.GeographicLocation.LongName,
                 Value = i.AverageRevenue
             };
             Kpi.GetKpiModel(
                 ViewBag, context,
                 industryId, boundingGeographicLocationId, granularity,
                 filter, selector, "Average Annual Revenue", "${0}", bands
                 );
             return(View("Heatmap"));
         }
     }
     else
     {
         using (var context = ContextFactory.SizeUpContext)
         {
             var data = Core.DataLayer.AverageRevenue.Bands(context, industryId, boundingGeographicLocationId, bands, granularity);
             return(Json(data, JsonRequestBehavior.AllowGet));
         }
     }
 }
Exemplo n.º 2
0
        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
                );
        }
Exemplo n.º 3
0
 public ActionResult Bands(
     long industryId, long boundingGeographicLocationId, int bands,
     Core.DataLayer.Granularity granularity, string contentType = "*/*"
     )
 {
     using (var context = ContextFactory.SizeUpContext)
     {
         if ("text/html".Equals(contentType))
         {
             Expression <Func <SizeUp.Data.IndustryData, bool> >             filter = i => i.TotalRevenue != null;
             Expression <Func <SizeUp.Data.IndustryData, Kpi.LabeledValue> > selector;
             selector = i => new Kpi.LabeledValue
             {
                 Label = i.GeographicLocation.LongName,
                 Value = i.TotalRevenue
             };
             Kpi.GetKpiModel(
                 ViewBag, context,
                 industryId, boundingGeographicLocationId, granularity,
                 filter, selector, "Total Revenue", "${0}", bands
                 );
             return(View("Heatmap"));
         }
         else
         {
             var data = Core.DataLayer.TotalRevenue.Bands(context, industryId, boundingGeographicLocationId, bands, granularity);
             return(Json(data, JsonRequestBehavior.AllowGet));
         }
     }
 }
Exemplo n.º 4
0
 public static List <Band> GetKpiBands(
     SizeUpContext context, long industryId, long locationId, string granularityName,
     Expression <Func <IndustryData, bool> > filter,
     Expression <Func <IndustryData, LabeledValue> > selector,
     string formatString, int numBands
     )
 {
     return(Core.DataLayer.IndustryData.Get(context)
            .Where(i => i.GeographicLocation.GeographicLocations.Any(gl => gl.Id == locationId))
            .Where(i => i.IndustryId == industryId)
            .Where(i => i.GeographicLocation.Granularity.Name == granularityName)
            .Where(filter)
            .Select(selector)
            .ToList()
            .NTileDescending(i => i.Value, numBands)
            .Select(i => new Kpi.Band
     {
         Min = string.Format(formatString, Kpi.Format(i.Min(v => v.Value.Value))),
         Max = string.Format(formatString, Kpi.Format(i.Max(v => v.Value.Value))),
         Items = i.Select(v => v.Label).ToList()
     })
            .ToList());
 }
        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));
                }
            }
        }