2
0

PolarAccData.cs 1022 B

123456789101112131415161718192021222324252627282930313233
  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. AccData(long timestamp, List<Vector3> values)
  12. {
  13. this.Timestamp = timestamp;
  14. this.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()).ToList();
  24. return new AccData(t, floats.Select(a => new Vector3(a[0], a[1], a[2])).ToList());
  25. }
  26. throw new FormatException("AccData String has wrong format");
  27. }
  28. }
  29. }