diff --git a/pert b/pert index daa1acc..ac4c055 100755 --- a/pert +++ b/pert @@ -2,7 +2,7 @@ set -o nounset set -o errexit -function _echo +function _echo { echo -e "$1" } @@ -12,6 +12,11 @@ function _echoB _echo "\033[1m$1\033[0m" } +red=$(tput setaf 1) +green=$(tput setaf 2) +yellow=$(tput setaf 3) +normal=$(tput sgr0) + function _help { _echo "" @@ -29,7 +34,7 @@ function _help } scale=2 -function _calc +function _calc { _echo "scale=$scale; $@" | bc -l | sed 's/^\./0./' } @@ -42,7 +47,7 @@ function _divider printf "%$width.${width}s+\n" "$divider" } -readonly format=" | %-12s |%11s |%10s |%12s |%9s |%9s |%9s |\n" +readonly format=" | %-12s |${green}%11s${normal} |%10s |${red}%12s${normal} |%9s |${yellow}%9s${normal} |%9s |\n" function _header { _echo "" @@ -53,78 +58,79 @@ function _header _divider } + function pert_table { _header - + counter=0 total_estimate=0 total_standard_deviation=0 total_variance=0 for var in "$@"; do - + # counter iterator counter=$[$counter +1] - + # split values IFS=',' read -ra ADDR <<< "$var" - + # optimistic value o="0" if [ -n "${ADDR[0]-}" ]; then o=${ADDR[0]} fi - + # realistic value r="0" if [ -n "${ADDR[1]-}" ]; then r=${ADDR[1]} fi - + # pessimistic value p="0" if [ -n "${ADDR[2]-}" ]; then p=${ADDR[2]} fi - + # check values if [ -z "$o" ] || [ -z "$r" ] || [ -z "$p" ]; then printf "$format" "$counter. bad input" $o $r $p else - + # pert estimate pert_estimate=$(_calc "($o+4*$r+$p)/6") - total_estimate=$(_calc "$total_estimate + $pert_estimate") - + total_estimate=$(_calc "$total_estimate + $pert_estimate") + # standard deviation standard_deviation=$(_calc "($p-$o)/6") total_standard_deviation=$(_calc "$total_standard_deviation + $standard_deviation") - + # variance variance=$(_calc "$standard_deviation * $standard_deviation") total_variance=$(_calc "$total_variance + $variance") - - # row + + # row printf "$format" "$counter. task" $o $r $p $pert_estimate $standard_deviation $variance fi - + done - + _divider - + if [[ $total_estimate > 0 ]]; then - - # footer summary + + # footer summary printf "$format" "summary" "-" "-" "-" $total_estimate $total_standard_deviation $total_variance _divider - + _echo "" _echoB "Three point estimates" _echo "" - - width=42 + + width=42 tpeformat=" | %-13s |%11s |%10s |\n" - + _divider printf "$tpeformat" "confidence" _divider @@ -132,9 +138,9 @@ function pert_table printf "$tpeformat" "2 Sigma - 95%" $(_calc "$total_estimate - 2 * $total_standard_deviation") $(_calc "$total_estimate + 2 * $total_standard_deviation") printf "$tpeformat" "3 Sigma - 99%" $(_calc "$total_estimate - 3 * $total_standard_deviation") $(_calc "$total_estimate + 3 * $total_standard_deviation") _divider - + fi - + _echo "" }