PERT est une méthodologie de gestion de projet. Il s'agit d'un fork du programme bash qui permet d'afficher les tâches et les prévisions individuels et cumulés : https://github.com/arzzen/pert
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pert 3.9KB

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