Browse Source

Merge pull request #5 from Varpie/colors

Adding colors using tput, thanks!
Lukáš Mešťan 7 years ago
parent
commit
3d778753a8
1 changed files with 33 additions and 27 deletions
  1. 33
    27
      pert

+ 33
- 27
pert View File

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

Loading…
Cancel
Save