Ejemplo n.º 1
0
        public ProfileAggregate(Guid id, User user, Guid chartId, string name, Track track, IDateTimeProvider datetime, IPlaceFinder placeFinder, IElevationService elevationService)
            : this()
        {
            if (!track.HasElevation())
            {
                elevationService.ImportElevationTo(track);
            }

            var profilePlaces = CreateProfilePlaces(user.Id, track, placeFinder);
            var result        = CreateResult(user, track, profilePlaces);
            var legs          = CreateLegs(track, profilePlaces);

            var data = new TrackAnalyzer().Analyze(track);

            RaiseEvent(new ProfileCreated(id, user.Id, chartId, name, datetime.Now, track, data.Ascending, data.Descending, data.HighestPoint, data.LowestPoint, data.Climbs, profilePlaces, legs, result));
        }
Ejemplo n.º 2
0
        public void Handle(ProfileCreated evt)
        {
            var user = _db.GetById <UserView>(evt.UserId);

            var nrOfProfiles    = user.NrOfProfiles + 1;
            var distance        = user.Distance;
            var ascending       = user.Ascending;
            var descending      = user.Descending;
            var highestAltitude = user.HighestAltitude;
            var lowestAltitude  = user.LowestAltitude;
            var nrOfClimbs      = user.NrOfClimbs;
            var climbPoints     = user.ClimbPoints;
            var timeSeconds     = user.TimeSeconds;

            if (evt.HighestPoint == null && evt.LowestPoint == null && evt.Track != null)
            {
                var trackData = new TrackAnalyzer().Analyze(evt.Track);

                distance   += evt.Track.Length;
                ascending  += trackData.Ascending;
                descending += trackData.Descending;

                if (trackData.HighestPoint != null)
                {
                    highestAltitude = Math.Max(user.HighestAltitude, trackData.HighestPoint.Altitude);
                }


                if (trackData.LowestPoint != null)
                {
                    lowestAltitude = Math.Min(user.LowestAltitude, trackData.LowestPoint.Altitude);
                }

                if (trackData.Climbs != null)
                {
                    nrOfClimbs += trackData.Climbs.Length;
                }


                if (trackData.Climbs != null)
                {
                    foreach (var climb in trackData.Climbs)
                    {
                        climbPoints += (int)climb.Points;
                    }
                }
            }
            else
            {
                distance   += evt.Track.Length;
                ascending  += evt.Ascending;
                descending += evt.Descending;

                if (evt.HighestPoint != null)
                {
                    highestAltitude = Math.Max(user.HighestAltitude, evt.HighestPoint.Altitude);
                }

                if (evt.LowestPoint != null)
                {
                    lowestAltitude = Math.Min(user.LowestAltitude, evt.LowestPoint.Altitude);
                }

                if (evt.Climbs != null)
                {
                    nrOfClimbs += evt.Climbs.Length;
                }


                if (evt.Climbs != null)
                {
                    foreach (var climb in evt.Climbs)
                    {
                        climbPoints += (int)climb.Points;
                    }
                }
            }

            if (evt.Result != null)
            {
                timeSeconds += evt.Result.TotalTimeSeconds;
            }

            _db.Update <UserView>(new { NrOfProfiles = nrOfProfiles, Distance = distance, Ascending = ascending, Descending = descending, HighestAltitude = highestAltitude, LowestAltitude = lowestAltitude, NrOfClimbs = nrOfClimbs, ClimbPoints = climbPoints, TimeSeconds = timeSeconds }, p => p.Id == evt.UserId);
        }