now also checks critical paths

This commit is contained in:
Enrico Fasoli 2015-04-07 14:09:05 +02:00
parent e2bd775359
commit 2f0a9a8da1
3 changed files with 25 additions and 4 deletions

View File

@ -12,11 +12,12 @@ pertApp.controller 'pertDiagController', ($scope) ->
if !data? then return
nodes = data.days.map (x) -> {id: x, label: ""+x}
connections = []
console.log data.criticalPaths
data.activities.forEach (x) ->
connections.push
from: x.startDay, to: x.endDay
label: x.id+" ("+(if x.permittedDelay > 0 then x.duration+"/"+(x.duration+x.permittedDelay) else x.duration)+")"
color: if !x.permittedDelay then 'red'
color: if x.critical then 'red' else if !x.permittedDelay then 'orange'
if x.permittedDelay > 0
connections.push
from: x.endDay

View File

@ -1,6 +1,7 @@
class Pert
constructor: (@list, @verbose) ->
@days = []
@criticalPaths = []
log: (x...) -> if @verbose then console.log chalk.bold("Pert:"), x...
err: (x...) -> console.log chalk.bold (chalk.red "Pert:"), x...
@ -64,6 +65,21 @@ class Pert
item.chainedDelay = lowestFDelay + lowestCDelay
return item.chainedDelay isnt olDelay
calculateCriticalPaths: (path) ->
@log "calculating path from",path
lastID = path[path.length - 1]
last = @toActivity lastID
if last.dependant? and last.dependant.length > 0
last.dependant.forEach (x) =>
ii = @toActivity x
unless ((ii.permittedDelay or 0) + (ii.chainedDelay or 0)) > 0
p = path; p.push x
@calculateCriticalPaths p
else
@log "calculated path", path
path.forEach (x) => @toActivity(x).critical = yes
@criticalPaths.push path
# Find out which activity has the highest id
highestID: => return @maxa(@list.map (x) -> x.id)
@ -89,7 +105,11 @@ class Pert
if @calculateDelays x
finished = no
@log "Done calculating delays. Took", i, "iterations"
results = activities: @list, days: @days
for x,i in @list
console.log x
if !x.depends? or x.depends.length is 0
@calculateCriticalPaths [x.id]
results = activities: @list, days: @days, criticalPaths: @criticalPaths
if options?.json
if cb? then cb(JSON.stringify results)
JSON.stringify results

View File

@ -5,7 +5,7 @@
<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>Dependant</b></td>
<td><b>End Day</b></td>
<td><b>Free Delay</b></td>
<td><b>Chained Delay</b></td>
@ -16,7 +16,7 @@
<td>{{item.duration}}</td>
<td>{{item.startDay}}</td>
<td>{{item.depends || "N/A"}}</td>
<td>{{item.dependent || "N/A"}}</td>
<td>{{item.dependant || "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>