ErgometerTest.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ErgometerApplication
  7. {
  8. class ErgometerTest
  9. {
  10. private int weight;
  11. private int length;
  12. private int age;
  13. private char gender;
  14. private enum state {WARMUP, WORKLOAD, COOLINGDOWN};
  15. private state currentstate;
  16. private int stateStarted;
  17. public ErgometerTest(int weight, int length , int age, char gender)
  18. {
  19. this.weight = weight;
  20. this.length = length;
  21. this.age = age;
  22. this.gender = gender;
  23. currentstate = state.WARMUP;
  24. stateStarted = 0;
  25. }
  26. public void timerTick()
  27. {
  28. switch(currentstate)
  29. {
  30. case state.WARMUP:
  31. if (MainClient.Metingen.Last().Seconds > 30)
  32. {
  33. List<ErgometerLibrary.Meting> last10 = MainClient.Metingen.GetRange(MainClient.Metingen.Count - 10, 10);
  34. int max = FindMaxValue(MainClient.Metingen, x => x.HeartBeat);
  35. int min = FindMaxValue(MainClient.Metingen, x => x.HeartBeat);
  36. if(max - min > 20) //Hartslag niet stabiel
  37. {
  38. return;
  39. }
  40. else
  41. {
  42. currentstate = state.WORKLOAD;
  43. }
  44. }
  45. break;
  46. case state.WORKLOAD:
  47. break;
  48. case state.COOLINGDOWN:
  49. break;
  50. }
  51. }
  52. // HELPER FUNCTIONS //
  53. private double CalculateMaximumHeartRate()
  54. {
  55. return 208 - (0.7 * age);
  56. }
  57. public int FindMaxValue<T>(List<T> list, Converter<T, int> projection)
  58. {
  59. if (list.Count == 0)
  60. {
  61. throw new InvalidOperationException("Empty list");
  62. }
  63. int maxValue = int.MinValue;
  64. foreach (T item in list)
  65. {
  66. int value = projection(item);
  67. if (value > maxValue)
  68. {
  69. maxValue = value;
  70. }
  71. }
  72. return maxValue;
  73. }
  74. public int FindMinValue<T>(List<T> list, Converter<T, int> projection)
  75. {
  76. if (list.Count == 0)
  77. {
  78. throw new InvalidOperationException("Empty list");
  79. }
  80. int minValue = int.MaxValue;
  81. foreach (T item in list)
  82. {
  83. int value = projection(item);
  84. if (value < minValue)
  85. {
  86. minValue = value;
  87. }
  88. }
  89. return minValue;
  90. }
  91. }
  92. }