コード例 #1
0
        private ProfilePlace[] CreateProfilePlaces(Guid userId, Track track, IPlaceFinder placeFinder)
        {
            var profilePlaces = new List <ProfilePlace>();

            var places = placeFinder.Find(track.Points, userId);

            foreach (var place in places)
            {
                var placePoints = FindPlacePoints(track.Points, place);

                foreach (var placePoint in placePoints)
                {
                    profilePlaces.Add(new ProfilePlace(place, placePoint, true, false));
                }
            }

            profilePlaces.Sort((x, y) => { return(x.Point.Distance.CompareTo(y.Point.Distance)); });

            ProfilePlace startProfilePlace  = null;
            ProfilePlace finishProfilePlace = null;

            var startPlace = placeFinder.FindClosest(track.FirstPoint, userId);

            if (startPlace != null)
            {
                profilePlaces.RemoveAll(pp => pp.Place.Id == startPlace.Id && pp.Point.Distance < 100);
                startProfilePlace = new ProfilePlace(startPlace, track.FirstPoint, true, true);
            }
            else
            {
                startProfilePlace = new ProfilePlace(new Place(Guid.NewGuid(), userId, "Start", "Local", track.FirstPoint, GeoPolygon.CreateRect(track.FirstPoint, 0.05)), track.FirstPoint, true, true);
            }


            var finishPlace = placeFinder.FindClosest(track.LastPoint, userId);

            if (finishPlace != null)
            {
                profilePlaces.RemoveAll(pp => pp.Place.Id == finishPlace.Id && pp.Point.Distance > track.Length - 100);
                finishProfilePlace = new ProfilePlace(finishPlace, track.LastPoint, true, true);
            }
            else
            {
                finishProfilePlace = new ProfilePlace(new Place(Guid.NewGuid(), userId, "Finish", "Local", track.LastPoint, GeoPolygon.CreateRect(track.LastPoint, 0.05)), track.LastPoint, true, true);
            }

            //var startProfilePlace = profilePlaces.FirstOrDefault(place => place.Point.Distance < 100);

            //if (startProfilePlace != null)
            //{
            //    startProfilePlace.Point.Distance = 0.0;
            //    startProfilePlace.Split = true; ;
            //}
            //else
            //    profilePlaces.Insert(0, new IProfilePlace(new Place(Guid.NewGuid(), userId, "Start", "Local", track.FirstPoint, GeoPolygon.CreateRect(track.FirstPoint, 0.05)), track.FirstPoint, true, true));

            //var finishPlace = profilePlaces.LastOrDefault(place => place.Point.Distance > (track.Length - 100));

            //if (finishPlace != null)
            //{
            //    finishPlace.Point.Distance = track.Length;
            //    finishPlace.Split = true;
            //}
            //else
            //    profilePlaces.Add(new IProfilePlace(new Place(Guid.NewGuid(), userId, "Finish", "Local", track.LastPoint, GeoPolygon.CreateRect(track.LastPoint, 0.05)), track.LastPoint, true, true));


            profilePlaces.Insert(0, startProfilePlace);
            profilePlaces.Add(finishProfilePlace);

            return(profilePlaces.ToArray());
        }
コード例 #2
0
        public void WhenCreatingProfile_ProfileShouldBeCreatedWithDefaultAttributes()
        {
            var id              = Guid.NewGuid();
            var userId          = Guid.NewGuid();
            var location        = new GeoLocation(63.0001, 15.0001, 123.5);
            var trackPoint      = new TrackPoint(location, 0.0, DateTime.Now);
            var track           = new Track(Guid.NewGuid(), new TrackPoint[] { trackPoint });
            var coffeeAttribute = new PlaceAttribute(PlaceAttributeType.Coffee, true);

            var place = new Place(Guid.NewGuid(), userId, "Test place", "", location, GeoPolygon.CreateRect(location, 0.05), coffeeAttribute);

            var legs = new Leg[] { new Leg(trackPoint, trackPoint, 0.0, 0.0) };

            var startSplit = new ResultSplit(trackPoint);
            var result     = new Result(new Athlete(userId, "IAthlete"), new ResultSplit[] { startSplit, new ResultSplit(trackPoint, startSplit, startSplit) });

            PlaceRepository.Add(place);

            var startProfilePlace  = new ProfilePlace(place, trackPoint, true, true, new ProfilePlaceAttribute(coffeeAttribute.Type, coffeeAttribute.DefaultValue));
            var finishProfilePlace = new ProfilePlace(place, trackPoint, true, true, new ProfilePlaceAttribute(coffeeAttribute.Type, coffeeAttribute.DefaultValue));

            When(new CreateProfile(id, userId, Guid.Empty, "First", track));
            Then(new ProfileCreated(id, userId, Guid.Empty, "First", DateTimeProvider.Now, track, 0.0, 0.0, trackPoint, trackPoint, null, new ProfilePlace[] { startProfilePlace, finishProfilePlace }, legs, result));
        }
コード例 #3
0
ファイル: AdminController.cs プロジェクト: Tylland/altidude
        private void ExtractPlaces(Feature feature, string @namespace, Dictionary <string, Place> places)
        {
            // Is the passed in value a Placemark?
            Placemark placemark = feature as Placemark;

            if (placemark != null)
            {
                var         name     = placemark.Name;
                var         fullName = @namespace + NamespaceSeparator + name;
                GeoLocation location = null;
                GeoPolygon  fence    = null;

                var point = placemark.Geometry as Point;

                if (point != null)
                {
                    location = new GeoLocation(point.Coordinate.Latitude, point.Coordinate.Longitude, (double)point.Coordinate.Altitude);
                    fence    = GeoPolygon.CreateRect(location, 0.05);

                    if (!places.ContainsKey(fullName))
                    {
                        places.Add(fullName, new Place(Guid.NewGuid(), UserId, placemark.Name, @namespace, location, fence, PlaceAttribute.CreateDefault()));
                    }
                    else
                    {
                        var place = places[fullName];
                        place.Location = location;
                    }
                }

                var polygon = placemark.Geometry as Polygon;

                if (polygon != null)
                {
                    var locations = polygon.OuterBoundary.LinearRing.Coordinates.Select(vector => new GeoLocation(vector.Latitude, vector.Longitude, (double)vector.Altitude));

                    fence = new GeoPolygon(locations.ToArray());

                    location = fence.Boudary.GetCenter();

                    if (!places.ContainsKey(fullName))
                    {
                        places.Add(fullName, new Place(Guid.NewGuid(), UserId, placemark.Name, @namespace, location, fence, null));
                    }
                    else
                    {
                        var place = places[fullName];
                        place.Polygon = fence;
                    }
                }
            }
            else
            {
                // Is it a Container, as the Container might have a child Placemark?
                Container container = feature as Container;
                if (container != null)
                {
                    var newNamespace = string.Empty;

                    if (!(container is Document))
                    {
                        if (@namespace != string.Empty)
                        {
                            newNamespace = @namespace + NamespaceSeparator + container.Name;
                        }
                        else
                        {
                            newNamespace = container.Name;
                        }
                    }
                    // Check each Feature to see if it's a Placemark or another Container
                    foreach (var f in container.Features)
                    {
                        ExtractPlaces(f, newNamespace, places);
                    }
                }
            }
        }
コード例 #4
0
        public void WhenCreatingProfile_ProfileShouldBeCreatedWithTwoPassedPlaces()
        {
            var id        = Guid.NewGuid();
            var userId    = Guid.NewGuid();
            var location1 = new GeoLocation(63.0001, 15.0001, 123.5);
            var location2 = new GeoLocation(63.0051, 15.051, 125);
            var location3 = new GeoLocation(63.0011, 15.0051, 123.5);

            var now         = new DateTime(2016, 08, 12);
            var trackPoint1 = new TrackPoint(location1, 0.0, now);
            var trackPoint2 = new TrackPoint(location2, 100.0, now.AddSeconds(10));
            var trackPoint3 = new TrackPoint(location3, 200.0, now.AddSeconds(20));

            var track = new Track(Guid.NewGuid(), new TrackPoint[] { trackPoint1, trackPoint2, trackPoint3 });
            var place = new Place(Guid.NewGuid(), userId, "Test place", "", location1, GeoPolygon.CreateRect(location1, 0.05));

            var legs = new Leg[] { new Leg(trackPoint1, trackPoint3, 1.5, 1.5) };

            var startSplit = new ResultSplit(trackPoint1);
            var result     = new Result(new Athlete(userId, "IAthlete"), new ResultSplit[] { startSplit, new ResultSplit(trackPoint3, startSplit, startSplit) });


            PlaceRepository.Add(place);

            When(new CreateProfile(id, userId, Guid.Empty, "First", track));
            Then(new ProfileCreated(id, userId, Guid.Empty, "First", DateTimeProvider.Now, track, 1.5, 1.5, trackPoint2, trackPoint1, null, new ProfilePlace[] { new ProfilePlace(place, trackPoint1, true, true), new ProfilePlace(place, trackPoint3, true, true) }, legs, result));
        }