public void UpdateStageDisplayUber(DateTime startTime, DateTime endTime, double maxDurationInMinutes) { double scale = maxDisplayWidth / maxDurationInMinutes; if (scale <= 0) { scale = 1; } // Start by adding a stage for time between now and the first stage. if (startTime > DateTime.Now) { double scaledDurationInMinutes = scale * ((startTime - DateTime.Now).TotalMinutes); StageDisplays.Add(StageModel.Waiting((int)(scaledDurationInMinutes))); } // Add the single stage as this is a car trip. StageDisplays.Add(new StageModel("#E0E0E4", (int)(scale * (endTime - startTime).TotalMinutes))); // Finally add the extra space to fill the bar within the tile if the trip is short. if (StageDisplays.Sum(x => x.Width) < maxDisplayWidth) { StageDisplays.Add(StageModel.Waiting((int)maxDisplayWidth - StageDisplays.Sum(x => x.Width))); } }
public void UpdateStageDisplay(DateTime scaledStartTime, bool isScaledStartTime, double maxDurationInMinutes, DateTime end) { if (DateTime.Now > this.Stages.Last().EndTime) { StageDisplays.Clear(); StageDisplays.Add(StageModel.Waiting((int)maxDisplayWidth)); return; } StageDisplays.Clear(); double scale = maxDisplayWidth / maxDurationInMinutes; double runningTime = 0; if (isScaledStartTime) { scale = (maxDisplayWidth - 60) / maxDurationInMinutes; StageDisplays.Add(StageModel.Waiting(60, Visibility.Visible)); } if (this.Stages.First().StartTime < DateTime.Now) { runningTime = (DateTime.Now - this.Stages.First().StartTime).TotalMinutes; } //TODO test with walking! Stage previousStage = null; // Start by adding a stage for time between now and the first stage. if (this.Stages.First().StartTime > scaledStartTime) { double scaledDurationInMinutes = scale * ((this.Stages.First().StartTime - scaledStartTime).TotalMinutes); StageDisplays.Add(StageModel.Waiting((int)(scaledDurationInMinutes))); } // Add the stages as stage models. foreach (Stage stage in Stages) { double scaledDurationInMinutes = 1.0; if (previousStage != null && stage.StartTime > previousStage.EndTime) { if (runningTime < (stage.StartTime - previousStage.EndTime).TotalMinutes) { scaledDurationInMinutes = scale * ((stage.StartTime - previousStage.EndTime).TotalMinutes - runningTime); StageDisplays.Add(StageModel.Waiting((int)(scaledDurationInMinutes))); runningTime = 0; } else { runningTime -= (stage.StartTime - previousStage.EndTime).TotalMinutes; } } previousStage = stage; if (runningTime < stage.Duration) { scaledDurationInMinutes = scale * (stage.Duration - runningTime); StageDisplays.Add(new StageModel(stage.Colour, (int)(scaledDurationInMinutes))); runningTime = 0; } else { runningTime -= stage.Duration; } } // End by adding a stage for time between the end of this path option and the end time of the longest path option. if (this.Stages.Last().EndTime < end) { if (runningTime < (end - this.Stages.Last().EndTime).TotalMinutes) { double scaledDurationInMinutes = scale * ((end - this.Stages.Last().EndTime).TotalMinutes - runningTime); StageDisplays.Add(StageModel.Waiting((int)(scaledDurationInMinutes))); runningTime = 0; } else { runningTime -= (end - this.Stages.Last().EndTime).TotalMinutes; } } // Finally add the extra space to fill the bar within the tile if the trip is short. if (StageDisplays.Sum(x => x.Width) < maxDisplayWidth) { StageDisplays.Add(StageModel.Waiting((int)maxDisplayWidth - StageDisplays.Sum(x => x.Width))); } }