implemented chained delays

This commit is contained in:
Enrico Fasoli 2015-04-07 13:36:07 +02:00
parent fab54bf553
commit e2bd775359
3 changed files with 34 additions and 5 deletions

View File

@ -47,6 +47,23 @@ class Pert
@insertDay item.startDay
return item.startDay
calculateDelays: (item) =>
if !item.dependant? or item.dependant.length is 0 then return no
lowestFDelay = 0; fDelay = no; cDelay = no; lowestCDelay = 0
for j,i of item.dependant
x = @toActivity i
if x.permittedDelay > 0
if x.permittedDelay < lowestFDelay or fDelay is no
lowestFDelay = x.permittedDelay
fDelay = yes
if x.chainedDelay > 0
if x.chainedDelay < lowestCDelay or cDelay is no
lowestCDelay = x.chainedDelay
cDelay = yes
olDelay = item.chainedDelay
item.chainedDelay = lowestFDelay + lowestCDelay
return item.chainedDelay isnt olDelay
# Find out which activity has the highest id
highestID: => return @maxa(@list.map (x) -> x.id)
@ -62,9 +79,16 @@ class Pert
calculate: (options,cb) ->
h = @highestID()
@list.forEach (x) =>
for x,i in @list
@log '('+x.id+'/'+h+')'
@calculateEndDay x
finished = no; i = 0
while !finished
i++; finished = yes
for x,i in @list
if @calculateDelays x
finished = no
@log "Done calculating delays. Took", i, "iterations"
results = activities: @list, days: @days
if options?.json
if cb? then cb(JSON.stringify results)
@ -72,4 +96,3 @@ class Pert
else
if cb? then cb(results)
results
if module? then module.exports = Pert

View File

@ -54,6 +54,6 @@ span.github a:hover {
}
#tab {
max-width: 40em;
max-width: 60em;
margin: 0 auto 0 auto;
}

View File

@ -4,15 +4,21 @@
<td><b>ID</b></td>
<td><b>Duration (days)</b></td>
<td><b>Start Day</b></td>
<td><b>Depends On</b></td>
<td><b>Dependent</b></td>
<td><b>End Day</b></td>
<td><b>Possible Delay</b></td>
<td><b>Free Delay</b></td>
<td><b>Chained Delay</b></td>
</tr>
<tr ng-repeat="item in list">
<td>{{$index + 1}}</td>
<td>{{item.id}}</td>
<td>{{item.duration}}</td>
<td>{{item.startDay}}</td>
<td>{{item.endDay}} --- {{item.endDay + (item.permittedDelay || 0)}}</td>
<td>{{item.depends || "N/A"}}</td>
<td>{{item.dependent || "N/A"}}</td>
<td>{{item.endDay}} --- {{item.endDay + (item.permittedDelay || 0) + (item.chainedDelay || 0)}}</td>
<td>{{item.permittedDelay || 0}}</td>
<td>{{item.chainedDelay || 0}}</td>
</tr>
</table>