private static void RoundWeight(BaseExercise exercise, Repeat repeat) { if (repeat.Weight == null) { return; } var equipment = exercise switch { Accessory accessory => accessory.EquipmentType, _ => EquipmentType.Barbell }; var factor = equipment switch { EquipmentType.Barbell => Stats.BarbellFactor, EquipmentType.Dumbbell => Stats.DumbbellFactor, _ => throw new ArgumentOutOfRangeException(nameof(equipment), "Type is not defined") }; var roundedWeight = Math.Round(repeat.Weight.Value / factor) * factor; repeat.Weight = roundedWeight; } } }
// private static void CalculatePercentage(BaseExercise exercise, Repeat repeat) // { // if (exercise.Weight == null || repeat.Percent != null) return; // // var repeats = repeat switch // { // SingleRepeat singleRepeat => singleRepeat.Repeats, // MultiRepeat multiRepeat => multiRepeat.Repeats.Max(), // _ => throw new ArgumentOutOfRangeException(nameof(repeat), repeat, null) // }; // // var percent = repeats switch // { // 1 => 1, // _ => 1 - repeats * 0.025 // }; // // var result = percent * Stats.WorkWeight; // repeat.Percent = result; // } // // private static void AddWarmupRepeats(BaseExercise exercise) // { // if (!exercise.IsWarmupNeeded // || exercise.Repeats.First() is not WeightedRepeat repeat) return; // // var warmUps = new List<Repeat>(); // // for (var i = 0.5; i.LessThan(repeat.Percent); i += 0.1) // { // Repeat result = repeat switch // { // SingleRepeat singleRepeat => new SingleRepeat {Percent = i, Repeats = singleRepeat.Repeats}, // MultiRepeat multiRepeat => new MultiRepeat {Percent = i, Repeats = multiRepeat.Repeats}, // // TODO Fix // _ => throw new ArgumentOutOfRangeException(nameof(repeat), repeat, null) // }; // // warmUps.Add(result); // } // // warmUps.AddRange(exercise.Repeats); // exercise.Repeats = warmUps; // exercise.IsWarmupNeeded = false; // } private static void CalculateWeight(BaseExercise exercise, Repeat repeat) { if (repeat.Weight == null && exercise.Weight != null) { repeat.Weight = exercise.Weight * repeat.Percent; } }
public static ResourceExerciseElement ConvertFromDTO(ModuleExerciseElementDTO dto, CoachingModule module) { BaseExercise exercise = null; var moduleReference = new CoachingModuleReference(module.Id); switch (dto.ClassName) { case "SortAndEvaluate": exercise = new SortAndEvaluateExercise(dto.Configuration.Split(';').ToList(), moduleReference); break; case "VideoExercise": exercise = new VideoExercise(moduleReference); break; case "KPExplorerQuestionnaire": exercise = new KPExplorerQuestionnaire(moduleReference); break; case "Promise": exercise = new PromiseExercise(dto.Configuration.Split(';').ToList(), moduleReference); break; case "Goal": exercise = new GoalExercise(moduleReference); break; case "QuestionAnswer": exercise = new QuestionAnswerExercise(moduleReference); break; default: break; } if (exercise != null) { exercise.Description = dto.Description; exercise.InstrunctionContent = dto.InstrunctionContent; } return(new ResourceExerciseElement(dto.Content) { Exercise = exercise }); }
static void Main(string[] args) { Console.SetWindowSize(Console.LargestWindowWidth / 3 * 2, Console.LargestWindowHeight / 3 * 2); ArrayTools _arrayTools = new ArrayTools(); // Present choice of Objective for this Chapter bool _isObjectiveNumber; string _objectiveName = ""; int _numberOfObjectivesInChapter = 5; string[] _objectives = new string[_numberOfObjectivesInChapter]; for (int index = 0; index < _numberOfObjectivesInChapter; index++) { _objectives[index] = "ExerciseClassesObjective1_" + (index + 1); Console.WriteLine(_objectives[index] + "... press " + (index + 1)); } do { Console.WriteLine("Please enter the number of the objective of which you wish to run exercises... (Entering nothing quits input) "); _isObjectiveNumber = int.TryParse(Console.ReadLine(), out int _objectiveNumber); if (_isObjectiveNumber && _objectiveNumber > 0 && _objectiveNumber <= _numberOfObjectivesInChapter) { _objectiveName = _objectives[_objectiveNumber - 1]; Console.WriteLine("The exercises contained in objective {0} are as follows... ", _objectiveNumber); _isObjectiveNumber = false; } else if (!_isObjectiveNumber) { Console.WriteLine("No objective selected... "); } else { Console.Write("Objective {0} does not exsist. ", _objectiveNumber); } }while (_isObjectiveNumber); // Acquire array of Exercise(s) by system (Array: _exercises) string _nmspace = "Programming_70_483_Chapter_1." + _objectiveName; string _startsWith = "Ex"; var _classes = _arrayTools.GetObjectArrayOfClasses(_nmspace, _startsWith); int _numberOfExercises = _classes.Length; int[] _possibleExerciseNumbers = new int[_numberOfExercises]; BaseExercise[] _exercises = new BaseExercise[_numberOfExercises]; BaseExercise _baseExercise; int _index = 0; foreach (var _clss in _classes) { _baseExercise = _clss as BaseExercise; _exercises[_index] = _baseExercise; _possibleExerciseNumbers[_index] = _baseExercise.GetNumber(); _index++; } // Acquire array of exercise(s) to run (by number) through user input (Array: _exercisesToRun) int[] _exercisesToRun = new int[0]; bool _isNumber; if (_numberOfExercises == 0) { Console.WriteLine("Unable to provide list of exercises. Most likely there are none in the Objective folder... "); } else { do { Console.WriteLine("Please enter the exercise number you wish to run... (0 is not valid. Entering nothing quits input) "); _isNumber = int.TryParse(Console.ReadLine(), out int _result); if (_isNumber && _result != 0) { if (_possibleExerciseNumbers.Contains(_result)) { _exercisesToRun = _arrayTools.AddExerciseNumberToGivenArrayAndGiveBackNewArray(_result, _exercisesToRun); Console.Write("Exercise {0} added to list. ", _result); } else { Console.Write("Exercise {0} does not exsist. ", _result); } } }while (_isNumber); } // Execute exercise(s) cross referencing arrays _exercises and _exercisesToRun if (_exercisesToRun.Length > 0) { Console.WriteLine("Executing requested exercises..... "); foreach (BaseExercise _exercise in _exercises) { _exercise.NeedsExecution(_exercisesToRun); } } else { Console.WriteLine("No exercises provided. Program will terminate... "); } }