statistic.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import glob
  2. import os
  3. import pandas as pd
  4. import matplotlib.pyplot as plt
  5. import time
  6. import numpy as np
  7. import seaborn as sns
  8. path = os.getcwd()
  9. def draw(filename):
  10. conditions = file['condition']
  11. result = file[filename]
  12. plt.figure(figsize=(9, 6), dpi=100)
  13. plt.bar(conditions, result, width=0.35, color=colors,alpha=a)
  14. plt.title(filename)
  15. plt.ylabel('score')
  16. plt.grid(alpha=0, linestyle=':')
  17. plt.savefig(filename + ".jpg", dpi=300)
  18. #plt.show()
  19. def drawTogether():
  20. plt.figure(figsize=(15,7))
  21. x = np.arange(len(scales))
  22. total_width, n = 0.8, 4
  23. width = total_width / n
  24. for i in range(0,4):
  25. result = []
  26. for scale in scales:
  27. result.append(file.iloc[i][scale])
  28. plt.bar(x+width*(i-1),result,width=width,color=colors[i],label=file.iloc[i]["condition"],alpha=a)
  29. plt.legend()
  30. plt.xticks(x+width/2,scales)
  31. #plt.show()
  32. plt.savefig("summary.jpg",dpi=300)
  33. # Merge all the .csv file start with "HectorVR", and
  34. all_files = glob.glob(os.path.join(path, "HectorVR*.csv"))
  35. df_from_each_file = (pd.read_csv(f, sep=',') for f in all_files)
  36. df_merged = pd.concat(df_from_each_file, ignore_index=True)
  37. # Save the file to Merged.csv in the same folder
  38. df_merged.to_csv( "Merged.csv")
  39. # save the results in csv
  40. file = df_merged.groupby(["condition"]).mean()
  41. file.to_csv( "Mean.csv")
  42. file = pd.read_csv("Mean.csv")
  43. scales = ["mental-demand","physical-demand","temporal-demand","performance", "effort","frustration","total"]
  44. colors = sns.color_palette()
  45. a = 0.6
  46. for scale in scales:
  47. draw(scale)
  48. drawTogether()