Advertisement
Guest User

Gear ratio distribution

a guest
Mar 15th, 2019
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.34 KB | None | 0 0
  1. csvFileName = "/home/majikstone/GoldenCheetah/export_mid2018_2019_Bike.csv";
  2. wheelC = 2.12;
  3. textYValB = 1.5;
  4. textYValC = 1;
  5. textYValD = 0.4;
  6. binVal = c(30/30,30/27,30/25,30/23,30/21,30/19,30/17,30/15,46/21,46/19,46/17,46/15,46/14,46/13,46/12,46/11);
  7. binBreaks = binVal - 0.001;
  8. binMax = 46/11+0.5;
  9. binBreaks = c(binBreaks,binMax);
  10. binTextB = c("30/30","30/27","30/25","30/23","30/21","30/19","30/17","30/15","46/21","46/19","46/17","46/15","46/14","46/13","46/12","46/11");
  11. binTextC = c("1.00","1.11","1.20","1.30","1.43","1.58","1.76","2.00","2.19","2.42","2.71","3.07","3.29","3.54","3.83","4.18");
  12. textYB = textYValB * c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
  13. textYC = textYValC * c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
  14. textYD = textYValD * c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
  15. textX = c(1:length(binVal));
  16.  
  17. for (i in c(1:length(binVal)-1))
  18. {
  19.     textX[i] = i;
  20. }
  21.  
  22. textX[length(binVal)] = (binVal[length(binVal)] + binMax)/2;
  23.  
  24. csvMat <- read.table(file=csvFileName,header=FALSE,sep=";",dec=",");
  25.  
  26. message("File loading complete!");
  27.  
  28. speed = as.numeric(csvMat$V1);
  29. cadence = as.numeric(csvMat$V2);
  30.  
  31. cadenceFilter = 50;
  32. speedFilter = 4;
  33. ratioFilterMin = 1.0;
  34. ratioFilterMax = 46/11+0.5;
  35.  
  36. filtCadence = cadence[cadence > cadenceFilter];
  37. filtSpeed = speed[cadence > cadenceFilter];
  38. cadence = filtCadence;
  39. speed = filtSpeed;
  40.  
  41. filtCadence = cadence[speed > speedFilter];
  42. filtSpeed = speed[speed > speedFilter];
  43. cadence = filtCadence;
  44. speed = filtSpeed;
  45.  
  46. gearRatio = 100 * speed / (6 * cadence * wheelC);
  47. gearRatio = gearRatio[gearRatio >= ratioFilterMin];
  48. gearRatio = gearRatio[gearRatio <= ratioFilterMax];
  49.  
  50. message("Data processing complete!");
  51.  
  52. gearHist = hist(gearRatio,breaks=binBreaks,plot=FALSE);
  53. percentages = diff(gearHist$breaks) * gearHist$density * 100;
  54. percText = sprintf("(%.1f %%)",percentages);
  55.  
  56. textYB = textYB + percentages;
  57. textYC = textYC + percentages;
  58. textYD = textYD + percentages;
  59.  
  60. x11(width=8,height=8);
  61. textX = barplot(percentages, ylim=c(0,max(percentages)+5),
  62.     col=rgb(0,0.5,0), border=rgb(0,0.75,0),
  63.     main="Gear ratio histogram", xlab="Gear ratio", ylab="Time %");
  64.  
  65. text(x=textX,y=textYB,labels=binTextB,adj=c(0.5,0.5),cex=0.8,col=rgb(0,0,0.5));
  66. text(x=textX,y=textYC,labels=binTextC,adj=c(0.5,0.5),cex=0.8,col=rgb(0,0,0.3));
  67. text(x=textX,y=textYD,labels=percText,adj=c(0.5,0.5),cex=0.9,col=rgb(0,0.75,0));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement