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.

116 lines
3.8 KiB

9 years ago
  1. 'use strict';
  2. function uuid() {
  3. return (Math.random()*1e15).toString(32) + "-" + (Math.random()*1e15).toString(32);
  4. }
  5. /**
  6. * This is a local assignment, this keeps track on how long an assignment takes THIS worker.
  7. *
  8. * @param id
  9. * @param type
  10. * @param timeStart
  11. * @constructor
  12. */
  13. function Job(id, type, timeStart, agentId, prerequisites) {
  14. this.id = id;
  15. this.type = type;
  16. this.agentId = agentId;
  17. this.timeStart = timeStart;
  18. this.timeResumed = timeStart;
  19. this.timePaused = 0;
  20. this.elapsedTime = 0;
  21. this.elapsedTimeWithPause = 0;
  22. this.endOfDayPause = false;
  23. this.paused = false;
  24. this.finished = false;
  25. this.duration = new DurationData();
  26. this.prediction = new DurationStats();
  27. this.startupTime = new DurationData();
  28. this.predictedStartupTime = new DurationStats();
  29. this.prerequisites = prerequisites;
  30. }
  31. Job.prototype.prerequisiteFinished = function(params) {
  32. var uuid = params.uuid;
  33. for (var i = 0; i < this.prerequisites.length; i++) {
  34. var prereq = this.prerequisites[i];
  35. if (prereq.uuid == uuid) {
  36. prereq.times.setData(params.duration);
  37. break;
  38. }
  39. }
  40. };
  41. Job.prototype.watchingPrerequisite = function(preliminaryStats, uuid) {
  42. for (var i = 0; i < this.prerequisites.length; i++) {
  43. var prereq = this.prerequisites[i];
  44. if (prereq.uuid == uuid) {
  45. prereq.stats.setData(preliminaryStats);
  46. this.predictedStartupTime.useHighest(preliminaryStats);
  47. break;
  48. }
  49. }
  50. };
  51. Job.prototype.finalizePrerequisites = function() {
  52. for (var i = 0; i < this.prerequisites.length; i++) {
  53. this.startupTime.useHighest(this.prerequisites[i].times);
  54. }
  55. };
  56. Job.prototype.finish = function(time) {
  57. this.finished = true;
  58. this.elapsedTime += new Date(time).getTime() - new Date(this.timeResumed).getTime();
  59. this.elapsedTimeWithPause += new Date(time).getTime() - new Date(this.timeResumed).getTime();
  60. this.finalizePrerequisites();
  61. this.duration.calculateDuration(time, this.timeStart, this.elapsedTime, this.elapsedTimeWithPause, this.startupTime);
  62. };
  63. Job.prototype.pause = function(time, endOfDay) {
  64. // if this is the endOfDay AND the job is paused, count the pause time and set the endOfDay pause to true
  65. if (endOfDay == true && this.paused == true) {
  66. this.elapsedTimeWithPause += new Date(time).getTime() - new Date(this.timePaused).getTime();
  67. this.endOfDayPause = true;
  68. }
  69. // if this is the endOfDay AND the job is NOT paused, pause the job, increment the timers
  70. else if (endOfDay == true && this.paused == false) {
  71. this.elapsedTimeWithPause += new Date(time).getTime() - new Date(this.timeResumed).getTime();
  72. this.elapsedTime += new Date(time).getTime() - new Date(this.timeResumed).getTime();
  73. this.endOfDayPause = true;
  74. }
  75. else if (this.paused == false) {
  76. this.elapsedTimeWithPause += new Date(time).getTime() - new Date(this.timeResumed).getTime();
  77. this.elapsedTime += new Date(time).getTime() - new Date(this.timeResumed).getTime();
  78. this.timePaused = time;
  79. this.paused = true;
  80. }
  81. };
  82. Job.prototype.resume = function(time, startOfDay) {
  83. // if the job was paused because of the endOfDay, resume it and set the timeResumed to now
  84. if (this.endOfDayPause == true && startOfDay == true && this.paused == false) {
  85. this.timeResumed = time;
  86. this.endOfDayPause = false;
  87. }
  88. // if the job was paused before the endOfDay, keep it paused, but set the paused time to now.
  89. else if (this.endOfDayPause == true && startOfDay == true && this.paused == true) {
  90. this.timePaused = time;
  91. this.endOfDayPause = false;
  92. }
  93. // if this is NOT the start of day and the job was paused, resume job, increment
  94. else if (startOfDay == false && this.paused == true) {
  95. this.elapsedTimeWithPause += new Date(time).getTime() - new Date(this.timePaused).getTime();
  96. this.timeResumed = time;
  97. this.paused = false;
  98. }
  99. };