Esempio n. 1
0
        public void Add(T item)
        {
            GenericValidator.CheckInitialization(item, nameof(item));

            var coordinate = _dbContext.Set <Models.Coordinates>().FirstOrDefault(c => new Coordinates(c.X, c.Y).Equals(new Coordinates(item.ObservationPoint.X, item.ObservationPoint.Y)));

            if (coordinate == null)
            {
                coordinate = new Models.Coordinates()
                {
                    X = item.ObservationPoint.X, Y = item.ObservationPoint.Y
                };
            }

            _dbContext.Set <EnergyObservations>().Add(new EnergyObservations()
            {
                Coordinate      = coordinate,
                EstimatedValue  = item.EstimatedValue,
                ObservationTime = item.ObservationTime
            });

            _dbContext.SaveChanges();

            //as we have navigation property in EnergyObservations points to coordinates, the last will be added in DB automaticly
        }
Esempio n. 2
0
        public static DbGeography getCircle(Models.Coordinates coords, double km)
        {
            string      textPoint    = String.Format("POINT ({0} {1})", coords.Lng, coords.Lat);
            DbGeography point        = DbGeography.PointFromText(textPoint, DbGeography.DefaultCoordinateSystemId); //4326 = [WGS84]
            DbGeography targetCircle = point.Buffer(km);

            return(targetCircle);
        }
Esempio n. 3
0
        public static Models.GenerateRowAndColumnResult GenerateRowAndColumn(Models.Coordinates coordinates)
        {
            int pixelMultiplier = int.Parse(WebConfigurationManager.AppSettings["pixelMultiplier"]);

            try
            {
                //
                // All we need to determine which triangle is being referenced is by (V1x,V1Y) and one of the other values
                // I'm choosing (V3x,V3y) because I'm going to need to confirm the lower Horizontal axis to determine the row
                //
                string row;
                int    column;

                //
                // Calculate the column, If V1y == V3y, then it's odd. Otherwise the column is even.
                //
                bool isOdd = coordinates.V1y == coordinates.V3y ? true : false;
                //
                // Make sure we are dealing with a right triangle
                //
                bool shouldProceed = ValidateRightTriangle(coordinates, isOdd);
                if (!shouldProceed)
                {
                    throw new ApplicationException();
                }

                if (isOdd)
                {
                    column = ((coordinates.V3x / pixelMultiplier) * 2) - 1;
                }
                else
                {
                    column = (coordinates.V3x / pixelMultiplier) * 2;
                }

                //
                // Calculate the row
                //
                row = CalculateRowFromCoordinate(coordinates.V3y);

                Models.GenerateRowAndColumnResult result = new Models.GenerateRowAndColumnResult()
                {
                    Column       = column,
                    Row          = row,
                    IsSuccessful = true
                };
                return(result);
            }
            catch (Exception ex)
            {
                // Don't do anything with the exception at this time, just return an error
                return(new Models.GenerateRowAndColumnResult()
                {
                    IsSuccessful = false
                });
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Location"/> class.
 /// </summary>
 /// <param name="id">id.</param>
 /// <param name="name">name.</param>
 /// <param name="address">address.</param>
 /// <param name="timezone">timezone.</param>
 /// <param name="capabilities">capabilities.</param>
 /// <param name="status">status.</param>
 /// <param name="createdAt">created_at.</param>
 /// <param name="merchantId">merchant_id.</param>
 /// <param name="country">country.</param>
 /// <param name="languageCode">language_code.</param>
 /// <param name="currency">currency.</param>
 /// <param name="phoneNumber">phone_number.</param>
 /// <param name="businessName">business_name.</param>
 /// <param name="type">type.</param>
 /// <param name="websiteUrl">website_url.</param>
 /// <param name="businessHours">business_hours.</param>
 /// <param name="businessEmail">business_email.</param>
 /// <param name="description">description.</param>
 /// <param name="twitterUsername">twitter_username.</param>
 /// <param name="instagramUsername">instagram_username.</param>
 /// <param name="facebookUrl">facebook_url.</param>
 /// <param name="coordinates">coordinates.</param>
 /// <param name="logoUrl">logo_url.</param>
 /// <param name="posBackgroundUrl">pos_background_url.</param>
 /// <param name="mcc">mcc.</param>
 /// <param name="fullFormatLogoUrl">full_format_logo_url.</param>
 public Location(
     string id                          = null,
     string name                        = null,
     Models.Address address             = null,
     string timezone                    = null,
     IList <string> capabilities        = null,
     string status                      = null,
     string createdAt                   = null,
     string merchantId                  = null,
     string country                     = null,
     string languageCode                = null,
     string currency                    = null,
     string phoneNumber                 = null,
     string businessName                = null,
     string type                        = null,
     string websiteUrl                  = null,
     Models.BusinessHours businessHours = null,
     string businessEmail               = null,
     string description                 = null,
     string twitterUsername             = null,
     string instagramUsername           = null,
     string facebookUrl                 = null,
     Models.Coordinates coordinates     = null,
     string logoUrl                     = null,
     string posBackgroundUrl            = null,
     string mcc                         = null,
     string fullFormatLogoUrl           = null)
 {
     this.Id                = id;
     this.Name              = name;
     this.Address           = address;
     this.Timezone          = timezone;
     this.Capabilities      = capabilities;
     this.Status            = status;
     this.CreatedAt         = createdAt;
     this.MerchantId        = merchantId;
     this.Country           = country;
     this.LanguageCode      = languageCode;
     this.Currency          = currency;
     this.PhoneNumber       = phoneNumber;
     this.BusinessName      = businessName;
     this.Type              = type;
     this.WebsiteUrl        = websiteUrl;
     this.BusinessHours     = businessHours;
     this.BusinessEmail     = businessEmail;
     this.Description       = description;
     this.TwitterUsername   = twitterUsername;
     this.InstagramUsername = instagramUsername;
     this.FacebookUrl       = facebookUrl;
     this.Coordinates       = coordinates;
     this.LogoUrl           = logoUrl;
     this.PosBackgroundUrl  = posBackgroundUrl;
     this.Mcc               = mcc;
     this.FullFormatLogoUrl = fullFormatLogoUrl;
 }
Esempio n. 5
0
 public Location(string id                          = null,
                 string name                        = null,
                 Models.Address address             = null,
                 string timezone                    = null,
                 IList <string> capabilities        = null,
                 string status                      = null,
                 string createdAt                   = null,
                 string merchantId                  = null,
                 string country                     = null,
                 string languageCode                = null,
                 string currency                    = null,
                 string phoneNumber                 = null,
                 string businessName                = null,
                 string type                        = null,
                 string websiteUrl                  = null,
                 Models.BusinessHours businessHours = null,
                 string businessEmail               = null,
                 string description                 = null,
                 string twitterUsername             = null,
                 string instagramUsername           = null,
                 string facebookUrl                 = null,
                 Models.Coordinates coordinates     = null,
                 string logoUrl                     = null,
                 string posBackgroundUrl            = null,
                 string mcc                         = null,
                 string fullFormatLogoUrl           = null)
 {
     Id                = id;
     Name              = name;
     Address           = address;
     Timezone          = timezone;
     Capabilities      = capabilities;
     Status            = status;
     CreatedAt         = createdAt;
     MerchantId        = merchantId;
     Country           = country;
     LanguageCode      = languageCode;
     Currency          = currency;
     PhoneNumber       = phoneNumber;
     BusinessName      = businessName;
     Type              = type;
     WebsiteUrl        = websiteUrl;
     BusinessHours     = businessHours;
     BusinessEmail     = businessEmail;
     Description       = description;
     TwitterUsername   = twitterUsername;
     InstagramUsername = instagramUsername;
     FacebookUrl       = facebookUrl;
     Coordinates       = coordinates;
     LogoUrl           = logoUrl;
     PosBackgroundUrl  = posBackgroundUrl;
     Mcc               = mcc;
     FullFormatLogoUrl = fullFormatLogoUrl;
 }
        public async Task <ActionResult> Surveys(Models.Coordinates coords)
        {
            using (var ctx = new Service.SurveyContext())
            {
                var survey = await ctx.GetSurveysAsync(coords);

                //var bodystring = RenderViewToString(this.ControllerContext, "_SurveyList", survey);
                //return Json(new { surveys = survey, body = bodystring },JsonRequestBehavior.AllowGet);
                return(PartialView("_SurveyList", survey));
            }
        }
 public ActionResult Create(string surveyQuestion, Models.Coordinates coords, int durationMinutes = 5, double distanceKm = 2)
 {
     using (var ctx = new Service.SurveyContext())
     {
         ctx.Surveys.Add(new Models.Survey()
         {
             AddDate        = DateTime.UtcNow,
             SurveyQuestion = surveyQuestion,
             ExpiritionDate = DateTime.UtcNow.AddMinutes(durationMinutes),
             Location       = Helper.Geo.getCircle(coords, distanceKm)
         });
         var t = ctx.SaveChanges();
         // ping
         var hubContext = GlobalHost.ConnectionManager.GetHubContext <Hubs.SurveyHub>();
         hubContext.Clients.Group("All").checkForNewSurveys();
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 8
0
        private static bool ValidateRightTriangle(Models.Coordinates coordinates, bool isOdd)
        {
            //
            // Use pythagorean theorem to determine if the triangle is a right triangle
            //
            double side1;
            double side2;
            double pixelMultiplier         = double.Parse(WebConfigurationManager.AppSettings["pixelMultiplier"]);
            double correctSquaredHypotenus = (pixelMultiplier * pixelMultiplier) + (pixelMultiplier * pixelMultiplier);

            if (isOdd)
            {
                side1 = Math.Abs(coordinates.V3x - coordinates.V1x);
                side2 = Math.Abs(coordinates.V1y - coordinates.V2y);
            }
            else
            {
                side1 = Math.Abs(coordinates.V1x - coordinates.V2x);
                side2 = Math.Abs(coordinates.V3y - coordinates.V1y);
            }

            //
            // Validate all sides are divisible by the multiplier
            //
            if (side1 != pixelMultiplier || side2 != pixelMultiplier)
            {
                return(false);
            }

            // Confirm right triangle
            if ((side1 * side1 + side2 * side2) <= correctSquaredHypotenus)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 9
0
 public Builder Coordinates(Models.Coordinates value)
 {
     coordinates = value;
     return(this);
 }
Esempio n. 10
0
 // POST api/values
 public Models.GenerateRowAndColumnResult Post(Models.Coordinates coordinates)
 {
     Models.GenerateRowAndColumnResult result = Repositories.TriangleRepository.GenerateRowAndColumn(coordinates);
     return(result);
 }
Esempio n. 11
0
 // GET api/values/Triangle
 public Models.Coordinates Get(string t)
 {
     Models.Coordinates coordinates = Repositories.TriangleRepository.GenerateCoordinates(t);
     return(coordinates);
 }
Esempio n. 12
0
 public Builder Coordinates(Models.Coordinates coordinates)
 {
     this.coordinates = coordinates;
     return(this);
 }
 public Task <List <Survey> > GetSurveysAsync(Models.Coordinates coords)
 {
     return(Database.SqlQuery <Survey>("dbo.usp_surveys_get_by_lat_lng @lat, @lng", new SqlParameter("lat", coords.Lat), new SqlParameter("lng", coords.Lng)).ToListAsync());
 }
Esempio n. 14
0
 public static Coordinates ToDomainEntity(this Models.Coordinates coordinates)
 {
     return(new Coordinates(coordinates.Id, coordinates.X, coordinates.Y));
 }
Esempio n. 15
0
        // Generate the coordinates based on a string location of the triangle
        public static Models.Coordinates GenerateCoordinates(string triangle)
        {
            int pixelMultiplier = int.Parse(WebConfigurationManager.AppSettings["pixelMultiplier"]);

            try
            {
                Models.Coordinates coordinates = new Models.Coordinates();

                //
                // Parse the inbound triangle row (A-F) to determine its vertical boundaries
                //
                string row = triangle.Substring(0, 1);
                int    verticalLowerBoundary = CharacterIntCalculator(row);
                int    verticalUpperBoundary = verticalLowerBoundary - pixelMultiplier;

                //
                // Use the column to determine the horizontal boundaries
                //
                int columnNumber       = 0;
                int actualColumnNumber = 0;
                int.TryParse(triangle.Substring(1), out columnNumber);
                int horizontalRightBoundary = 0;
                int horizontalLeftBoundary  = 0;

                //
                // Since the triangles are mirroed at the hypotenus, V1x and V1y depend on whether the column is even or odd
                //
                if (columnNumber > 0 && columnNumber % 2 == 0) //even
                {
                    actualColumnNumber      = columnNumber / 2;
                    horizontalRightBoundary = actualColumnNumber * pixelMultiplier;
                    horizontalLeftBoundary  = horizontalRightBoundary - pixelMultiplier;

                    coordinates.V1x = horizontalRightBoundary;
                    coordinates.V1y = verticalUpperBoundary;
                }
                else //odd, hopefully
                {
                    actualColumnNumber      = (columnNumber + 1) / 2;
                    horizontalRightBoundary = actualColumnNumber * pixelMultiplier;
                    horizontalLeftBoundary  = horizontalRightBoundary - pixelMultiplier;

                    coordinates.V1x = horizontalLeftBoundary;
                    coordinates.V1y = verticalLowerBoundary;
                }

                //
                // Set model values
                //
                coordinates.V2x = horizontalLeftBoundary;
                coordinates.V3x = horizontalRightBoundary;
                coordinates.V2y = verticalUpperBoundary;
                coordinates.V3y = verticalLowerBoundary;

                return(coordinates);
            }
            catch (Exception ex)
            {
                // Don't do anything with the exception at this time - normally I would wrap my return object in a RepositoryResult object and return
                // a failed status message but I'll just return an empty object instead.
                return(new Models.Coordinates());
            }
        }