/// <summary> /// Creates the personal contour from TimePhased data list. /// </summary> /// <param name="obj">The obj.</param> /// <returns></returns> PersonalContour IFactoryMethod <PersonalContour> .Create(object obj) { PersonalContour retVal = null; if (obj is KeyValuePair <Assignment, TimePhasedDataType[]> ) { KeyValuePair <Assignment, TimePhasedDataType[]> timePhasedData = (KeyValuePair <Assignment, TimePhasedDataType[]>)obj; retVal = new PersonalContour(); int counter = 0; foreach (TimePhasedDataType timePhase in timePhasedData.Value) { counter++; Assignment assignment = timePhasedData.Key; long startDuration = assignment.WorkingCalendar.SubstractDates(timePhase.Start, assignment.Start, false); long endDuration = assignment.WorkingCalendar.SubstractDates(timePhase.Finish, assignment.Start, false); if (startDuration == endDuration) { continue; } double unit = (double)timePhase.Value / (endDuration - startDuration); retVal.InsertInterval(startDuration, endDuration, unit); } } return(retVal); }
/// <summary> /// Adjusts the units. /// </summary> /// <param name="multiplier">The multiplier.</param> /// <param name="startingFrom">The starting from.</param> /// <returns></returns> public override AbstractContour AdjustUnits(double multiplier, long startingFrom) { PersonalContour newContour = new PersonalContour(); newContour.ContourBuckets.AddRange(GetBucketsBeforeDuration(startingFrom)); foreach (PersonalContourBucket remainingBucket in GetBucketAfterDuration(startingFrom)) { newContour.ContourBuckets.Add(remainingBucket.AdjustUnits(multiplier)); } this.ContourBuckets.Clear(); this.ContourBuckets.AddRange(newContour.ContourBuckets); return this; }
/// <summary> /// Adjusts the work. /// </summary> /// <param name="multiplier">The multiplier.</param> /// <param name="actualDuration">The actual duration.</param> /// <returns></returns> public override AbstractContour AdjustWork(double multiplier, long actualDuration) { PersonalContour newContour = new PersonalContour(); newContour.ContourBuckets.AddRange(GetBucketsBeforeDuration(actualDuration)); foreach (PersonalContourBucket remainingBucket in GetBucketAfterDuration(actualDuration)) { newContour.ContourBuckets.Add(remainingBucket.AdjustWork(multiplier)); } this.ContourBuckets.Clear(); this.ContourBuckets.AddRange(newContour.ContourBuckets); return(this); }
/// <summary> /// Set the duration of the personal contour. This implies either truncating the bucket array or changing the last bucket /// to accommodate the new duration. Note that only the last bucket will be modified. The number of buckets will never increase. /// Since the buckets themselves are immutable, the last element will most likely be replaced. /// </summary> /// <param name="newDuration">The new duration.</param> /// <param name="actualDuration">The actual duration.</param> /// <returns></returns> public override AbstractContour AdjustDuration(long newDuration, long actualDuration) { PersonalContour newContour = new PersonalContour(); foreach (AbstractContourBucket bucket in base.ContourBuckets) { PersonalContourBucket personalBucket = (PersonalContourBucket)bucket; newContour.ContourBuckets.Add(personalBucket); newDuration -= personalBucket.Duration; if (newDuration <= 0) { // adding a negative value personalBucket.AdjustDuration(newDuration); newDuration = 0; //AbstractContour result = newContour.makePacked(); // pack so as to get rid of any trailing empty buckets } } // extend last bucket to account for duration ((PersonalContourBucket)newContour.ContourBuckets[newContour.ContourBuckets.Count - 1]).AdjustDuration(newDuration); this.ContourBuckets.Clear(); this.ContourBuckets.AddRange(newContour.ContourBuckets); return this; }
/// <summary> /// Set the duration of the personal contour. This implies either truncating the bucket array or changing the last bucket /// to accommodate the new duration. Note that only the last bucket will be modified. The number of buckets will never increase. /// Since the buckets themselves are immutable, the last element will most likely be replaced. /// </summary> /// <param name="newDuration">The new duration.</param> /// <param name="actualDuration">The actual duration.</param> /// <returns></returns> public override AbstractContour AdjustDuration(long newDuration, long actualDuration) { PersonalContour newContour = new PersonalContour(); foreach (AbstractContourBucket bucket in base.ContourBuckets) { PersonalContourBucket personalBucket = (PersonalContourBucket)bucket; newContour.ContourBuckets.Add(personalBucket); newDuration -= personalBucket.Duration; if (newDuration <= 0) { // adding a negative value personalBucket.AdjustDuration(newDuration); newDuration = 0; //AbstractContour result = newContour.makePacked(); // pack so as to get rid of any trailing empty buckets } } // extend last bucket to account for duration ((PersonalContourBucket)newContour.ContourBuckets[newContour.ContourBuckets.Count - 1]).AdjustDuration(newDuration); this.ContourBuckets.Clear(); this.ContourBuckets.AddRange(newContour.ContourBuckets); return(this); }
private XmlDocument DebugInterval(PersonalContour contour, Assignment assignment) { XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateElement("ss")); long startDuration = 0; foreach (PersonalContourBucket bucket in contour.ContourBuckets) { XmlElement element = doc.CreateElement("TimePhaseData"); XmlNode node = element.AppendChild(doc.CreateElement("Start")); node.InnerText = new DateTime(CalendarHelper.Milis2Tick(assignment.WorkingCalendar.AddDuration(assignment.Start, startDuration, false))).ToString("yyyy-MM-ddTHH:mm:ss"); node = element.AppendChild(doc.CreateElement("Finish")); node.InnerText = new DateTime(CalendarHelper.Milis2Tick(assignment.WorkingCalendar.AddDuration(assignment.Start, bucket.ElapsedDuration, false))).ToString("yyyy-MM-ddTHH:mm:ss"); node = element.AppendChild(doc.CreateElement("Value")); node.InnerText = String.Format("PT{0}H{1}M{2}S", bucket.Duration / CalendarHelper.MilisPerHour(), (bucket.Duration % CalendarHelper.MilisPerHour()) / CalendarHelper.MilisPerMinute(), (bucket.Duration % CalendarHelper.MilisPerMinute()) / (CalendarHelper.MilisPerMinute() / 60)); doc.DocumentElement.AppendChild(element); startDuration = bucket.ElapsedDuration; } return doc; }