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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 \"1,2,12 4,5,9 2,3,6\", where whitespace separates tasks."
  21. _echo ""
  22. _echoB "Usage:"
  23. _echo "\tpert [optimistic,realistic,pessimistic]"
  24. _echo ""
  25. _echoB "Example:"
  26. _echo "\tpert 1,3,4"
  27. _echo "\tpert 10,15,20 5,7,10"
  28. _echo "\tpert \"1,2,3\" \"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 "Tasks"
  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. for var in "$@"; do
  61. # counter iterator
  62. counter=$[$counter +1]
  63. # split values
  64. IFS=',' read -ra ADDR <<< "$var"
  65. # optimistic value
  66. o="0"
  67. if [ -n "${ADDR[0]-}" ]; then
  68. o=${ADDR[0]}
  69. fi
  70. # realistic value
  71. r="0"
  72. if [ -n "${ADDR[1]-}" ]; then
  73. r=${ADDR[1]}
  74. fi
  75. # pessimistic value
  76. p="0"
  77. if [ -n "${ADDR[2]-}" ]; then
  78. p=${ADDR[2]}
  79. fi
  80. # check values
  81. if [ -z "$o" ] || [ -z "$r" ] || [ -z "$p" ]; then
  82. printf "$format" "$counter. bad input" $o $r $p
  83. else
  84. # pert estimate
  85. pert_estimate=$(_calc "($o+4*$r+$p)/6")
  86. total_estimate=$(_calc "$total_estimate + $pert_estimate")
  87. # standard deviation
  88. standard_deviation=$(_calc "($p-$o)/6")
  89. total_standard_deviation=$(_calc "$total_standard_deviation + $standard_deviation")
  90. # variance
  91. variance=$(_calc "$standard_deviation * $standard_deviation")
  92. total_variance=$(_calc "$total_variance + $variance")
  93. # row
  94. printf "$format" "$counter. task" $o $r $p $pert_estimate $standard_deviation $variance
  95. fi
  96. done
  97. _divider
  98. if [[ $total_estimate > 0 ]]; then
  99. # footer summary
  100. printf "$format" "summary" "-" "-" "-" $total_estimate $total_standard_deviation $total_variance
  101. _divider
  102. _echo ""
  103. _echoB "Three point estimates"
  104. _echo ""
  105. width=42
  106. tpeformat=" | %-13s |%11s |%10s |\n"
  107. _divider
  108. printf "$tpeformat" "confidence"
  109. _divider
  110. printf "$tpeformat" "1 Sigma - 68%" $(_calc "$total_estimate - $total_standard_deviation") $(_calc "$total_estimate + $total_standard_deviation")
  111. printf "$tpeformat" "2 Sigma - 95%" $(_calc "$total_estimate - 2 * $total_standard_deviation") $(_calc "$total_estimate + 2 * $total_standard_deviation")
  112. printf "$tpeformat" "3 Sigma - 99%" $(_calc "$total_estimate - 3 * $total_standard_deviation") $(_calc "$total_estimate + 3 * $total_standard_deviation")
  113. _divider
  114. fi
  115. _echo ""
  116. }
  117. # main
  118. if [ $# -eq 0 ]; then
  119. _help
  120. exit 1
  121. fi
  122. case "$1" in
  123. *help|*h)
  124. _help
  125. exit 1
  126. ;;
  127. *)
  128. pert_table $@
  129. exit 0
  130. ;;
  131. esac