|
@@ -1,21 +1,38 @@
|
1
|
1
|
#!/bin/bash
|
|
2
|
+set -o nounset
|
|
3
|
+set -o errexit
|
2
|
4
|
|
3
|
|
-# help text
|
4
|
|
-if [ -z "$1" ] || [[ "$1" =~ [-]*(help|h) ]]; then
|
5
|
|
- echo -e "\n\033[1mA command line PERT calculator for quick estimates.\033[0m"
|
6
|
|
- echo -e "\nComma separated task list in the form \"1,2,12 4,5,9 2,3,6\", where whitespace separates tasks."
|
7
|
|
- echo -e "\n\033[1mUsage:\033[0m\n\tpert.sh [optimistic,realistic,pessimistic]\n"
|
8
|
|
- echo -e "\033[1mExample:\033[0m"
|
9
|
|
- echo -e "\tpert.sh 1,3,4"
|
10
|
|
- echo -e "\tpert.sh 10,15,20 5,7,10"
|
11
|
|
- echo -e "\tpert.sh \"1,2,3\" \"15,17,20\"\n"
|
|
5
|
+function _echo
|
|
6
|
+{
|
|
7
|
+ echo -e "$1"
|
|
8
|
+}
|
|
9
|
+
|
|
10
|
+function _echoB
|
|
11
|
+{
|
|
12
|
+ _echo "\033[1m$1\033[0m"
|
|
13
|
+}
|
|
14
|
+
|
|
15
|
+function _help
|
|
16
|
+{
|
|
17
|
+ _echo ""
|
|
18
|
+ _echoB "A command line PERT calculator for quick estimates."
|
|
19
|
+ _echo "Comma separated task list in the form \"1,2,12 4,5,9 2,3,6\", where whitespace separates tasks."
|
|
20
|
+ _echo ""
|
|
21
|
+ _echoB "Usage:"
|
|
22
|
+ _echo "\tpert.sh [optimistic,realistic,pessimistic]"
|
|
23
|
+ _echo ""
|
|
24
|
+ _echoB "Example:"
|
|
25
|
+ _echo "\tpert.sh 1,3,4"
|
|
26
|
+ _echo "\tpert.sh 10,15,20 5,7,10"
|
|
27
|
+ _echo "\tpert.sh \"1,2,3\" \"15,17,20\""
|
|
28
|
+ _echo ""
|
12
|
29
|
exit 1
|
13
|
|
-fi
|
|
30
|
+}
|
14
|
31
|
|
|
32
|
+scale=2
|
15
|
33
|
function _calc
|
16
|
34
|
{
|
17
|
|
- scale=2
|
18
|
|
- echo "scale=$scale; $@" | bc -l | sed 's/^\./0./'
|
|
35
|
+ _echo "scale=$scale; $@" | bc -l | sed 's/^\./0./'
|
19
|
36
|
}
|
20
|
37
|
|
21
|
38
|
width=88
|
|
@@ -23,17 +40,27 @@ function _divider
|
23
|
40
|
{
|
24
|
41
|
divider=------------------------------
|
25
|
42
|
divider=" +"$divider$divider$divider"+"
|
26
|
|
-
|
27
|
43
|
printf "%$width.${width}s+\n" "$divider"
|
28
|
44
|
}
|
29
|
45
|
|
30
|
|
-format=" | %-12s |%11s |%10s |%12s |%9s |%9s |%9s |\n"
|
|
46
|
+readonly format=" | %-12s |%11s |%10s |%12s |%9s |%9s |%9s |\n"
|
|
47
|
+function _header
|
|
48
|
+{
|
|
49
|
+ _echo ""
|
|
50
|
+ _echoB "Tasks"
|
|
51
|
+ _echo ""
|
|
52
|
+ _divider
|
|
53
|
+ printf "$format" "#" "optimistic" "realistic" "pessimistic" "duration" "risk" "variance"
|
|
54
|
+ _divider
|
|
55
|
+}
|
31
|
56
|
|
32
|
|
-# header
|
33
|
|
-echo -e "\n\033[1mTasks\033[0m\n"
|
34
|
|
-_divider
|
35
|
|
-printf "$format" "#" "optimistic" "realistic" "pessimistic" "duration" "risk" "variance"
|
36
|
|
-_divider
|
|
57
|
+# help text
|
|
58
|
+if [ $# -eq 0 ] || [ -z "$1" ] || [[ "$1" =~ [-]*(help|h) ]]; then
|
|
59
|
+ _help
|
|
60
|
+fi
|
|
61
|
+
|
|
62
|
+# main
|
|
63
|
+_header
|
37
|
64
|
|
38
|
65
|
counter=0
|
39
|
66
|
total_estimate=0
|
|
@@ -48,13 +75,22 @@ for var in "$@"; do
|
48
|
75
|
IFS=',' read -ra ADDR <<< "$var"
|
49
|
76
|
|
50
|
77
|
# optimistic value
|
51
|
|
- o=${ADDR[0]}
|
|
78
|
+ o="0"
|
|
79
|
+ if [ -n "${ADDR[0]-}" ]; then
|
|
80
|
+ o=${ADDR[0]}
|
|
81
|
+ fi
|
52
|
82
|
|
53
|
83
|
# realistic value
|
54
|
|
- r=${ADDR[1]}
|
|
84
|
+ r="0"
|
|
85
|
+ if [ -n "${ADDR[1]-}" ]; then
|
|
86
|
+ r=${ADDR[1]}
|
|
87
|
+ fi
|
55
|
88
|
|
56
|
89
|
# pessimistic value
|
57
|
|
- p=${ADDR[2]}
|
|
90
|
+ p="0"
|
|
91
|
+ if [ -n "${ADDR[2]-}" ]; then
|
|
92
|
+ p=${ADDR[2]}
|
|
93
|
+ fi
|
58
|
94
|
|
59
|
95
|
# check values
|
60
|
96
|
if [ -z "$o" ] || [ -z "$r" ] || [ -z "$p" ]; then
|
|
@@ -83,11 +119,13 @@ _divider
|
83
|
119
|
|
84
|
120
|
if [[ $total_estimate > 0 ]]; then
|
85
|
121
|
|
86
|
|
- # footer
|
|
122
|
+ # footer summary
|
87
|
123
|
printf "$format" "summary" "-" "-" "-" $total_estimate $total_standard_deviation $total_variance
|
88
|
124
|
_divider
|
89
|
125
|
|
90
|
|
- echo -e "\n\033[1mThree point estimates\033[0m\n"
|
|
126
|
+ _echo ""
|
|
127
|
+ _echoB "Three point estimates"
|
|
128
|
+ _echo ""
|
91
|
129
|
|
92
|
130
|
width=42
|
93
|
131
|
tpeformat=" | %-13s |%11s |%10s |\n"
|
|
@@ -102,4 +140,4 @@ if [[ $total_estimate > 0 ]]; then
|
102
|
140
|
|
103
|
141
|
fi
|
104
|
142
|
|
105
|
|
-echo -e "\n"
|
|
143
|
+_echo ""
|