forked from kjezek/api-evolution-data-corpus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.sh
executable file
·150 lines (116 loc) · 4.13 KB
/
benchmark.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
OUTPUT_DIRECTORY="output"
TOOLS_REPORTS_DIRECTORY="$OUTPUT_DIRECTORY/reports"
GROUND_TRUTH_CSV_FILE="$OUTPUT_DIRECTORY/ground_truth.csv"
BENCHMARK_RESULTS_CSV_FILE="$OUTPUT_DIRECTORY/benchmark.csv"
BENCHMARK_TMP_CSV_FILE="$OUTPUT_DIRECTORY/benchmark.tmp.csv"
PRECISIONS_CSV_FILE="$OUTPUT_DIRECTORY/precisions.csv"
RECALLS_CSV_FILE="$OUTPUT_DIRECTORY/recalls.csv"
function incompatibility_detected() {
report="$TOOLS_REPORTS_DIRECTORY/$1"
if grep -q "$2" "$report" ; then echo 1
else echo 0 ; fi
}
# Check necessary tools are installed
tools=("ant" "mvn" "pip3" "python3")
for tool in "${tools[@]}"; do
if ! command -v "$tool" &> /dev/null; then
echo "$tool is not installed. Please install it."
exit 1
fi
done
pip3 install -r requirements.txt
[ -f "$OUTPUT_DIRECTORY" ] || mkdir -p "$OUTPUT_DIRECTORY"
sh build_ground_truth.sh
sh tools/run.sh
echo "Analyzing results..."
tool_reports=()
for d in "$TOOLS_REPORTS_DIRECTORY"/* ; do
filename=$(basename "$d")
tool_reports+=("$filename")
done
echo "change,source,binary" > $BENCHMARK_RESULTS_CSV_FILE
cp $GROUND_TRUTH_CSV_FILE $BENCHMARK_RESULTS_CSV_FILE
# Read the benchmark CSV file
source_array=()
binary_array=()
while IFS=, read -r change source binary; do
if [ "$change" = "change" ]; then
continue
fi
source_array+=("$source")
binary_array+=("$binary")
done < "$BENCHMARK_RESULTS_CSV_FILE"
breaking_array=()
breaking_changes_count=0
for ((i = 0; i < ${#source_array[@]}; i++)); do
# A change is breaking if source == 0 or binary == 0
if [ "${source_array[i]}" = "0" ] || [ "${binary_array[i]}" = "0" ]; then
breaking_array+=("0")
breaking_changes_count=$((breaking_changes_count + 1))
else
breaking_array+=("1")
fi
done
echo "Number of breaking changes: $breaking_changes_count"
# Compute stats for each tool
precisions_array=()
recalls_array=()
tool_names=()
for filename in "${tool_reports[@]}"; do
rm -f "$BENCHMARK_TMP_CSV_FILE"
tool_name=$(echo "$filename" | cut -f 1 -d '.')
tool_names+=("$tool_name")
all_retrieved=0
relevant_retrieved=0
index=0
tool_values=()
while read -r line; do
change=$(echo "$line" | cut -d, -f1)
if [ "$change" = "change" ]; then
value="$tool_name"
else
value=$(incompatibility_detected "$filename" "$change")
all_retrieved=$((all_retrieved + value))
tool_values+=("$value")
if [ "${binary_array[index]}" -eq 0 ] || [ "${source_array[index]}" -eq 0 ]; then
relevant_retrieved=$((relevant_retrieved + value))
fi
index=$((index + 1))
fi
echo "${line},${value}" >> "$BENCHMARK_TMP_CSV_FILE"
done < "$BENCHMARK_RESULTS_CSV_FILE"
if [ "$all_retrieved" -ne 0 ]; then
precision=$(echo "scale=4; $relevant_retrieved / $all_retrieved * 100 " | bc)
else
precision=0.00
fi
if [ "$breaking_changes_count" -ne 0 ]; then
recall=$(echo "scale=4; $relevant_retrieved / $breaking_changes_count * 100 " | bc)
else
recall=0.00
fi
echo "Precision for $tool_name: $precision"
echo "Recall for $tool_name: $recall"
recalls_array+=("$recall")
precisions_array+=("$precision")
cp "$BENCHMARK_TMP_CSV_FILE" "$BENCHMARK_RESULTS_CSV_FILE"
done
# Clean up
rm -f "$BENCHMARK_TMP_CSV_FILE"
precisions_array_line="Precision,,"
for precision in "${precisions_array[@]}"; do
precisions_array_line+=",$precision"
done
echo "$precisions_array_line" >> "$BENCHMARK_RESULTS_CSV_FILE"
recalls_array_line="Recall,,"
for recall in "${recalls_array[@]}"; do
recalls_array_line+=",$recall"
done
echo "$recalls_array_line" >> "$BENCHMARK_RESULTS_CSV_FILE"
# Save the precisions and recalls arrays to separate CSV files
echo "tool,precision" > "$PRECISIONS_CSV_FILE"
paste -d ',' <(printf "%s\n" "${tool_names[@]}") <(printf "%s\n" "${precisions_array[@]}") >> "$PRECISIONS_CSV_FILE"
echo "tool,recall" > "$RECALLS_CSV_FILE"
paste -d ',' <(printf "%s\n" "${tool_names[@]}") <(printf "%s\n" "${recalls_array[@]}") >> "$RECALLS_CSV_FILE"
python3 plot.py