PolarHRData.cs 791 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Sensors.Polar
  5. {
  6. public readonly struct HRData
  7. {
  8. public List<long> RrsMs { get; }
  9. public int HeartRate { get; }
  10. private HRData(List<long> rrsMs, int heartRate)
  11. {
  12. RrsMs = rrsMs;
  13. HeartRate = heartRate;
  14. }
  15. public static HRData FromString(string s)
  16. {
  17. var data = s.Split(';');
  18. if (data.Length == 2)
  19. {
  20. var hr = int.Parse(data[0]);
  21. var values = data[1].Split(',').Select(value => long.Parse(value)).ToList();
  22. return new HRData(values, hr);
  23. }
  24. throw new FormatException("HRData String has wrong format");
  25. }
  26. }
  27. }