Fixed incorrect truncation

This commit is contained in:
Rob Pearce 2022-08-29 11:01:10 +10:00
parent fba28d7ee0
commit 64ac879faa
1 changed files with 36 additions and 12 deletions

View File

@ -65,10 +65,22 @@ if [[ $mode == "s" ]]; then
diagram="${diagram}[server]\n" diagram="${diagram}[server]\n"
eq="${eq} * 100" eq="${eq} * 100"
answer=$(echo "scale=9; $eq" | bc) answer=$(echo "scale=9; $eq" | bc)
answershort=$(echo "$answer" | tr -dc '9.') if [[ $answer == 99.* ]]; then
nines=$(echo $answershort | tr -d -C 9 | wc -c | tr -d ' ') answershort=$(echo "$answer" | tr -dc '9.')
[[ $nines -eq 1 ]] && ess="" || ess="s" else
ninestext="${nines} nine${ess}" answershort=$answer
fi
if [[ $answershort == 99.* ]]; then
nines=$(echo $answershort | tr -d -C 9 | wc -c | tr -d ' ')
[[ $nines -eq 1 ]] && ess="" || ess="s"
if [[ -n $HAVE_BASHTOOLS ]]; then
ninestext=" (^b\"${nines} nine${ess}\"^p)"
else
ninestext=" (\"${nines} nine${ess}\")"
fi
else
ninestext=""
fi
if [[ -n $HAVE_BASHTOOLS ]]; then if [[ -n $HAVE_BASHTOOLS ]]; then
@ -77,7 +89,7 @@ if [[ $mode == "s" ]]; then
echo echo
csecho -e "$WHITE" "^b${UNDERLINE}Availability^p\n" csecho -e "$WHITE" "^b${UNDERLINE}Availability^p\n"
inform "^bEquation:^p ${eq}" inform "^bEquation:^p ${eq}"
inform "^bAvailability:^p ${answershort}% (^b\"$ninestext\"^p)" inform "^bAvailability:^p ${answershort}% $ninestext"
echo echo
else else
echo "Architecture" echo "Architecture"
@ -88,7 +100,7 @@ if [[ $mode == "s" ]]; then
echo "Availability" echo "Availability"
echo "------------" echo "------------"
echo "* Equation: ${eq}" echo "* Equation: ${eq}"
echo "* Availability: ${answershort}% (\"$ninestext\")" echo "* Availability: ${answershort}% $ninestext"
echo echo
fi fi
elif [[ $mode == "p" ]]; then elif [[ $mode == "p" ]]; then
@ -178,10 +190,22 @@ elif [[ $mode == "p" ]]; then
eq="(1 - (1 - (${sysuptime}/100))^${nsites})*100" eq="(1 - (1 - (${sysuptime}/100))^${nsites})*100"
answer=$(echo "scale=15; $eq" | bc) answer=$(echo "scale=15; $eq" | bc)
answershort=$(echo "$answer" | tr -dc '9.') if [[ $answer == 99.* ]]; then
nines=$(echo $answershort | tr -d -C 9 | wc -c | tr -d ' ') answershort=$(echo "$answer" | tr -dc '9.')
[[ $nines -eq 1 ]] && ess="" || ess="s" else
ninestext="${nines} nine${ess}" answershort=$answer
fi
if [[ $answershort == 99.* ]]; then
nines=$(echo $answershort | tr -d -C 9 | wc -c | tr -d ' ')
[[ $nines -eq 1 ]] && ess="" || ess="s"
if [[ -n $HAVE_BASHTOOLS ]]; then
ninestext=" (^b\"${nines} nine${ess}\"^p)"
else
ninestext=" (\"${nines} nine${ess}\")"
fi
else
ninestext=""
fi
if [[ -n $HAVE_BASHTOOLS ]]; then if [[ -n $HAVE_BASHTOOLS ]]; then
@ -190,7 +214,7 @@ elif [[ $mode == "p" ]]; then
echo echo
csecho -e "$WHITE" "^b${UNDERLINE}Availability^p\n" csecho -e "$WHITE" "^b${UNDERLINE}Availability^p\n"
inform "^bEquation:^p ${eq}" inform "^bEquation:^p ${eq}"
inform "^bAvailability:^p ${answershort}% (^b\"$ninestext\"^p)" inform "^bAvailability:^p ${answershort}% $ninestext)"
else else
echo "Architecture" echo "Architecture"
echo "------------" echo "------------"
@ -200,7 +224,7 @@ elif [[ $mode == "p" ]]; then
echo "Availability" echo "Availability"
echo "------------" echo "------------"
echo "Equation: ${eq}" echo "Equation: ${eq}"
echo "Availability: ${answershort}% (\"$ninestext\")" echo "Availability: ${answershort}% $ninestext"
fi fi
echo echo
elif [[ $mode == "i" ]]; then elif [[ $mode == "i" ]]; then