Esempio n. 1
0
        public void Build(List <PhotoSession> photoSessions)
        {
            Candidates.Clear();
            Sessions = photoSessions;
            ComputeSessionsScores();

            var rankedSessions = Sessions.OrderByDescending(s => s.Score).ToList();

            while (rankedSessions.Any())
            {
                var mainSession    = rankedSessions.First();
                var nearbySessions = rankedSessions
                                     .Skip(1)
                                     .Where(s => IsNear(mainSession.Location, s.Location)).ToList();

                var newCandidate = new DestinationCandidate(mainSession);

                if (nearbySessions.Count() > 0)
                {
                    newCandidate.Add(nearbySessions.ToList());
                }


                Candidates.Add(newCandidate);
                rankedSessions = rankedSessions
                                 .Skip(1)
                                 .Where(s => !nearbySessions.Contains(s)).ToList();
            }

            // Merge();
            Candidates = Candidates.OrderByDescending(l => l.TotalScore).ToList();

            // fill in the destination  from the session locations
            foreach (var candidate in Candidates)
            {
                var childLocation = candidate.Sessions.Select(s => s.Location).ToList();

                candidate.Location    = _locationService.DetectParentLocation(childLocation);
                candidate.DisplayName = candidate?.Location.DisplayName ?? "Unknown";

                Debug.Assert(candidate.Location != null);
            }
        }
Esempio n. 2
0
        private Location DetectParentLocation(TripCandidate tripCandidate)
        {
            var childLocations = tripCandidate.Destinations.Select(d => d.Location).ToList();

            return(_locationService.DetectParentLocation(childLocations));
        }