-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisura.sh
executable file
·69 lines (59 loc) · 1.78 KB
/
misura.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
CORRETTI=0
ERRATI=0
#Identifichiamo l'argomento contenente l'esito del/dei supervisor/Servers
for arg in $@ ; do
read -r firstline < $arg
case $firstline in
( "SERVER"* ) SERVER_FILE=$arg;;
esac
done
#Invertiamo il contenuto del file per fermarci prima durante la scansione
tac $SERVER_FILE > REVERSE_SF.txt
RV="REVERSE_SF.txt"
#Per ogni client, memorizza valore SECRET
i=0
for file in $@ ; do
DIFFERENCE="NULL"
ESTIMATE="NULL"
exec 3<$RV
if [[ $file != $SERVER_FILE ]]; then
read -r SECRET < $file
#Ritagliamo solo il valore di SECRET
ID=${SECRET/*"CLIENT"/}
ID=${ID/" SECRET"*/}
SECRET=${SECRET/*"SECRET"/}
#Controlla valore stimato dal supervisor per quel client
while read -u 3 line ; do
case $line in
( *"${ID} BASED"* )
ESTIMATE=${line/*"ESTIMATE "/}
ESTIMATE=${ESTIMATE/" FOR"*/}
break;;
esac
done
#Incrementa statistica
if [[ $ESTIMATE!="NULL" ]]; then
DIFFERENCE=$(($SECRET - $ESTIMATE))
DIFFERENCE=${DIFFERENCE/-/} #Rimuovo eventuali segni di negatività
if [[ $DIFFERENCE -le 25 ]] ; then
(( CORRETTI++ ))
else (( ERRATI++ ))
err[$i]=$DIFFERENCE
(( i++ ))
fi
fi
fi
done
#Calcolo errore medio
sum=0
for num in $err ; do
sum=$(($sum + $num))
done
#Output statistiche
tot=$(($# - 1))
echo Statistiche:
echo SECRET corretti: ${CORRETTI}/$tot
echo SECRET errati: ${ERRATI}/$tot
echo "Errore medio: $(($sum / $ERRATI)) calcolato in proporzione ai valori errati"
echo "Errore medio: $(($sum / $tot)) calcolato in proporzione ai valori totali"