mirror of
https://github.com/fazo96/pbs.git
synced 2025-01-29 14:54:18 +01:00
can now view graphs
This commit is contained in:
parent
bd1f993373
commit
6b5f5f504d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
client/bower_components/
|
||||||
test/
|
test/
|
||||||
lib/
|
lib/
|
||||||
bin/
|
bin/
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
src/
|
src/
|
||||||
|
client/bower_components/
|
||||||
test/
|
test/
|
||||||
|
21
client/bower.json
Normal file
21
client/bower.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "pert-gui",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"homepage": "https://github.com/fazo96/pert",
|
||||||
|
"authors": [
|
||||||
|
"Enrico Fasoli <fazius2009@gmail.com>"
|
||||||
|
],
|
||||||
|
"description": "web ui for pert",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true,
|
||||||
|
"ignore": [
|
||||||
|
"**/.*",
|
||||||
|
"node_modules",
|
||||||
|
"bower_components",
|
||||||
|
"test",
|
||||||
|
"tests"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"vis": "~3.11.0"
|
||||||
|
}
|
||||||
|
}
|
20
client/index.html
Normal file
20
client/index.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Pert</title>
|
||||||
|
<link rel="stylesheet" href="bower_components/vis/dist/vis.min.css">
|
||||||
|
<style>
|
||||||
|
#pert {
|
||||||
|
width: 400px;
|
||||||
|
height: 400px;
|
||||||
|
border: 1px solid lightgray;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script src="bower_components/jquery/dist/jquery.js"></script>
|
||||||
|
<script src="bower_components/vis/dist/vis.min.js"></script>
|
||||||
|
<div id="pert"></div>
|
||||||
|
<script src="pert-ui.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -5,7 +5,7 @@
|
|||||||
"main": "lib/pert.js",
|
"main": "lib/pert.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"pert": "./bin/pert"
|
"pert": "./bin/pert"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublish": "scripts/build.sh",
|
"prepublish": "scripts/build.sh",
|
||||||
"build": "scripts/build.sh",
|
"build": "scripts/build.sh",
|
||||||
@ -23,7 +23,8 @@
|
|||||||
"homepage": "https://github.com/fazo96/pert",
|
"homepage": "https://github.com/fazo96/pert",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^1.0.0",
|
"chalk": "^1.0.0",
|
||||||
"commander": "^2.6.0"
|
"commander": "^2.6.0",
|
||||||
|
"express": "^4.12.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"coffee-script": "^1.9.1"
|
"coffee-script": "^1.9.1"
|
||||||
|
@ -3,3 +3,4 @@ echo '#!/usr/bin/env node' > bin/pert
|
|||||||
coffee -b -c --no-header -p src/pert-cli.coffee >> bin/pert
|
coffee -b -c --no-header -p src/pert-cli.coffee >> bin/pert
|
||||||
chmod +x bin/pert
|
chmod +x bin/pert
|
||||||
coffee -b -c --no-header -p src/pert.coffee > lib/pert.js
|
coffee -b -c --no-header -p src/pert.coffee > lib/pert.js
|
||||||
|
coffee -b -c --no-header -p src/pert-ui.coffee > client/pert-ui.js
|
||||||
|
@ -3,6 +3,7 @@ chalk = require 'chalk'
|
|||||||
cli = require 'commander'
|
cli = require 'commander'
|
||||||
fs = require 'fs'
|
fs = require 'fs'
|
||||||
Pert = require '../lib/pert.js'
|
Pert = require '../lib/pert.js'
|
||||||
|
express = require 'express'
|
||||||
|
|
||||||
ex = [{id: 0, depends: [], duration: 2}, { id: 1, depends: [0], duration: 3},{id: 2, depends: [0,1], duration: 4}]
|
ex = [{id: 0, depends: [], duration: 2}, { id: 1, depends: [0], duration: 3},{id: 2, depends: [0,1], duration: 4}]
|
||||||
|
|
||||||
@ -36,6 +37,24 @@ cli
|
|||||||
pert = new Pert JSON.parse(content), cli.verbose
|
pert = new Pert JSON.parse(content), cli.verbose
|
||||||
console.log pert.calculate options
|
console.log pert.calculate options
|
||||||
|
|
||||||
|
cli
|
||||||
|
.command 'graph <file>'
|
||||||
|
.description 'serve HTTP GUI with pert graph of given JSON document'
|
||||||
|
.alias 'g'
|
||||||
|
.action (file) ->
|
||||||
|
didSomething = yes
|
||||||
|
fs.readFile file, (error,content) ->
|
||||||
|
if error then err error
|
||||||
|
else
|
||||||
|
pert = new Pert JSON.parse(content), cli.verbose
|
||||||
|
data = pert.calculate()
|
||||||
|
app = express()
|
||||||
|
app.use express.static 'client'
|
||||||
|
app.get '/data', (req,res) -> res.json data
|
||||||
|
app.listen 3000
|
||||||
|
console.log chalk.green('Started Web Server'), 'on port', chalk.bold(3000)
|
||||||
|
|
||||||
|
|
||||||
cli.parse process.argv
|
cli.parse process.argv
|
||||||
|
|
||||||
if !didSomething then console.log chalk.green('Tip:'), 'see', chalk.bold(cli.name()+' --help')
|
if !didSomething then console.log chalk.green('Tip:'), 'see', chalk.bold(cli.name()+' --help')
|
||||||
|
17
src/pert-ui.coffee
Normal file
17
src/pert-ui.coffee
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
$.get 'data', (data) ->
|
||||||
|
console.log data
|
||||||
|
i = 0
|
||||||
|
nodes = data.days.map (x) -> {id: x, label: ""+x}
|
||||||
|
connections = []
|
||||||
|
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)+")"
|
||||||
|
if x.permittedDelay > 0
|
||||||
|
connections.push from: x.endDay, to: x.endDay+x.permittedDelay, color: 'green', label: "("+x.permittedDelay+")"
|
||||||
|
console.log nodes
|
||||||
|
console.log connections
|
||||||
|
options =
|
||||||
|
edges:
|
||||||
|
style: 'arrow'
|
||||||
|
network = new vis.Network (document.getElementById 'pert'), { nodes: nodes, edges: connections }, options
|
@ -3,6 +3,7 @@ fs = require 'fs'
|
|||||||
|
|
||||||
module.exports = class Pert
|
module.exports = class Pert
|
||||||
constructor: (@list, @verbose) ->
|
constructor: (@list, @verbose) ->
|
||||||
|
@days = []
|
||||||
|
|
||||||
log: (x...) -> if @verbose then console.log chalk.bold("Pert:"), x...
|
log: (x...) -> if @verbose then console.log chalk.bold("Pert:"), x...
|
||||||
err: (x...) -> console.log chalk.bold (chalk.red "Pert:"), x...
|
err: (x...) -> console.log chalk.bold (chalk.red "Pert:"), x...
|
||||||
@ -25,11 +26,14 @@ module.exports = class Pert
|
|||||||
@log "start day of",item.id,"is",item.startDay
|
@log "start day of",item.id,"is",item.startDay
|
||||||
item.endDay = item.startDay + item.duration
|
item.endDay = item.startDay + item.duration
|
||||||
@log "end day of",item.id,"is",item.endDay
|
@log "end day of",item.id,"is",item.endDay
|
||||||
|
@insertDay item.endDay
|
||||||
return item.endDay
|
return item.endDay
|
||||||
|
|
||||||
# Find out which day the activity starts
|
# Find out which day the activity starts
|
||||||
calculateStartDay: (item) =>
|
calculateStartDay: (item) =>
|
||||||
if !item.depends? or item.depends.length is 0 then return item.startDay = 0
|
if !item.depends? or item.depends.length is 0
|
||||||
|
@insertDay 0
|
||||||
|
return item.startDay = 0
|
||||||
item.startDay = @maxa item.depends.map(@toActivity).map @calculateEndDay
|
item.startDay = @maxa item.depends.map(@toActivity).map @calculateEndDay
|
||||||
@log "start day of",item.id,"is",item.startDay
|
@log "start day of",item.id,"is",item.startDay
|
||||||
# write max delay time to each depend
|
# write max delay time to each depend
|
||||||
@ -41,11 +45,20 @@ module.exports = class Pert
|
|||||||
@log "written permittedDelay to dependency", x, "of", item, "as", i.permittedDelay
|
@log "written permittedDelay to dependency", x, "of", item, "as", i.permittedDelay
|
||||||
else @log "aborting permittedDelay: already calculated"
|
else @log "aborting permittedDelay: already calculated"
|
||||||
@log "permitted delay of",x,"is",i.permittedDelay
|
@log "permitted delay of",x,"is",i.permittedDelay
|
||||||
|
@insertDay item.startDay
|
||||||
return item.startDay
|
return item.startDay
|
||||||
|
|
||||||
# Find out which activity has the highest id
|
# Find out which activity has the highest id
|
||||||
highestID: => return @maxa(@list.map (x) -> x.id)
|
highestID: => return @maxa(@list.map (x) -> x.id)
|
||||||
|
|
||||||
|
# Insert a day to the list of days if it's not there already
|
||||||
|
insertDay: (day) =>
|
||||||
|
for d in @days
|
||||||
|
if day is d then return
|
||||||
|
@days.push day
|
||||||
|
|
||||||
calculate: (options) ->
|
calculate: (options) ->
|
||||||
@calculateEndDay @toActivity @highestID()
|
@calculateEndDay @toActivity @highestID()
|
||||||
if options?.json then JSON.stringify @list else @list
|
results = activities: @list, days: @days
|
||||||
|
if options?.json then JSON.stringify results else results
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user