diff --git a/src/controllers.coffee b/src/controllers.coffee index e970190..83a98a4 100644 --- a/src/controllers.coffee +++ b/src/controllers.coffee @@ -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 diff --git a/src/pert.coffee b/src/pert.coffee index 48e66f4..c320148 100644 --- a/src/pert.coffee +++ b/src/pert.coffee @@ -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 diff --git a/src/table.html b/src/table.html index fa83db3..50af13f 100644 --- a/src/table.html +++ b/src/table.html @@ -5,7 +5,7 @@ Duration (days) Start Day Depends On - Dependent + Dependant End Day Free Delay Chained Delay @@ -16,7 +16,7 @@ {{item.duration}} {{item.startDay}} {{item.depends || "N/A"}} - {{item.dependent || "N/A"}} + {{item.dependant || "N/A"}} {{item.endDay}} --- {{item.endDay + (item.permittedDelay || 0) + (item.chainedDelay || 0)}} {{item.permittedDelay || 0}} {{item.chainedDelay || 0}}