vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.5 KiB

10 years ago
  1. /**
  2. * Created by Alex on 9/25/2014.
  3. */
  4. function DurationStats() {
  5. this.fields = ['duration','durationWithPause','durationWithStartup','durationWithBoth'];
  6. for (var i = 0; i < this.fields.length; i++) {
  7. this[this.fields[i]] = {mean: 0, std: 0};
  8. }
  9. }
  10. DurationStats.prototype.clearStats = function() {
  11. for (var i = 0; i < this.fields.length; i++) {
  12. var field = this.fields[i];
  13. this[field].mean = 0;
  14. this[field].std = 0;
  15. }
  16. };
  17. DurationStats.prototype.sumStats = function(otherData) {
  18. for (var i = 0; i < this.fields.length; i++) {
  19. var field = this.fields[i];
  20. this[field].mean += otherData[field].mean;
  21. this[field].std += Math.pow(otherData[field].std,2);
  22. }
  23. };
  24. DurationStats.prototype.averageStats = function(datapoints) {
  25. for (var i = 0; i < this.fields.length; i++) {
  26. var field = this.fields[i];
  27. this[field].mean /= datapoints;
  28. this[field].std = Math.sqrt(this[field].std / datapoints);
  29. }
  30. };
  31. DurationStats.prototype.getMeanData = function() {
  32. var dataObj = {};
  33. for (var i = 0; i < this.fields.length; i++) {
  34. dataObj[this.fields[i]] = this[this.fields[i]].mean;
  35. }
  36. return dataObj;
  37. };
  38. DurationStats.prototype.getData = function() {
  39. var dataObj = {};
  40. for (var i = 0; i < this.fields.length; i++) {
  41. dataObj[this.fields[i]] = {};
  42. dataObj[this.fields[i]].mean = this[this.fields[i]].mean;
  43. dataObj[this.fields[i]].std = this[this.fields[i]].std;
  44. }
  45. return dataObj;
  46. };
  47. DurationStats.prototype.setData = function(otherData) {
  48. for (var i = 0; i < this.fields.length; i++) {
  49. var field = this.fields[i];
  50. this[field].mean = otherData[field].mean;
  51. this[field].std = otherData[field].std;
  52. }
  53. };
  54. DurationStats.prototype.generateData = function(otherData) {
  55. for (var i = 0; i < this.fields.length; i++) {
  56. var field = this.fields[i];
  57. this[field].mean = otherData[i] * 3600000;
  58. this[field].std = otherData[i] * 0.1;
  59. }
  60. };
  61. DurationStats.prototype.useHighest = function(otherData) {
  62. for (var i = 0; i < this.fields.length; i++) {
  63. var field = this.fields[i];
  64. if (this[field].mean < otherData[field].mean) {
  65. this[field].mean = otherData[field].mean;
  66. this[field].std = otherData[field].std;
  67. }
  68. }
  69. };
  70. DurationStats.prototype.getFakeStats = function(type) {
  71. switch (type) {
  72. case "Assemble Coffeemaker":
  73. this.generateData([1.3,1.3,1.3,1.3]);
  74. break;
  75. case "Discuss potential NC":
  76. this.generateData([0.5,0.5,0.9,0.9]);
  77. break;
  78. case "Drilling rework":
  79. this.generateData([5,5,8,8]);
  80. break;
  81. case "Go to station":
  82. var a = 0.3;
  83. this.generateData([a,a,a,a]);
  84. break;
  85. case "Inspect finished Coffeemaker":
  86. var a = 2;
  87. this.generateData([a,a,a,a]);
  88. break;
  89. case "Inspect potential NC":
  90. var a = 0.5;
  91. this.generateData([a,a,a,a]);
  92. break;
  93. case "Kitting Coffeemaker":
  94. var a = 1.2;
  95. this.generateData([a,a,a,a]);
  96. break;
  97. case "NC Meeting":
  98. var a = 15;
  99. this.generateData([3,3.5,a,a]);
  100. break;
  101. case "Go to NC meeting":
  102. var a = 12;
  103. this.generateData([a,a,a,a]);
  104. break;
  105. case "Organise drilling rework":
  106. var a = 2;
  107. this.generateData([a,a,3,3]);
  108. break;
  109. case "Produce Coffeemaker":
  110. var a = 35;
  111. this.generateData([a,a,a,a]);
  112. break;
  113. case "Transport to delivery":
  114. var a = 0.4;
  115. this.generateData([a,a,a,a]);
  116. break;
  117. default:
  118. console.log("CANNOT MATCH", type);
  119. break;
  120. }
  121. };