mirror of
https://github.com/fazo96/pbs.git
synced 2025-01-29 14:54:18 +01:00
release ready
This commit is contained in:
parent
063fa2121a
commit
ecfaf08b46
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
test/
|
||||||
bin/
|
bin/
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
src/
|
src/
|
||||||
|
test.json
|
||||||
build.sh
|
build.sh
|
||||||
|
68
README.md
Normal file
68
README.md
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# Pert
|
||||||
|
|
||||||
|
Pert is a command line tool built to assist in the process of creating pert diagrams and calculating permitted delays.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Make sure you have `node` and `npm` installed and working
|
||||||
|
|
||||||
|
__From git__
|
||||||
|
|
||||||
|
1. clone this repo and run `build.sh`
|
||||||
|
2. run `bin/pert`
|
||||||
|
|
||||||
|
__From npm__
|
||||||
|
|
||||||
|
1. `npm install -g pert`
|
||||||
|
2. run `pert` in your shell
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Usage: pert loads activity data from JSON and computes the possible activity delays
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
|
||||||
|
example show an example of the JSON data format
|
||||||
|
calculate|c [options] <file> calculate data on given JSON document
|
||||||
|
|
||||||
|
Options:
|
||||||
|
|
||||||
|
-h, --help output usage information
|
||||||
|
-V, --version output the version number
|
||||||
|
--verbose be verbose (for debugging)
|
||||||
|
|
||||||
|
This is the help information for the `pert calculate` command:
|
||||||
|
|
||||||
|
Usage: calculate|c [options] <file>
|
||||||
|
|
||||||
|
calculate data on given JSON document
|
||||||
|
|
||||||
|
Options:
|
||||||
|
|
||||||
|
-h, --help output usage information
|
||||||
|
-j, --json output json data
|
||||||
|
|
||||||
|
## Data format
|
||||||
|
|
||||||
|
This is a valid input document:
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{"id": 0, "duration": 3},
|
||||||
|
{"id": 1, "duration": 1},
|
||||||
|
{"id": 2, "duration": 2, "depends": [0]},
|
||||||
|
{"id": 3, "duration": 5, "depends": [1]},
|
||||||
|
{"id": 4, "duration": 5, "depends": [1]},
|
||||||
|
{"id": 5, "duration": 2, "depends": [2,3,4]}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
And this is the output of the `calculate` command on the previous document using the `--json` flag:
|
||||||
|
|
||||||
|
```json
|
||||||
|
[{"id":0,"duration":3,"startDay":0,"endDay":3,"permittedDelay":0},{"id":1,"duration":1,"startDay":0,"endDay":1,"permittedDelay":0},{"id":2,"duration":2,"depends":[0],"startDay":3,"endDay":5,"permittedDelay":1},{"id":3,"duration":5,"depends":[1],"startDay":1,"endDay":6,"permittedDelay":0},{"id":4,"duration":5,"depends":[1],"startDay":1,"endDay":6,"permittedDelay":0},{"id":5,"duration":2,"depends":[2,3,4],"startDay":6,"endDay":8}]
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pert",
|
"name": "pert",
|
||||||
"version": "0.0.1",
|
"version": "0.1.0",
|
||||||
"description": "pert diagram calculator",
|
"description": "pert diagram calculator",
|
||||||
"main": "pert.coffee",
|
"main": "pert.coffee",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env coffee
|
#!/usr/bin/env coffee
|
||||||
chalk = require 'chalk'
|
chalk = require 'chalk'
|
||||||
|
cli = require 'commander'
|
||||||
|
fs = require 'fs'
|
||||||
|
|
||||||
verbose = no
|
log = (x...) -> if cli.verbose then console.log chalk.bold("Log:"), x...
|
||||||
|
|
||||||
log = (x...) -> if verbose then console.log chalk.bold("Log:"), x...
|
|
||||||
err = (x...) -> console.log chalk.bold (chalk.red "Error:"), x...
|
err = (x...) -> console.log chalk.bold (chalk.red "Error:"), x...
|
||||||
|
|
||||||
# Returns the highest number in an array of numbers
|
# Returns the highest number in an array of numbers
|
||||||
@ -28,16 +28,19 @@ calculateEndDay = (item,list) ->
|
|||||||
|
|
||||||
# Find out which day the activity starts
|
# Find out which day the activity starts
|
||||||
calculateStartDay = (item,list) ->
|
calculateStartDay = (item,list) ->
|
||||||
if item.depends.length is 0 then return item.startDay = 0
|
if !item.depends? or item.depends.length is 0 then return item.startDay = 0
|
||||||
max = maxa item.depends.map((x) -> toActivity x,list).map((x) -> calculateEndDay x, list)
|
item.startDay = maxa item.depends.map((x) -> toActivity x,list).map((x) -> calculateEndDay x, list)
|
||||||
log "start day of",item.id,"is",max
|
log "start day of",item.id,"is",item.startDay
|
||||||
# write max delay time to each depend
|
# write max delay time to each depend
|
||||||
item.depends.forEach (x) ->
|
item.depends.forEach (x) ->
|
||||||
log "writing permittedDelay to dependency", x, "of", item
|
log "checking permittedDelay to dependency", x, "of", item
|
||||||
i = toActivity x, list
|
i = toActivity x, list
|
||||||
i.permittedDelay = max - calculateEndDay i, list
|
if !i.permittedDelay?
|
||||||
|
i.permittedDelay = item.startDay - calculateEndDay i, list
|
||||||
|
log "written permittedDelay to dependency", x, "of", item, "as", i.permittedDelay
|
||||||
|
else log "aborting permittedDelay: already calculated"
|
||||||
log "permitted delay of",x,"is",i.permittedDelay
|
log "permitted delay of",x,"is",i.permittedDelay
|
||||||
return item.startDay = max
|
return item.startDay
|
||||||
|
|
||||||
# Find out which activity has the highest id
|
# Find out which activity has the highest id
|
||||||
highestID = (list) -> return maxa(list.map (x) -> x.id)
|
highestID = (list) -> return maxa(list.map (x) -> x.id)
|
||||||
@ -47,4 +50,36 @@ calculate = (list) ->
|
|||||||
return list
|
return list
|
||||||
|
|
||||||
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}]
|
||||||
console.log calculate ex
|
|
||||||
|
cli
|
||||||
|
.version '0.1'
|
||||||
|
.usage 'loads activity data from JSON and computes the possible activity delays'
|
||||||
|
.option '--verbose', 'be verbose (for debugging)'
|
||||||
|
|
||||||
|
didSomething = no
|
||||||
|
|
||||||
|
cli
|
||||||
|
.command 'example'
|
||||||
|
.description 'show an example of the JSON data format'
|
||||||
|
.action ->
|
||||||
|
didSomething = yes
|
||||||
|
console.log chalk.bold.green('Before:'), ex
|
||||||
|
console.log chalk.bold.green('After calculations:'), calculate ex
|
||||||
|
console.log chalk.green 'Tip:',chalk.bold 'optional fields can be freely included in the input data'
|
||||||
|
|
||||||
|
cli
|
||||||
|
.command 'calculate <file>'
|
||||||
|
.description 'calculate data on given JSON document'
|
||||||
|
.alias 'c'
|
||||||
|
.option '-j, --json', 'output json data'
|
||||||
|
.action (file,options) ->
|
||||||
|
didSomething = yes
|
||||||
|
fs.readFile file, (error,content) ->
|
||||||
|
if error then err error
|
||||||
|
else
|
||||||
|
if options.json then console.log JSON.stringify (calculate JSON.parse(content))
|
||||||
|
else console.log calculate JSON.parse(content)
|
||||||
|
|
||||||
|
cli.parse process.argv
|
||||||
|
|
||||||
|
if !didSomething then console.log chalk.green('Tip:'), 'see', chalk.bold(cli.name()+' --help')
|
||||||
|
Loading…
Reference in New Issue
Block a user