helper function
This commit is contained in:
parent
252a7147c6
commit
07a6571948
1 changed files with 31 additions and 17 deletions
48
pert
48
pert
|
|
@ -3,19 +3,34 @@
|
||||||
# help text
|
# help text
|
||||||
if [ -z "$1" ] || [[ "$1" =~ [-]*(help|h) ]]; then
|
if [ -z "$1" ] || [[ "$1" =~ [-]*(help|h) ]]; then
|
||||||
echo -e "\nA command line PERT calculator for quick estimates."
|
echo -e "\nA command line PERT calculator for quick estimates."
|
||||||
echo -e "Comma separated task list in the form \"1,2,12 4,5,9 2,3,6\", where whitespace separates tasks.\n"
|
echo -e "\nComma separated task list in the form \"1,2,12 4,5,9 2,3,6\", where whitespace separates tasks."
|
||||||
echo -e "Usage:\n\tpert [optimistic,realistic,pessimistic]\n"
|
echo -e "\nUsage:\n\tpert [optimistic,realistic,pessimistic]\n"
|
||||||
|
echo -e "Example:"
|
||||||
|
echo -e "\tpert 1,3,4"
|
||||||
|
echo -e "\tpert 10,15,20 5,7,10"
|
||||||
|
echo -e "\tpert \"1,2,3\" \"15,17,20\"\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# helper
|
||||||
|
function _calc
|
||||||
|
{
|
||||||
|
scale=2
|
||||||
|
echo "scale=$scale; $@" | bc -l | sed 's/^\./0./'
|
||||||
|
}
|
||||||
|
|
||||||
|
function _divider
|
||||||
|
{
|
||||||
|
divider=------------------------------
|
||||||
|
divider=" "$divider$divider$divider
|
||||||
|
width=83
|
||||||
|
|
||||||
|
printf "%$width.${width}s\n" "$divider"
|
||||||
|
}
|
||||||
|
|
||||||
header="\n %-12s |%11s |%10s |%12s |%9s |%7s |%9s\n"
|
header="\n %-12s |%11s |%10s |%12s |%9s |%7s |%9s\n"
|
||||||
format=" %-12s |%11s |%10s |%12s |%9s |%7s |%9s\n"
|
format=" %-12s |%11s |%10s |%12s |%9s |%7s |%9s\n"
|
||||||
|
|
||||||
divider=------------------------------
|
|
||||||
divider=" "$divider$divider$divider
|
|
||||||
width=83
|
|
||||||
|
|
||||||
scale=2
|
|
||||||
counter=0
|
counter=0
|
||||||
total_estimate=0
|
total_estimate=0
|
||||||
total_standard_deviation=0
|
total_standard_deviation=0
|
||||||
|
|
@ -39,27 +54,26 @@ for var in "$@"; do
|
||||||
|
|
||||||
# header
|
# header
|
||||||
if [[ $counter = 1 ]]; then
|
if [[ $counter = 1 ]]; then
|
||||||
printf "$header" "task" "optimistic" "realistic" "pessimistic" "duration" "risk" "variance"
|
printf "$header" "#" "optimistic" "realistic" "pessimistic" "duration" "risk" "variance"
|
||||||
printf "%$width.${width}s\n" "$divider"
|
_divider
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check values
|
# check values
|
||||||
if [ -z "$o" ] || [ -z "$r" ] || [ -z "$p" ]; then
|
if [ -z "$o" ] || [ -z "$r" ] || [ -z "$p" ]; then
|
||||||
#echo -e "\tbad input [$o,$r,$p]"
|
|
||||||
printf "$format" "$counter. bad input" $o $r $p
|
printf "$format" "$counter. bad input" $o $r $p
|
||||||
else
|
else
|
||||||
|
|
||||||
# pert estimate
|
# pert estimate
|
||||||
pert_estimate=$(echo "scale=$scale; ($o+4*$r+$p)/6" | bc -l | sed 's/^\./0./')
|
pert_estimate=$(_calc "($o+4*$r+$p)/6")
|
||||||
total_estimate=$(echo "scale=$scale; $total_estimate + $pert_estimate" | bc -l | sed 's/^\./0./')
|
total_estimate=$(_calc "$total_estimate + $pert_estimate")
|
||||||
|
|
||||||
# standard deviation
|
# standard deviation
|
||||||
standard_deviation=$(echo "scale=$scale; ($p-$o)/6" | bc -l | sed 's/^\./0./')
|
standard_deviation=$(_calc "($p-$o)/6")
|
||||||
total_standard_deviation=$(echo "scale=$scale; $total_standard_deviation + $standard_deviation" | bc | sed 's/^\./0./')
|
total_standard_deviation=$(_calc "$total_standard_deviation + $standard_deviation")
|
||||||
|
|
||||||
# variance
|
# variance
|
||||||
variance=$(echo "scale=$scale; $standard_deviation*$standard_deviation" | bc -l | sed 's/^\./0./')
|
variance=$(_calc "$standard_deviation * $standard_deviation")
|
||||||
total_variance=$(echo "scale=$scale; $total_variance + $variance" | bc | sed 's/^\./0./')
|
total_variance=$(_calc "$total_variance + $variance")
|
||||||
|
|
||||||
# row
|
# row
|
||||||
printf "$format" "$counter. task" $o $r $p $pert_estimate $standard_deviation $variance
|
printf "$format" "$counter. task" $o $r $p $pert_estimate $standard_deviation $variance
|
||||||
|
|
@ -70,7 +84,7 @@ done
|
||||||
if [[ $total_estimate > 0 ]]; then
|
if [[ $total_estimate > 0 ]]; then
|
||||||
|
|
||||||
# footer
|
# footer
|
||||||
printf "%$width.${width}s\n" "$divider"
|
_divider
|
||||||
printf "$format" "summary" "-" "-" "-" $total_estimate $total_standard_deviation $total_variance
|
printf "$format" "summary" "-" "-" "-" $total_estimate $total_standard_deviation $total_variance
|
||||||
|
|
||||||
echo -e "\nThree point estimate:"
|
echo -e "\nThree point estimate:"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue