-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptimizing-working-time.js
317 lines (277 loc) · 7.66 KB
/
optimizing-working-time.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/**
* parse the value of a fieldId in float
*
* @param id
* @returns float
*/
function getValue(id) {
return parseFloat($(id).val());
}
/**
* parse the value of a field text in float
*
* @param id
* @returns float
*/
function getValueText(id) {
return parseFloat($(id).text());
}
/**
* Returns a decimal with precision 2. Ex x:2,535 -> 2,54
*
* @param x
* @returns {Number}
*/
function roundValue(x) {
return Math.round(x * 100) / 100;
}
/**
* Returns the value in float of the selected option
*
* @param id
* @returns float
*/
function getValueUnit(id) {
var idRef = $(id).val();
return parseFloat($('#' + idRef).val());
}
/**
* returns the coefficient a from f(x) = a * x. It is the current equation in
* time spent
*
* @returns {Number}
*/
function getA_X() {
var actualTaskDuration = getValue('#actualTaskDurationId');
var actualTaskDurationUnit = getValueUnit('#actualTaskDurationUnitId');
var actualTaskFrequency = getValue('#actualTaskFrequencyId');
var actualTaskFrequencyUnit = getValueUnit('#actualTaskFrequencyUnitId');
// equation actual time spent
var a_x = (actualTaskDuration * actualTaskDurationUnit * actualTaskFrequency)
/ (1.0 * actualTaskFrequencyUnit);
return a_x;
}
/**
* returns the coefficient b_future from f_future(x) = a_future * x + b_future
* It is the future equation in time spent
*
* @returns {Number}
*/
function get_B_Future() {
// in min
var b_prime = getValue('#timePutInPlaceId') * getValue('#pWorkingDayId');
return b_prime;
}
/**
* returns the coefficient a_future from f_future(x) = a_future * x + b_future
* It is the future equation in time spent
*
* @returns {Number}
*/
function getA_X_Future() {
// in min
var timeExecution = getValue('#timeExecutionId')
* getValue('#pWorkingMinId');
var taskFrequency = getValue('#taskFrequencyId');
var taskFrequencyUnit = getValueUnit('#taskFrequencyUnitId');
var a_x_prime = (timeExecution * taskFrequency) / (1.0 * taskFrequencyUnit);
return a_x_prime;
}
/**
* Comestic function to change text 'Gain' to 'Loss' and color background
*
* @param gainValue
* @returns Void
*/
function displayGainOrLoss(gainValue) {
if (gainValue < 0) {
$("#resultZoneId .bg-success h3:contains('Gain')").html(
function(occurrence, text) {
var sNewText = text.replace("Gain", "Loss");
return sNewText;
});
$("#resultZoneId .bg-success li:contains('gain')").html(
function(occurrence, text) {
var sNewText = text
.replace(new RegExp('gain', 'g'), "loss"); // replaceAll
return sNewText;
});
// change background success to danger
$('#resultZoneId .bg-success').addClass('bg-danger');
$('#resultZoneId .bg-success').removeClass('bg-success');
} else {
$("#resultZoneId .bg-danger h3:contains('Loss')").html(
function(occurrence, text) {
var sNewText = text.replace("Loss", "Gain");
return sNewText;
});
$("#resultZoneId .bg-danger li:contains('loss')").html(
function(occurrence, text) {
var sNewText = text
.replace(new RegExp('loss', 'g'), "gain");
return sNewText;
});
// change background danger to success
$('#resultZoneId .bg-danger').addClass('bg-success');
$('#resultZoneId .bg-danger').removeClass('bg-danger');
}
}
/**
* Display the Chart, use the library http://www.flotcharts.org/ and the plugin
* jquery.flot.axislabels to display titles on axis
*
* @returns Void
*/
function displayChart() {
var LIMIT_FACTOR_AXIS_X = 2;
// coord x for the gain point
var xA = getValueText('#timeGainAfterId');
// coord (x,y) for the extreme right point for the current equation
var xA_limit = LIMIT_FACTOR_AXIS_X * xA;
var yA_limit = LIMIT_FACTOR_AXIS_X * getA_X() * xA;
// cord y for the start of the future equation
var yB_Future = get_B_Future() / (1.0 * getValue('#pWorkingDayId'));
// no gain, no display
if (xA <= 0) {
$("#chartId").empty();
return;
}
// coord y for the extreme right point for the future equation
var yA_Future_limit = LIMIT_FACTOR_AXIS_X * getA_X_Future() * xA;
// points for the current equation
var now = [ [ 0, 0 ], [ xA_limit, yA_limit ] ];
// points for the future equation
var future = [ [ 0, yB_Future ], [ xA_limit, yA_Future_limit + yB_Future ] ];
// points to show the gain point
var crosspoint = [ [ xA, 0 ], [ xA, xA * getA_X() ] ];
// points to show the gain area
var gainArea = [ [ xA, xA * getA_X() ], [ xA_limit, yA_limit ] ];
// chart libray flotcharts
var plot = $.plot($("#chartId"), [ {
data : now,
label : " Time currently spent on the task",
show : true,
color : "#d1a1a1",
shadowSize : 0
}, {
data : future,
label : " Time spent with the automated task",
show : true,
color : "#9ec5d8",
shadowSize : 0
}, {
data : crosspoint,
lines : {
show : true,
lineWidth : 1
},
color : "#545454",
shadowSize : 0,
points : {
show : true
}
}, {
data : gainArea,
lines : {
show : true,
lineWidth : 0, // to avoid to mask the lines of the data 'now'
fill : true,
fillColor : { // opacity < 1.0 to avoid to mask the lines of the
// data 'future'
colors : [ {
opacity : 0.4
}, {
opacity : 0.4
} ]
}
},
color : "#c0e0b3",
shadowSize : 0
} ], {
grid : {
borderWidth : {
"top" : 0,
"right" : 0,
"bottom" : 1,
"left" : 1
}
},
yaxis : {
min : 0,
max : yA_limit,
tickDecimals : 0,
axisLabel : "Task worload",
tickFormatter : function(val) {
return val + " w. days";
}
},
xaxis : {
min : 0,
max : xA_limit,
axisLabel : "Working time",
tickFormatter : function(val) {
return val + " w. days";
}
},
legend : {
position : "nw"
}
}
);
// show the gain point in the chart with a message
var o = plot.pointOffset({
x : xA,
y : xA * getA_X()
});
$("#chartId").append(
"<div class='chart-crosspoint' style='left:" + (o.left + 4)
+ "px;top:" + o.top + "px;'>Gain point = " + xA
+ " w. days</div>");
}
/**
* Main function to calculate the indicators
*
* 1. Compute the intersection of the current equation of time spent f(x) = a *
* x and the future equation in f(x) = a * x + b
*
* 2. updates the fields with the new indicators
*/
function computeTime() {
// current equation time spent
var a_x = getA_X();
// future time spent
var a_prime_x = getA_X_Future();
// in min
var b_prime = get_B_Future();
// in min
var timeGainAfter = b_prime / (1.0 * (a_x - a_prime_x));
// convert gain in working day
timeGainAfter = timeGainAfter / getValue('#pWorkingDayId');
// compute gain step after, by w.day
var timeGain = (a_x - a_prime_x) * getValue('#pWorkingDayId');
// update fields
$('#timeGainAfterId').text(roundValue(timeGainAfter));
$('#timeGainDayId').text(roundValue(timeGain));
// convert in w. hour by w. week
$('#timeGainWeekId')
.text(
roundValue(timeGain
* getValue('#pWorkingWeekId')
/ (getValue('#pWorkingDayId') * getValue('#pWorkingHourId'))));
// convert in w. day by w. month
$('#timeGainMonthId')
.text(
roundValue(timeGain
* getValue('#pWorkingMonthId')
/ (getValue('#pWorkingDayId') * getValue('#pWorkingDayId'))));
// convert in w. day by w. year
$('#timeGainYearId')
.text(
roundValue(timeGain
* getValue('#pWorkingYearId')
/ (getValue('#pWorkingDayId') * getValue('#pWorkingDayId'))));
displayGainOrLoss(timeGain);
displayChart();
}
// launch
computeTime();