1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- # Modalità "query"
- # Variabili e funzioni di supporto
- # a modalità query
- # Prendendo in ingresso un'entrata
- # restituisce la durata in ore
- # del turno corrispondente
- get_shift_duration(){
- echo "$1" | cut -f3 | cut -d'=' -f2
- return 0
- }
- # Controlla che l'id in ingresso esista
- # e lo converte nel nome dell'operatore corrispondente
- # (se non esiste, ferma il programma esce con un errore)
- id_to_name_check(){
- case "$1" in
- 0)
- echo "$ID_0_150"
- ;;
- 1)
- echo "$ID_1_150"
- ;;
- 2)
- echo "$ID_2_150"
- ;;
- *)
- echoerr "Illegal operator ID specified. Choose between 0,1,2."
- esac
- return 0
- }
- # Prendendo in ingresso l'id di un operatore
- # restituisce il numero totale di ore di lavoro
- get_operator_total(){
- OPERATOR_NAME=$(id_to_name_check "$1") || exit 1
- awk -F\; -v pattern="$OPERATOR_NAME" '
- BEGIN { counter=0 }
- $0 ~ pattern { counter+=$3; }
- END{ print counter }' "$SHIFT_FILE"
- return 0
- }
- # Grand total mode
- print_gtotal(){
- echo -e "\nHere it comes the operators' grand total:"
- for i in {0..2}
- do
- printf "%-30s%10s/150h\n" "$(id_to_name_check $i):" "$(get_operator_total $i)"
- done
- }
|