コード例 #1
0
        public static IQueryable <Models.DistanceEntity <Data.Business> > Near(SizeUpContext context, LatLng latLng)
        {
            var distanceFilter = new DistanceEntity <Data.Business> .DistanceEntityFilter(latLng);

            return(Get(context)
                   .Where(i => i.MatchLevel == "0")
                   .Select(i => new KeyValue <Data.Business, Geo.LatLng>
            {
                Key = i,
                Value = new Geo.LatLng {
                    Lat = (double)i.Lat, Lng = (double)i.Long
                }
            })
                   .Select(distanceFilter.Projection));
        }
コード例 #2
0
ファイル: Place.cs プロジェクト: microbet/sizeup
        public static IQueryable <Models.DistanceEntity <Models.Place> > ListNear(SizeUpContext context, Core.Geo.LatLng latLng)
        {
            var distanceFilter = new DistanceEntity <Data.Place> .DistanceEntityFilter(latLng);

            return(Get(context)
                   .Select(i => new KeyValue <Data.Place, Geo.LatLng>
            {
                Key = i,
                Value = i.GeographicLocation.Geographies.AsQueryable().Where(g => g.GeographyClass.Name == Geo.GeographyClass.Calculation)
                        .Select(g => new Geo.LatLng {
                    Lat = g.CenterLat.Value, Lng = g.CenterLong.Value
                })
                        .FirstOrDefault()
            })
                   .Select(distanceFilter.Projection)
                   .Select(new Projections.Place.Distance().Expression));
        }
コード例 #3
0
ファイル: Place.cs プロジェクト: microbet/sizeup
        public static Models.Place GetBoundingCity(SizeUpContext context, Core.Geo.LatLng latLng)
        {
            var distanceFilter = new DistanceEntity <Data.Place> .DistanceEntityFilter(latLng);

            var locations = Core.DataLayer.Geography.Get(context).Where(x =>
                                                                        x.West <= latLng.Lng && x.East >= latLng.Lng &&
                                                                        x.North >= latLng.Lat && x.South <= latLng.Lat
                                                                        );

            foreach (var location in locations)
            {
                var geoId = location.GeographicLocationId;
                var geographicLocation = Core.DataLayer.GeographicLocation.Get(context).Any(x => x.Id == geoId && x.GranularityId == 4);

                if (geographicLocation == true)
                {
                    return(Core.DataLayer.Place.Get(context).Where(x => x.GeographicLocation.Id == geoId)
                           .Select(new Projections.Place.Default().Expression)
                           .FirstOrDefault());
                }
            }
            return(null);
        }
コード例 #4
0
ファイル: Advertising.cs プロジェクト: microbet/sizeup
        public static IQueryable <Models.Advertising> Get(SizeUpContext context, long industryId, long geographicLocationId, AdvertisingFilters filters)
        {
            var center = Core.DataLayer.Geography.Display(context)
                         .Where(i => i.GeographicLocationId == geographicLocationId)
                         .Select(new Projections.Geography.Centroid().Expression)
                         .Select(i => i.Value)
                         .FirstOrDefault();

            DistanceEntity <Grouping> .DistanceEntityFilter dist = new DistanceEntity <Grouping> .DistanceEntityFilter(center);

            var data = context.ZipCodes
                       .SelectMany(i => i.GeographicLocation.Demographics, (i, o) => new { ZipCode = i, Demographics = o })
                       .SelectMany(i => i.ZipCode.GeographicLocation.IndustryDatas, (i, o) => new { i.ZipCode, i.Demographics, IndustryData = o })
                       .SelectMany(i => i.ZipCode.GeographicLocation.Geographies, (i, o) => new { i.ZipCode, i.Demographics, i.IndustryData, Geography = o, Place = i.ZipCode.Places.FirstOrDefault() })
                       .Where(i => i.Demographics.Year == CommonFilters.TimeSlice.Demographics.Year && i.Demographics.Quarter == CommonFilters.TimeSlice.Demographics.Quarter)
                       .Where(i => i.IndustryData.Year == CommonFilters.TimeSlice.Industry.Year && i.IndustryData.Quarter == CommonFilters.TimeSlice.Industry.Quarter && i.IndustryData.IndustryId == industryId)
                       .Where(i => i.Geography.GeographyClass.Name == Geo.GeographyClass.Calculation)
                       .Select(i => new KeyValue <Grouping, Geo.LatLng>
            {
                Key = new Grouping
                {
                    Place              = i.Place,
                    IndustryData       = i.IndustryData,
                    Demographics       = i.Demographics,
                    Geography          = i.Geography,
                    ZipCode            = i.ZipCode,
                    TotalEmployeesBand = i.IndustryData.Bands.Where(b => b.Attribute.Name == IndustryAttribute.TotalEmployees).Select(b => new Band <double> {
                        Min = (double)b.Min.Value, Max = (double)b.Max.Value
                    }).FirstOrDefault(),
                    AverageRevenueBand = i.IndustryData.Bands.Where(b => b.Attribute.Name == IndustryAttribute.AverageRevenue).Select(b => new Band <double> {
                        Min = (double)b.Min.Value, Max = (double)b.Max.Value
                    }).FirstOrDefault(),
                    TotalRevenueBand = i.IndustryData.Bands.Where(b => b.Attribute.Name == IndustryAttribute.TotalRevenue).Select(b => new Band <double> {
                        Min = (double)b.Min.Value, Max = (double)b.Max.Value
                    }).FirstOrDefault(),
                    RevenuePerCapitaBand = i.IndustryData.Bands.Where(b => b.Attribute.Name == IndustryAttribute.RevenuePerCapita).Select(b => new Band <double> {
                        Min = (double)b.Min.Value, Max = (double)b.Max.Value
                    }).FirstOrDefault()
                },
                Value = new Geo.LatLng
                {
                    Lat = i.Geography.CenterLat.Value,
                    Lng = i.Geography.CenterLong.Value
                }
            })
                       .Select(dist.Projection)
                       .Select(i => new { i.Distance, i.Entity.Demographics, i.Entity.Geography, i.Entity.IndustryData, i.Entity.ZipCode, i.Entity.TotalRevenueBand, i.Entity.TotalEmployeesBand, i.Entity.RevenuePerCapitaBand, i.Entity.AverageRevenueBand, Place = i.Entity.Place })
                       .Select(i => new DistanceEntity <Wrapper>
            {
                Distance = i.Distance,
                Entity   = new Wrapper
                {
                    Place   = i.Place,
                    ZipCode = new Models.ZipCode
                    {
                        Id   = i.ZipCode.Id,
                        Name = i.ZipCode.Name,
                        Zip  = i.ZipCode.Zip
                    },
                    Centroid = new Geo.LatLng
                    {
                        Lat = i.Geography.CenterLat.Value,
                        Lng = i.Geography.CenterLong.Value
                    },
                    BoundingBox = new Geo.BoundingBox
                    {
                        NorthEast = new Geo.LatLng
                        {
                            Lat = i.Geography.North,
                            Lng = i.Geography.East
                        },
                        SouthWest = new Geo.LatLng
                        {
                            Lat = i.Geography.South,
                            Lng = i.Geography.West
                        }
                    },
                    AverageRevenue          = i.IndustryData.AverageRevenue,
                    TotalRevenue            = i.IndustryData.TotalRevenue,
                    TotalEmployees          = i.IndustryData.TotalEmployees,
                    RevenuePerCapita        = i.IndustryData.RevenuePerCapita,
                    BachelorsDegreeOrHigher = i.Demographics.BachelorsOrHigherPercentage,
                    HighSchoolOrHigher      = i.Demographics.HighSchoolOrHigherPercentage,
                    HouseholdIncome         = i.Demographics.MedianHouseholdIncome,
                    WhiteCollarWorkers      = i.Demographics.WhiteCollarWorkersPercentage,
                    MedianAge             = i.Demographics.MedianAge,
                    Population            = i.Demographics.TotalPopulation,
                    HouseholdExpenditures = i.Demographics.AverageHouseholdExpenditure,

                    TotalEmployeesBand   = i.TotalEmployeesBand,
                    AverageRevenueBand   = i.AverageRevenueBand,
                    TotalRevenueBand     = i.TotalRevenueBand,
                    RevenuePerCapitaBand = i.RevenuePerCapitaBand
                }
            });

            data = FilterQuery(data, filters);

            IQueryable <Models.Advertising> output = new List <Models.Advertising>().AsQueryable();

            output = data.Select(i => new Models.Advertising
            {
                PlaceId                 = i.Entity.Place.Id,
                StateSEOKey             = i.Entity.Place.County.State.SEOKey,
                CountySEOKey            = i.Entity.Place.County.SEOKey,
                CitySEOKey              = i.Entity.Place.City.SEOKey,
                Centroid                = i.Entity.Centroid,
                BoundingBox             = i.Entity.BoundingBox,
                TotalEmployees          = i.Entity.TotalEmployeesBand,
                TotalRevenue            = i.Entity.TotalRevenueBand,
                AverageRevenue          = i.Entity.AverageRevenueBand,
                RevenuePerCapita        = i.Entity.RevenuePerCapitaBand,
                BachelorsDegreeOrHigher = i.Entity.BachelorsDegreeOrHigher,
                HighSchoolOrHigher      = i.Entity.HighSchoolOrHigher,
                HouseholdExpenditures   = i.Entity.HouseholdExpenditures,
                HouseholdIncome         = i.Entity.HouseholdIncome,
                MedianAge               = i.Entity.MedianAge,
                Population              = i.Entity.Population,
                WhiteCollarWorkers      = i.Entity.WhiteCollarWorkers,
                ZipCode                 = i.Entity.ZipCode,
                Distance                = i.Distance
            });

            return(output);
        }