PolarAccData.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace Sensors.Polar
  6. {
  7. public readonly struct AccData
  8. {
  9. public long Timestamp { get; }
  10. public List<Vector3> Values { get; }
  11. private AccData(long timestamp, List<Vector3> values)
  12. {
  13. Timestamp = timestamp;
  14. Values = values;
  15. }
  16. public static AccData FromString(string s)
  17. {
  18. var data = s.Split(';');
  19. if (data.Length == 2)
  20. {
  21. var t = long.Parse(data[0]);
  22. var tupleStrings = data[1].Split(',').Select(item => item.Replace("(", "").Replace(")", ""));
  23. var floats = tupleStrings.Select(s1 => s1.Split('/').Select(value => float.Parse(value)).ToList())
  24. .ToList();
  25. return new AccData(t, floats.Select(a => new Vector3(a[0], a[1], a[2])).ToList());
  26. }
  27. throw new FormatException("AccData String has wrong format");
  28. }
  29. }
  30. }