Example #1
0
        public async Task SuggestionAnalysis(LogControl logControl, TilerElements.Location requestLocation)
        {
            if (logControl.Now == null)
            {
                logControl.Now = new ReferenceNow(DateTimeOffset.UtcNow, logControl.getTilerRetrievedUser().EndfOfDay, logControl.getTilerRetrievedUser().TimeZoneDifference);
            }
            else
            {
                logControl.Now = new ReferenceNow(logControl.Now.constNow, logControl.getTilerRetrievedUser().EndfOfDay, logControl.getTilerRetrievedUser().TimeZoneDifference);
            }
            DateTimeOffset nowTime  = logControl.Now.constNow;
            TimeLine       timeline = new TimeLine(logControl.Now.constNow.AddDays(-45), logControl.Now.constNow.AddDays(45));
            List <IndexedThirdPartyAuthentication> AllIndexedThirdParty = await ScheduleController.getAllThirdPartyAuthentication(logControl.LoggedUserID, db).ConfigureAwait(false);

            List <GoogleTilerEventControl> AllGoogleTilerEvents = AllIndexedThirdParty.Select(obj => new GoogleTilerEventControl(obj, db)).ToList();
            var tupleOfSUbEVentsAndAnalysis = await logControl.getSubCalendarEventForAnalysis(timeline, logControl.getTilerRetrievedUser()).ConfigureAwait(false);

            List <SubCalendarEvent> subEvents = tupleOfSUbEVentsAndAnalysis.Item1.ToList();
            Analysis analysis = tupleOfSUbEVentsAndAnalysis.Item2;
            Task <ConcurrentBag <CalendarEvent> > GoogleCalEventsTask = GoogleTilerEventControl.getAllCalEvents(AllGoogleTilerEvents, timeline);
            IEnumerable <CalendarEvent>           GoogleCalEvents     = await GoogleCalEventsTask.ConfigureAwait(false);

            subEvents.AddRange(GoogleCalEvents.SelectMany(o => o.AllSubEvents));

            foreach (CalendarEvent calEvent in  new HashSet <CalendarEvent> (subEvents.Select(o => o.ParentCalendarEvent)))
            {
                calEvent.backUpAndresetDeadlineSuggestions();
                calEvent.resetSleepDeadlineSuggestion();
            }

            ScheduleSuggestionsAnalysis scheduleSuggestion = new ScheduleSuggestionsAnalysis(subEvents, logControl.Now, logControl.getTilerRetrievedUser(), analysis);
            var overoccupiedTimelines = scheduleSuggestion.getOverLoadedWeeklyTimelines(nowTime, scheduleSuggestion.getActiveRatio());
            var suggestion            = scheduleSuggestion.suggestScheduleChange(overoccupiedTimelines, scheduleSuggestion.getActiveRatio());

            suggestion.updateDeadlineSuggestions();


            var overoccupiedSleepTimelines = scheduleSuggestion.getOverLoadedWeeklyTimelines(nowTime, scheduleSuggestion.getSleepRatio());
            var sleepSuggestionDeadlines   = scheduleSuggestion.suggestScheduleChange(overoccupiedSleepTimelines, scheduleSuggestion.getSleepRatio());

            foreach (KeyValuePair <CalendarEvent, TimeLine> kvp in sleepSuggestionDeadlines.DeadlineUpdates)
            {
                kvp.Key.updateSleepDeadlineSuggestion(kvp.Value.End);
            }
            List <CalendarEvent> calEvents = new HashSet <CalendarEvent>(subEvents.Select(o => o.ParentCalendarEvent)).ToList();
            await logControl.Commit(calEvents, null, "0", logControl.Now, null, requestLocation);
        }