Browse Source

rename file

arzzen 8 years ago
parent
commit
8f86752f5c
2 changed files with 155 additions and 158 deletions
  1. 155
    1
      pert
  2. 0
    157
      pert.sh

+ 155
- 1
pert View File

1
 #!/bin/bash
1
 #!/bin/bash
2
+set -o nounset
3
+set -o errexit
2
 
4
 
3
-. pert.sh
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 ""
29
+}
30
+
31
+scale=2
32
+function _calc 
33
+{
34
+    _echo "scale=$scale; $@" | bc -l | sed 's/^\./0./'
35
+}
36
+
37
+width=88
38
+function _divider
39
+{
40
+    divider=------------------------------
41
+    divider=" +"$divider$divider$divider"+"
42
+    printf "%$width.${width}s+\n" "$divider"
43
+}
44
+
45
+readonly format=" | %-12s |%11s |%10s |%12s |%9s |%9s |%9s |\n"
46
+function _header
47
+{
48
+    _echo ""
49
+    _echoB "Tasks"
50
+    _echo ""
51
+    _divider
52
+    printf "$format" "#" "optimistic" "realistic" "pessimistic" "duration" "risk" "variance"
53
+    _divider
54
+}
55
+
56
+function pert_table
57
+{
58
+    _header
59
+    
60
+    counter=0
61
+    total_estimate=0
62
+    total_standard_deviation=0
63
+    total_variance=0
64
+    for var in "$@"; do
65
+        
66
+        # counter iterator
67
+        counter=$[$counter +1]
68
+    
69
+        # split values
70
+        IFS=',' read -ra ADDR <<< "$var"
71
+        
72
+        # optimistic value
73
+        o="0"
74
+        if [ -n "${ADDR[0]-}" ]; then
75
+            o=${ADDR[0]}
76
+        fi
77
+        
78
+        # realistic value
79
+        r="0"
80
+        if [ -n "${ADDR[1]-}" ]; then
81
+            r=${ADDR[1]}
82
+        fi
83
+        
84
+        # pessimistic value
85
+        p="0"
86
+        if [ -n "${ADDR[2]-}" ]; then
87
+            p=${ADDR[2]}
88
+        fi
89
+        
90
+        # check values
91
+        if [ -z "$o" ] || [ -z "$r" ] || [ -z "$p" ]; then
92
+            printf "$format" "$counter. bad input" $o $r $p
93
+        else
94
+        
95
+            # pert estimate
96
+            pert_estimate=$(_calc "($o+4*$r+$p)/6")
97
+            total_estimate=$(_calc "$total_estimate + $pert_estimate") 
98
+            
99
+            # standard deviation
100
+            standard_deviation=$(_calc "($p-$o)/6")
101
+            total_standard_deviation=$(_calc "$total_standard_deviation + $standard_deviation")
102
+    
103
+            # variance
104
+            variance=$(_calc "$standard_deviation * $standard_deviation")
105
+            total_variance=$(_calc "$total_variance + $variance")
106
+        
107
+            # row        
108
+            printf "$format" "$counter. task" $o $r $p $pert_estimate $standard_deviation $variance
109
+        fi
110
+    
111
+    done
112
+    
113
+    _divider
114
+    
115
+    if [[ $total_estimate > 0 ]]; then
116
+        
117
+        # footer summary       
118
+        printf "$format" "summary" "-" "-" "-" $total_estimate $total_standard_deviation $total_variance
119
+        _divider
120
+        
121
+        _echo ""
122
+        _echoB "Three point estimates"
123
+        _echo ""
124
+        
125
+        width=42 
126
+        tpeformat=" | %-13s |%11s |%10s |\n"
127
+        
128
+        _divider
129
+        printf "$tpeformat" "confidence"
130
+        _divider
131
+        printf "$tpeformat" "1 Sigma - 68%" $(_calc "$total_estimate - $total_standard_deviation") $(_calc "$total_estimate + $total_standard_deviation")
132
+        printf "$tpeformat" "2 Sigma - 95%" $(_calc "$total_estimate - 2 * $total_standard_deviation") $(_calc "$total_estimate + 2 * $total_standard_deviation")
133
+        printf "$tpeformat" "3 Sigma - 99%" $(_calc "$total_estimate - 3 * $total_standard_deviation") $(_calc "$total_estimate + 3 * $total_standard_deviation")
134
+        _divider
135
+    
136
+    fi
137
+    
138
+    _echo ""
139
+}
140
+
141
+
142
+# main
143
+if [ $# -eq 0 ]; then
144
+    _help
145
+    exit 1
146
+fi
147
+
148
+case "$1" in
149
+  *help|*h)
150
+    _help
151
+    exit 1
152
+    ;;
153
+  *)
154
+    pert_table $@
155
+    exit 0
156
+    ;;
157
+esac

+ 0
- 157
pert.sh View File

1
-#!/bin/bash
2
-set -o nounset
3
-set -o errexit
4
-
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 ""
29
-}
30
-
31
-scale=2
32
-function _calc 
33
-{
34
-    _echo "scale=$scale; $@" | bc -l | sed 's/^\./0./'
35
-}
36
-
37
-width=88
38
-function _divider
39
-{
40
-    divider=------------------------------
41
-    divider=" +"$divider$divider$divider"+"
42
-    printf "%$width.${width}s+\n" "$divider"
43
-}
44
-
45
-readonly format=" | %-12s |%11s |%10s |%12s |%9s |%9s |%9s |\n"
46
-function _header
47
-{
48
-    _echo ""
49
-    _echoB "Tasks"
50
-    _echo ""
51
-    _divider
52
-    printf "$format" "#" "optimistic" "realistic" "pessimistic" "duration" "risk" "variance"
53
-    _divider
54
-}
55
-
56
-function pert_table
57
-{
58
-    _header
59
-    
60
-    counter=0
61
-    total_estimate=0
62
-    total_standard_deviation=0
63
-    total_variance=0
64
-    for var in "$@"; do
65
-        
66
-        # counter iterator
67
-        counter=$[$counter +1]
68
-    
69
-        # split values
70
-        IFS=',' read -ra ADDR <<< "$var"
71
-        
72
-        # optimistic value
73
-        o="0"
74
-        if [ -n "${ADDR[0]-}" ]; then
75
-            o=${ADDR[0]}
76
-        fi
77
-        
78
-        # realistic value
79
-        r="0"
80
-        if [ -n "${ADDR[1]-}" ]; then
81
-            r=${ADDR[1]}
82
-        fi
83
-        
84
-        # pessimistic value
85
-        p="0"
86
-        if [ -n "${ADDR[2]-}" ]; then
87
-            p=${ADDR[2]}
88
-        fi
89
-        
90
-        # check values
91
-        if [ -z "$o" ] || [ -z "$r" ] || [ -z "$p" ]; then
92
-            printf "$format" "$counter. bad input" $o $r $p
93
-        else
94
-        
95
-            # pert estimate
96
-            pert_estimate=$(_calc "($o+4*$r+$p)/6")
97
-            total_estimate=$(_calc "$total_estimate + $pert_estimate") 
98
-            
99
-            # standard deviation
100
-            standard_deviation=$(_calc "($p-$o)/6")
101
-            total_standard_deviation=$(_calc "$total_standard_deviation + $standard_deviation")
102
-    
103
-            # variance
104
-            variance=$(_calc "$standard_deviation * $standard_deviation")
105
-            total_variance=$(_calc "$total_variance + $variance")
106
-        
107
-            # row        
108
-            printf "$format" "$counter. task" $o $r $p $pert_estimate $standard_deviation $variance
109
-        fi
110
-    
111
-    done
112
-    
113
-    _divider
114
-    
115
-    if [[ $total_estimate > 0 ]]; then
116
-        
117
-        # footer summary       
118
-        printf "$format" "summary" "-" "-" "-" $total_estimate $total_standard_deviation $total_variance
119
-        _divider
120
-        
121
-        _echo ""
122
-        _echoB "Three point estimates"
123
-        _echo ""
124
-        
125
-        width=42 
126
-        tpeformat=" | %-13s |%11s |%10s |\n"
127
-        
128
-        _divider
129
-        printf "$tpeformat" "confidence"
130
-        _divider
131
-        printf "$tpeformat" "1 Sigma - 68%" $(_calc "$total_estimate - $total_standard_deviation") $(_calc "$total_estimate + $total_standard_deviation")
132
-        printf "$tpeformat" "2 Sigma - 95%" $(_calc "$total_estimate - 2 * $total_standard_deviation") $(_calc "$total_estimate + 2 * $total_standard_deviation")
133
-        printf "$tpeformat" "3 Sigma - 99%" $(_calc "$total_estimate - 3 * $total_standard_deviation") $(_calc "$total_estimate + 3 * $total_standard_deviation")
134
-        _divider
135
-    
136
-    fi
137
-    
138
-    _echo ""
139
-}
140
-
141
-
142
-# main
143
-if [ $# -eq 0 ]; then
144
-    _help
145
-    exit 1
146
-fi
147
-
148
-case "$1" in
149
-  *help|*h)
150
-    _help
151
-    exit 1
152
-    ;;
153
-  *)
154
-    pert_table $@
155
-    exit 0
156
-    ;;
157
-esac

Loading…
Cancel
Save