using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ErgometerApplication { class ErgometerTest { private int weight; private int length; private int age; private char gender; private enum state {WARMUP, WORKLOAD, COOLINGDOWN}; private state currentstate; private int stateStarted; public ErgometerTest(int weight, int length , int age, char gender) { this.weight = weight; this.length = length; this.age = age; this.gender = gender; currentstate = state.WARMUP; stateStarted = 0; } public void timerTick() { switch(currentstate) { case state.WARMUP: if (MainClient.Metingen.Last().Seconds > 30) { List last10 = MainClient.Metingen.GetRange(MainClient.Metingen.Count - 10, 10); int max = FindMaxValue(MainClient.Metingen, x => x.HeartBeat); int min = FindMaxValue(MainClient.Metingen, x => x.HeartBeat); if(max - min > 20) //Hartslag niet stabiel { return; } else { currentstate = state.WORKLOAD; } } break; case state.WORKLOAD: break; case state.COOLINGDOWN: break; } } // HELPER FUNCTIONS // private double CalculateMaximumHeartRate() { return 208 - (0.7 * age); } public int FindMaxValue(List list, Converter projection) { if (list.Count == 0) { throw new InvalidOperationException("Empty list"); } int maxValue = int.MinValue; foreach (T item in list) { int value = projection(item); if (value > maxValue) { maxValue = value; } } return maxValue; } public int FindMinValue(List list, Converter projection) { if (list.Count == 0) { throw new InvalidOperationException("Empty list"); } int minValue = int.MaxValue; foreach (T item in list) { int value = projection(item); if (value < minValue) { minValue = value; } } return minValue; } } }