CSVWriter.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 = Path.GetDirectoryName(Application.dataPath) + "/DataCSV/Pieter/";
  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. string path2 = path + mc.perspective.ToString() + "_" + mc.complexity.ToString() + "_" + mc.direction.ToString() + "_"
  21. + mc.feedback.ToString() + "_" + mc.speed.ToString() + ".csv";
  22. StreamWriter sw = new StreamWriter(path2);
  23. sw.WriteLine(demos + bodys + "time");
  24. for (int i = 0; i < posJointsDemos.Count; i++)
  25. {
  26. List<Vector3> demo = posJointsDemos[i];
  27. List<Vector3> body = posJointsBodys[i];
  28. string d = "";
  29. string b = "";
  30. for (int j = 0; j < demo.Count; j++)
  31. {
  32. d += Vector3ToString(demo[j]) + ",";
  33. b += Vector3ToString(body[j]) + ",";
  34. }
  35. sw.WriteLine(d + b + csvTimes[i]);
  36. }
  37. sw.Close();
  38. }
  39. private static string Vector3ToString(Vector3 vector)
  40. {
  41. return vector.x.ToString() + ";" + vector.y.ToString() + ";" + vector.z.ToString();
  42. }
  43. }