|
@@ -3,19 +3,34 @@
|
3
|
3
|
# help text
|
4
|
4
|
if [ -z "$1" ] || [[ "$1" =~ [-]*(help|h) ]]; then
|
5
|
5
|
echo -e "\nA command line PERT calculator for quick estimates."
|
6
|
|
- echo -e "Comma separated task list in the form \"1,2,12 4,5,9 2,3,6\", where whitespace separates tasks.\n"
|
7
|
|
- echo -e "Usage:\n\tpert [optimistic,realistic,pessimistic]\n"
|
|
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 "\nUsage:\n\tpert [optimistic,realistic,pessimistic]\n"
|
|
8
|
+ echo -e "Example:"
|
|
9
|
+ echo -e "\tpert 1,3,4"
|
|
10
|
+ echo -e "\tpert 10,15,20 5,7,10"
|
|
11
|
+ echo -e "\tpert \"1,2,3\" \"15,17,20\"\n"
|
8
|
12
|
exit 1
|
9
|
13
|
fi
|
10
|
14
|
|
|
15
|
+# helper
|
|
16
|
+function _calc
|
|
17
|
+{
|
|
18
|
+ scale=2
|
|
19
|
+ echo "scale=$scale; $@" | bc -l | sed 's/^\./0./'
|
|
20
|
+}
|
|
21
|
+
|
|
22
|
+function _divider
|
|
23
|
+{
|
|
24
|
+ divider=------------------------------
|
|
25
|
+ divider=" "$divider$divider$divider
|
|
26
|
+ width=83
|
|
27
|
+
|
|
28
|
+ printf "%$width.${width}s\n" "$divider"
|
|
29
|
+}
|
|
30
|
+
|
11
|
31
|
header="\n %-12s |%11s |%10s |%12s |%9s |%7s |%9s\n"
|
12
|
32
|
format=" %-12s |%11s |%10s |%12s |%9s |%7s |%9s\n"
|
13
|
33
|
|
14
|
|
-divider=------------------------------
|
15
|
|
-divider=" "$divider$divider$divider
|
16
|
|
-width=83
|
17
|
|
-
|
18
|
|
-scale=2
|
19
|
34
|
counter=0
|
20
|
35
|
total_estimate=0
|
21
|
36
|
total_standard_deviation=0
|
|
@@ -39,27 +54,26 @@ for var in "$@"; do
|
39
|
54
|
|
40
|
55
|
# header
|
41
|
56
|
if [[ $counter = 1 ]]; then
|
42
|
|
- printf "$header" "task" "optimistic" "realistic" "pessimistic" "duration" "risk" "variance"
|
43
|
|
- printf "%$width.${width}s\n" "$divider"
|
|
57
|
+ printf "$header" "#" "optimistic" "realistic" "pessimistic" "duration" "risk" "variance"
|
|
58
|
+ _divider
|
44
|
59
|
fi
|
45
|
60
|
|
46
|
61
|
# check values
|
47
|
62
|
if [ -z "$o" ] || [ -z "$r" ] || [ -z "$p" ]; then
|
48
|
|
- #echo -e "\tbad input [$o,$r,$p]"
|
49
|
63
|
printf "$format" "$counter. bad input" $o $r $p
|
50
|
64
|
else
|
51
|
65
|
|
52
|
66
|
# pert estimate
|
53
|
|
- pert_estimate=$(echo "scale=$scale; ($o+4*$r+$p)/6" | bc -l | sed 's/^\./0./')
|
54
|
|
- total_estimate=$(echo "scale=$scale; $total_estimate + $pert_estimate" | bc -l | sed 's/^\./0./')
|
|
67
|
+ pert_estimate=$(_calc "($o+4*$r+$p)/6")
|
|
68
|
+ total_estimate=$(_calc "$total_estimate + $pert_estimate")
|
55
|
69
|
|
56
|
70
|
# standard deviation
|
57
|
|
- standard_deviation=$(echo "scale=$scale; ($p-$o)/6" | bc -l | sed 's/^\./0./')
|
58
|
|
- total_standard_deviation=$(echo "scale=$scale; $total_standard_deviation + $standard_deviation" | bc | sed 's/^\./0./')
|
|
71
|
+ standard_deviation=$(_calc "($p-$o)/6")
|
|
72
|
+ total_standard_deviation=$(_calc "$total_standard_deviation + $standard_deviation")
|
59
|
73
|
|
60
|
74
|
# variance
|
61
|
|
- variance=$(echo "scale=$scale; $standard_deviation*$standard_deviation" | bc -l | sed 's/^\./0./')
|
62
|
|
- total_variance=$(echo "scale=$scale; $total_variance + $variance" | bc | sed 's/^\./0./')
|
|
75
|
+ variance=$(_calc "$standard_deviation * $standard_deviation")
|
|
76
|
+ total_variance=$(_calc "$total_variance + $variance")
|
63
|
77
|
|
64
|
78
|
# row
|
65
|
79
|
printf "$format" "$counter. task" $o $r $p $pert_estimate $standard_deviation $variance
|
|
@@ -70,7 +84,7 @@ done
|
70
|
84
|
if [[ $total_estimate > 0 ]]; then
|
71
|
85
|
|
72
|
86
|
# footer
|
73
|
|
- printf "%$width.${width}s\n" "$divider"
|
|
87
|
+ _divider
|
74
|
88
|
printf "$format" "summary" "-" "-" "-" $total_estimate $total_standard_deviation $total_variance
|
75
|
89
|
|
76
|
90
|
echo -e "\nThree point estimate:"
|