CSVWriter.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public static class CSVWriter
  6. {
  7. private static string path = Application.dataPath + "/data";
  8. public static void WriteCSV(List<List<Vector3>> posJointsDemos, List<List<Vector3>> posJointsBodys, List<float> csvTimes, ModeController mc)
  9. {
  10. string[] jointsName = { "SpineBase", "SpineMid", "Neck", "ShoulderLeft", "ElbowLeft", "WristLeft", "ShoulderRight",
  11. "ElbowRight", "WristRight", "HipLeft", "KneeLeft", "AnkleLeft", "FootLeft", "HipRight", "KneeRight", "AnkleRight",
  12. "FootRight", "SpineShoulder" };
  13. string demos = "";
  14. string bodys = "";
  15. foreach (string name in jointsName)
  16. {
  17. demos += "Demo_" + name + ",";
  18. bodys += "Body_" + name + ",";
  19. }
  20. path += "_" + mc.perspective.ToString() + "_" + mc.feedback.ToString() + ".csv";
  21. StreamWriter sw = new StreamWriter(path);
  22. sw.WriteLine(demos + bodys + "time");
  23. for (int i = 0; i < posJointsDemos.Count; i++)
  24. {
  25. List<Vector3> demo = posJointsDemos[i];
  26. List<Vector3> body = posJointsBodys[i];
  27. string d = "";
  28. string b = "";
  29. for (int j = 0; j < demo.Count; j++)
  30. {
  31. d += Vector3ToString(demo[j]) + ",";
  32. b += Vector3ToString(body[j]) + ",";
  33. }
  34. sw.WriteLine(d + b + csvTimes[i]);
  35. }
  36. sw.Close();
  37. }
  38. private static string Vector3ToString(Vector3 vector)
  39. {
  40. return vector.x.ToString() + ";" + vector.y.ToString() + ";" + vector.z.ToString();
  41. }
  42. }