private Step(string name, TimeSpan duration, Pace.Names pace, double distance, bool isDurationCalculated, bool isDistanceCalculated, TimeSpan? rest = null, int repetitions = 1) : this() { if (!isDurationCalculated ^ isDistanceCalculated) { throw new ArgumentException("Exactly one of duration and distance can have been calculated"); } Name = name; Duration = duration; Pace = pace; Distance = distance; Rest = rest ?? TimeSpan.Zero; Repetitions = repetitions; IsDurationCalculated = isDurationCalculated; IsDistanceCalculated = isDistanceCalculated; }
/// <summary> /// Initializes a new Data instance with the given name. /// This name is used to resolve the path to the persisted data. /// </summary> /// <param name="planName">Name of the training plan.</param> public Data(string planName) { Instance = this; // create persistence handler for this `Data` instance. var persistence = new DataPersistence(this); // load persisted data // NOTE: Must load training plan first because its name is needed to find the other files _trainingPlan = persistence.LoadPlan(planName); _trainingPlan.SetData(this); Pace = persistence.LoadPace(); _workouts = new List<Workout>(persistence.LoadWorkouts()); _categories = new List<WorkoutCategory>(persistence.LoadCategories()); Logger.Info("Data instantiated"); }
/// <summary> /// Create a new step with the length being determined by the distance. /// </summary> public Step(string name, double distance, Pace.Names pace, TimeSpan? rest = null, int repetitions = 1) : this(name, TimeSpan.FromSeconds(distance*Data.Instance.GetDurationFromPace(pace).TotalSeconds), pace, distance, true, false, rest, repetitions) { }
/// <summary> /// Create a new step with the length being determined by the duration. /// </summary> public Step(string name, TimeSpan duration, Pace.Names pace, TimeSpan? rest = null, int repetitions = 1) : this(name, duration, pace, duration.TotalSeconds/Data.Instance.GetDurationFromPace(pace).TotalSeconds, false, true, rest, repetitions) { }
/// <summary> /// Updates the value of several paces. /// </summary> /// <param name="keys">Description of the changed paces.</param> /// <param name="values">New value of the changed paces.</param> public void ChangePaces(Pace.Names[] keys, TimeSpan[] values) { if (keys.Length != values.Length) { throw new ArgumentException(); } // save pace in model for (var i = 0; i < keys.Length; i++) { Pace.SetPace(keys[i], values[i]); } Logger.Debug("Triggering PaceChanged event"); PaceChanged(this, null); }
public TimeSpan GetDurationFromPace(Pace.Names pace) { switch (pace) { case Pace.Names.Easy: return Pace.Easy; case Pace.Names.Base: return Pace.Base; case Pace.Names.Steady: return Pace.Steady; case Pace.Names.Marathon: return Pace.Marathon; case Pace.Names.Halfmarathon: return Pace.Halfmarathon; case Pace.Names.Threshold: return Pace.Threshold; case Pace.Names.TenK: return Pace.TenK; case Pace.Names.FiveK: return Pace.FiveK; default: throw new ArgumentOutOfRangeException("pace"); } }