コード例 #1
0
ファイル: Schedule.cs プロジェクト: jerbio/WagTapWeb
        KeyValuePair<CalendarEvent, TimeLine> EvaluateEachSnugPossibiliyOfSnugPossibility(List<List<List<SubCalendarEvent>>> SnugPossibilityPermutation, TimeLine ReferenceTimeLine, CalendarEvent ReferenceCalendarEvent)
        {
            TimeLine CopyOfReferenceTimeLine;
            List<TimeLine> SnugPossibilityTimeLine = new System.Collections.Generic.List<TimeLine>();
            Dictionary<BusyTimeLine, SubCalendarEvent> MyBusyTimeLineToSubCalendarEventDict = new System.Collections.Generic.Dictionary<BusyTimeLine, SubCalendarEvent>();

            Dictionary<CalendarEvent, TimeLine> CalendarEvent_EvaluationIndexDict = new System.Collections.Generic.Dictionary<CalendarEvent, TimeLine>();

            foreach (List<List<SubCalendarEvent>> SnugPermutation in SnugPossibilityPermutation)//goes each permutation of snug possibility generated
            {
                List<SubCalendarEvent> AllSubEvents = new System.Collections.Generic.List<SubCalendarEvent>();

                foreach (List<SubCalendarEvent> eachList in SnugPermutation)
                {
                    AllSubEvents.AddRange(eachList);
                    foreach (SubCalendarEvent eachSubCalendarEvent in eachList)
                    {
                        ReferenceCalendarEvent.updateSubEvent(eachSubCalendarEvent.SubEvent_ID, eachSubCalendarEvent);
                        /*if (SubEvent != null)
                        {
                            SubEvent.updateSubEvent(SubEvent.SubEvent_ID, eachSubCalendarEvent);
                        }*/
                    }

                }

                ReferenceTimeLine = Utility.AddSubCaleventsToTimeLine(ReferenceTimeLine, AllSubEvents);
                CalendarEvent_EvaluationIndexDict.Add(ReferenceCalendarEvent, ReferenceTimeLine);

                /*
                CopyOfReferenceTimeLine = ReferenceTimeLine.CreateCopy();
                //SnugPossibilityTimeLine.Add(CopyOfReferenceTimeLine);
                List<TimeLine> ListOfFreeSpots=getOnlyPertinentTimeFrame(getAllFreeSpots_NoCompleteSchedule(CopyOfReferenceTimeLine), CopyOfReferenceTimeLine);
                List<SubCalendarEvent> ReassignedSubEvents = new System.Collections.Generic.List<SubCalendarEvent>();
                for (int i=0; i<ListOfFreeSpots.Count;i++)
                {
                    DateTime RelativeStartTime = ListOfFreeSpots[i].Start;

                    TimeLine UpdatedTimeLine=Utility.AddSubCaleventsToTimeLine(ListOfFreeSpots[i], SnugPermutation[i]);
                    ListOfFreeSpots[i].AddBusySlots(UpdatedTimeLine.OccupiedSlots);
                    
                    foreach (SubCalendarEvent MySubCalendarEvent in SnugPermutation[i])
                    {//tries to reassign each element in a snug permutation into the referencetimeLine
                        SubCalendarEvent CopyOfMySubCalendarEvent = MySubCalendarEvent.createCopy();
                        TimeSpan MySubCalendarDuration = (CopyOfMySubCalendarEvent.End - CopyOfMySubCalendarEvent.Start);
                        DateTime RelativeEndtime = RelativeStartTime + MySubCalendarDuration;
                        CopyOfMySubCalendarEvent.ReassignTime(RelativeStartTime, RelativeEndtime);
                        CopyOfMySubCalendarEvent.ActiveSlot = new BusyTimeLine(CopyOfMySubCalendarEvent.ID, RelativeStartTime, RelativeEndtime);//Note this is a hack to resolve the reassignment of time since we dont know currently know the distiction between BusyTimeLine and SubCalendarEvent(TimeLine)
                        TimeLine MyTimeLine=CopyOfMySubCalendarEvent.EventTimeLine;
                        CopyOfReferenceTimeLine.MergeTimeLines(MyTimeLine);
                        RelativeStartTime = CopyOfMySubCalendarEvent.End;
                        MyBusyTimeLineToSubCalendarEventDict.Add(CopyOfMySubCalendarEvent.ActiveSlot, CopyOfMySubCalendarEvent);
                    }
                }
                SnugPossibilityTimeLine.Add(CopyOfReferenceTimeLine);*/
            }

            Dictionary<string, double> DictionaryGraph = new System.Collections.Generic.Dictionary<string, double>();

            /*
            foreach (TimeLine MyTimeLine in SnugPossibilityTimeLine)
            {
                
                CalendarEvent MyEventCopy=ReferenceCalendarEvent.createCopy();
                
                foreach (BusyTimeLine MyBusyPeriod in MyTimeLine.OccupiedSlots)
                {
                    EventID MyEventID = new EventID(MyBusyPeriod.TimeLineID);
                    string ParentCalendarEventID = MyEventID.getLevelID(0);
                    if (MyEventCopy.ID == ParentCalendarEventID)
                    {

                        SubCalendarEvent MySubCalendarEvent=MyBusyTimeLineToSubCalendarEventDict[MyBusyPeriod];
                        for (int i = 0; i < MyEventCopy.AllEvents.Length; i++)
                        {
                            if (MyEventCopy.AllEvents[i].ID == MySubCalendarEvent.ID)
                            {
                                MyEventCopy.AllEvents[i] = MySubCalendarEvent;
                                break;
                            }
                        }
                        
                    }
                }
                
                //MyEventCopy=EvaluateTotalTimeLineAndAssignValidTimeSpotsWithReferenceTimeLine(MyEventCopy, MyTimeLine);

                
            }*/

            double HighestValue = 0;

            KeyValuePair<CalendarEvent, TimeLine> FinalSuggestion = new System.Collections.Generic.KeyValuePair<CalendarEvent, TimeLine>(CalendarEvent_EvaluationIndexDict.Keys.ToList()[0], CalendarEvent_EvaluationIndexDict.Values.ToList()[0]);

            /*TimeLine TimeLineUpdated = null;
            Dictionary<string, double> LocationVector = new System.Collections.Generic.Dictionary<string,double>();
            LocationVector.Add("sameElement", 10000000000);


            foreach (KeyValuePair<CalendarEvent, TimeLine> MyCalendarEvent_TimeLine in CalendarEvent_EvaluationIndexDict)
            {
                int RandomIndex = EvaluateRandomNetIndex(MyCalendarEvent_TimeLine.Value);
                RandomIndex = 0;
                LocationVector=BuildDictionaryDistanceEdge(MyCalendarEvent_TimeLine.Value, MyCalendarEvent_TimeLine.Key, LocationVector);
                double ClumpIndex = EvaluateClumpingIndex(MyCalendarEvent_TimeLine.Value, LocationVector);
                ClumpIndex = 1 / ClumpIndex;
                double EvaluationSum = ClumpIndex + RandomIndex;
                if (EvaluationSum < 0)
                {
                    EvaluationSum *= -1;
                }

                if ( EvaluationSum > HighestValue)
                {
                    HighestValue = EvaluationSum;
                    FinalSuggestion = MyCalendarEvent_TimeLine;
                }
            }

            if (FinalSuggestion.Equals(new KeyValuePair<CalendarEvent,TimeLine>()))
            {
                MessageBox.Show("Oh oh J, you'll need to look outside this range...Think of moving other events out of white box space");
            }
            */
            return FinalSuggestion;
        }
コード例 #2
0
ファイル: Schedule.cs プロジェクト: jerbio/My24HourTimerWPF
        public CalendarEvent EvaluateTotalTimeLineAndAssignValidTimeSpots(CalendarEvent MyEvent,HashSet<SubCalendarEvent> UnDoneEvents, List<CalendarEvent> NoneCOmmitedCalendarEvent = null, int InterringWithNowEvent=0)
        {
            int i = 0;
            if (NoneCOmmitedCalendarEvent == null)
            {
                NoneCOmmitedCalendarEvent = new List<CalendarEvent>();
            }
            if (MyEvent.RepetitionStatus)
            {
                for (i = 0; i < MyEvent.Repeat.RecurringCalendarEvents.Length; i++)
                {
                    MyEvent.Repeat.RecurringCalendarEvents[i] = EvaluateTotalTimeLineAndAssignValidTimeSpots(MyEvent.Repeat.RecurringCalendarEvents[i], UnDoneEvents, NoneCOmmitedCalendarEvent);
                    NoneCOmmitedCalendarEvent.Add(MyEvent.Repeat.RecurringCalendarEvents[i]);
                    if (MyEvent.Repeat.RecurringCalendarEvents[i].ErrorStatus)
                    {
                        MyEvent.UpdateError(MyEvent.Repeat.RecurringCalendarEvents[i].Error);
                    }
                }
                return MyEvent;
            }

            BusyTimeLine[] AllOccupiedSlot = CompleteSchedule.OccupiedSlots;
            TimeSpan TotalActiveDuration = new TimeSpan();
            TimeLine[] TimeLineArrayWithSubEventsAssigned = new TimeLine[MyEvent.ActiveSubEvents.Length];
            SubCalendarEvent TempSubEvent = new SubCalendarEvent();
            BusyTimeLine MyTempBusyTimerLine = new BusyTimeLine();
            List<TimeLine> FreeSpotsAvailableWithinValidTimeline = getAllFreeSpots(new TimeLine(MyEvent.Start, MyEvent.End)).ToList();

            FreeSpotsAvailableWithinValidTimeline = CheckTimeLineListForEncompassingTimeLine(FreeSpotsAvailableWithinValidTimeline, MyEvent.RangeTimeLine);

            FreeSpotsAvailableWithinValidTimeline = getOnlyPertinentTimeFrame(FreeSpotsAvailableWithinValidTimeline.ToArray(), new TimeLine(MyEvent.Start, MyEvent.End));

            i = 0;
            TimeSpan TotalFreeTimeAvailable = new TimeSpan();
            if (MyEvent.Rigid)
            {
                TempSubEvent = new SubCalendarEvent(MyEvent.ActiveDuration, MyEvent.Start, MyEvent.End, MyEvent.Preparation, MyEvent.ID, MyEvent.Rigid, MyEvent.isEnabled, MyEvent.UIParam, MyEvent.Notes, MyEvent.isComplete, MyEvent.myLocation, MyEvent.RangeTimeLine);
                MyTempBusyTimerLine = new BusyTimeLine(TempSubEvent.ID, TempSubEvent.Start, TempSubEvent.End);
                TempSubEvent = new SubCalendarEvent(TempSubEvent.ID, TempSubEvent.Start, TempSubEvent.End, MyTempBusyTimerLine, MyEvent.Rigid, TempSubEvent.isEnabled, TempSubEvent.UIParam, TempSubEvent.Notes, TempSubEvent.isComplete, MyEvent.myLocation, MyEvent.RangeTimeLine);
                MyEvent.updateSubEvent(TempSubEvent.SubEvent_ID, TempSubEvent);


                KeyValuePair<CalendarEvent, TimeLine> TimeLineAndCalendarUpdated = ReArrangeClashingEventsofRigid(MyEvent, NoneCOmmitedCalendarEvent.ToList(), InterringWithNowEvent);

                CalendarEvent MyCalendarEventUpdated = TimeLineAndCalendarUpdated.Key;

                if (MyCalendarEventUpdated != null && !MyCalendarEventUpdated.ErrorStatus)
                {
                    string MyEventParentID = (new EventID(MyEvent.ID)).getLevelID(0);
                    foreach (BusyTimeLine MyBusyTimeLine in TimeLineAndCalendarUpdated.Value.OccupiedSlots)
                    {
                        string ParentID = (new EventID(MyBusyTimeLine.TimeLineID)).getLevelID(0);
                        if (ParentID != MyEventParentID)
                        {
                            SubCalendarEvent[] MyArrayOfSubCalendarEvents;
                            if (AllEventDictionary[ParentID].RepetitionStatus)
                            {
                                //bool Verified = AllEventDictionary[ParentID].updateSubEvent(new EventID(MyBusyTimeLine.TimeLineID), new SubCalendarEvent(MyBusyTimeLine.TimeLineID, MyBusyTimeLine.Start, MyBusyTimeLine.End, MyBusyTimeLine, AllEventDictionary[ParentID].Rigid, AllEventDictionary[ParentID].myLocation));
                                SubCalendarEvent referenceSubCalEvent = AllEventDictionary[ParentID].getSubEvent(new EventID(MyBusyTimeLine.TimeLineID));
                                referenceSubCalEvent.shiftEvent(MyBusyTimeLine.Start - referenceSubCalEvent.Start);
                            }
                            else
                            {
                                MyArrayOfSubCalendarEvents = AllEventDictionary[ParentID].AllSubEvents;
                                for (i = 0; i < MyArrayOfSubCalendarEvents.Length; i++)
                                {
                                    if (MyArrayOfSubCalendarEvents[i].ID == MyBusyTimeLine.TimeLineID)
                                    {
                                        //string ThirdPartyID = MyArrayOfSubCalendarEvents[i].ThirdPartyID;
                                        //SubCalendarEvent newSubCalevent = new SubCalendarEvent(MyBusyTimeLine.TimeLineID, MyBusyTimeLine.Start, MyBusyTimeLine.End, MyBusyTimeLine, MyArrayOfSubCalendarEvents[i].Rigid, MyArrayOfSubCalendarEvents[i].myLocation, AllEventDictionary[ParentID].RangeTimeLine);
                                        //newSubCalevent.ThirdPartyID = ThirdPartyID;
                                        //AllEventDictionary[ParentID].updateSubEvent(newSubCalevent.SubEvent_ID, newSubCalevent);
                                        SubCalendarEvent referenceSubCalEvent = MyArrayOfSubCalendarEvents[i];
                                        referenceSubCalEvent.shiftEvent(MyBusyTimeLine.Start - referenceSubCalEvent.Start);
                                        
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (MyCalendarEventUpdated == null)
                    {
                        MyCalendarEventUpdated = MyEvent;
                    }
                }

                return MyCalendarEventUpdated;
            }
            else
            {
                for (i = 0; i < FreeSpotsAvailableWithinValidTimeline.Count; i++)
                {
                    TotalFreeTimeAvailable += FreeSpotsAvailableWithinValidTimeline[i].TimelineSpan;
                }

                //if (TotalFreeTimeAvailable >= MyEvent.ActiveDuration)
                {
                    /*TimeLineArrayWithSubEventsAssigned = SplitFreeSpotsInToSubEventTimeSlots(FreeSpotsAvailableWithinValidTimeline.ToArray(), MyEvent.AllEvents.Length, MyEvent.ActiveDuration);
                    if (TimeLineArrayWithSubEventsAssigned == null)*/
                    {
                        BusyTimeLine[] CompleteScheduleOccupiedSlots = CompleteSchedule.OccupiedSlots;
                        KeyValuePair<CalendarEvent, TimeLine> TimeLineAndCalendarUpdated = ReArrangeTimeLineWithinWithinCalendaEventRange(MyEvent, NoneCOmmitedCalendarEvent.ToList(), InterringWithNowEvent, UnDoneEvents);
                        CalendarEvent MyCalendarEventUpdated = TimeLineAndCalendarUpdated.Key;
                        //CompleteSchedule.OccupiedSlots = TimeLineAndCalendarUpdated.Value.OccupiedSlots;//hack need to review architecture to avoid this assignment
                        if (MyCalendarEventUpdated != null)// && !MyCalendarEventUpdated.ErrorStatus)
                        {
                            string MyEventParentID = (new EventID(MyEvent.ID)).getLevelID(0);
                            foreach (BusyTimeLine MyBusyTimeLine in TimeLineAndCalendarUpdated.Value.OccupiedSlots)
                            {
                                string ParentID = (new EventID(MyBusyTimeLine.TimeLineID)).getLevelID(0);
                                if (ParentID != MyEventParentID)
                                {
                                    SubCalendarEvent[] MyArrayOfSubCalendarEvents;
                                    if (AllEventDictionary[ParentID].RepetitionStatus)
                                    {
                                        //bool Verified = AllEventDictionary[ParentID].updateSubEvent(new EventID(MyBusyTimeLine.TimeLineID), new SubCalendarEvent(MyBusyTimeLine.TimeLineID, MyBusyTimeLine.Start, MyBusyTimeLine.End, MyBusyTimeLine, AllEventDictionary[ParentID].Rigid, AllEventDictionary[ParentID].myLocation));
                                        SubCalendarEvent referenceSubCalEvent = AllEventDictionary[ParentID].getSubEvent(new EventID(MyBusyTimeLine.TimeLineID));
                                        referenceSubCalEvent.shiftEvent(MyBusyTimeLine.Start - referenceSubCalEvent.Start);
                                    }
                                    else
                                    {
                                        MyArrayOfSubCalendarEvents = AllEventDictionary[ParentID].ActiveSubEvents;
                                        for (i = 0; i < MyArrayOfSubCalendarEvents.Length; i++)
                                        {
                                            if (MyArrayOfSubCalendarEvents[i] != null)//for procrastinate scenario where subcalevents get removed
                                            {
                                                if (MyArrayOfSubCalendarEvents[i].ID == MyBusyTimeLine.TimeLineID)
                                                {
                                                    /*string ThirdPartyID = MyArrayOfSubCalendarEvents[i].ThirdPartyID;
                                                    SubCalendarEvent newSubCalevent = new SubCalendarEvent(MyBusyTimeLine.TimeLineID, MyBusyTimeLine.Start, MyBusyTimeLine.End, MyBusyTimeLine, MyArrayOfSubCalendarEvents[i].Rigid, MyArrayOfSubCalendarEvents[i].myLocation, AllEventDictionary[ParentID].RangeTimeLine);
                                                    newSubCalevent.ThirdPartyID = ThirdPartyID;
                                                    AllEventDictionary[ParentID].updateSubEvent(newSubCalevent.SubEvent_ID, newSubCalevent);*/



                                                    SubCalendarEvent referenceSubCalEvent = MyArrayOfSubCalendarEvents[i];
                                                    referenceSubCalEvent.shiftEvent(MyBusyTimeLine.Start - referenceSubCalEvent.Start);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            /*if (MyCalendarEventUpdated.RepetitionStatus)
                            {
                                for (i = 0; i < MyEvent.Repeat.RecurringCalendarEvents.Length; i++)
                                {
                                    MyCalendarEventUpdated.Repeat.RecurringCalendarEvents[i] = EvaluateTotalTimeLineAndAssignValidTimeSpots(MyEvent.Repeat.RecurringCalendarEvents[i]);
                                }
                            }*/


                            return MyCalendarEventUpdated;
                        }
                        else
                        {
                            throw new Exception("code generated a null calendar event. THis is weird");
                        }
                    }
                }
                /*else
                {
                    //MessageBox.Show("Sorry, the total free time available during activiy limits is less than your active duration!!!");
                    List<CalendarEvent> ListOfCalendarEventsWithLatterDeadlines = new System.Collections.Generic.List<CalendarEvent>();
                    return new CalendarEvent(new CustomErrors(true, "There isnt enough time in for the time space"));
                }
                */
                /*if (TimeLineArrayWithSubEventsAssigned.Length < MyEvent.AllSubEvents.Length)// This means the assigned time per subevent spots won't be sufficient for the subevents available to the calendar event
                {
                    return null;
                }

                i = 0;
                for (; i < MyEvent.AllActiveSubEvents.Length; i++)
                {
                    TempSubEvent = new SubCalendarEvent(TimeLineArrayWithSubEventsAssigned[i].TimelineSpan, TimeLineArrayWithSubEventsAssigned[i].Start, TimeLineArrayWithSubEventsAssigned[i].End, MyEvent.Preparation, MyEvent.ID, MyEvent.Rigid, MyEvent.myLocation, MyEvent.RangeTimeLine);
                    MyTempBusyTimerLine = new BusyTimeLine(TempSubEvent.ID, TimeLineArrayWithSubEventsAssigned[i].Start, TimeLineArrayWithSubEventsAssigned[i].End);
                    TempSubEvent = new SubCalendarEvent(TempSubEvent.ID, TimeLineArrayWithSubEventsAssigned[i].Start.Add(-MyEvent.Preparation), TimeLineArrayWithSubEventsAssigned[i].End, MyTempBusyTimerLine, MyEvent.Rigid, MyEvent.myLocation, MyEvent.RangeTimeLine);
                    MyEvent.updateSubEvent(TempSubEvent.SubEvent_ID, TempSubEvent);
                }
                 */
            }



            return MyEvent;
        }