Skip to content

Commit e72ffd6

Browse files
committed
dispatch: Add a match ratio metric
1 parent 2c37513 commit e72ffd6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

display.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def pair_graphs(pairs):
9999

100100
f = Page(f"out/pairs/{idx}.html")
101101
f.write("<div>")
102-
f.write(f"<h1>{pair['directory1']} | {pair['directory2']}</h1>")
102+
f.write(f"<h1>{pair['directory1']} | {pair['directory2']} | {pair['match_ratio']}</h1>")
103103
f.write("</div>")
104104

105105
left = ""
@@ -178,7 +178,7 @@ def index(pairs):
178178
f.write("<h1>Pairs</h1>")
179179

180180
f.write(
181-
"<table><tr><th>Directory 1</th><th>Directory 2</th><th>Matching files</th><th>Details</th></tr>"
181+
"<table><tr><th>Directory 1</th><th>Directory 2</th><th>Score</th><th>Details</th></tr>"
182182
)
183183

184184
for idx, pair in enumerate(pairs):
@@ -189,7 +189,7 @@ def index(pairs):
189189

190190
f.write(f"<td>{pair['directory1']}</td>")
191191
f.write(f"<td>{pair['directory2']}</td>")
192-
f.write(f"<td>{len(pair['matches'])}</td>")
192+
f.write(f"<td>{pair['match_ratio']}</td>")
193193
f.write(f'<td><a href="pairs/{idx}.html">Details</a></td>')
194194

195195
f.write("</tr>")
@@ -205,7 +205,7 @@ def main():
205205
with open("pairs.json", "r") as f:
206206
pairs = json.load(f)
207207

208-
pairs = sorted(pairs, key=lambda pair: -len(pair["matches"]))
208+
pairs = sorted(pairs, key=lambda pair: -pair["match_ratio"])
209209

210210
pair_graphs(pairs)
211211
index(pairs)

src/dispatch.cc

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct Pair {
5353
std::vector<Match> matches;
5454
Directory *directory1;
5555
Directory *directory2;
56+
float match_ratio;
5657
};
5758

5859
std::regex *glob = nullptr;
@@ -153,6 +154,8 @@ void do_diff(Pair *pair, Directory *d1, Directory *d2) {
153154
pair->directory1 = d1;
154155
pair->directory2 = d2;
155156

157+
unsigned file_count = 0;
158+
double totalSim = 0.0;
156159
for (size_t i = 0; i < d1->sexps.size(); i++) {
157160
for (size_t j = 0; j < d2->sexps.size(); j++) {
158161
const std::string &p1 = d1->sexps[i].path;
@@ -176,10 +179,18 @@ void do_diff(Pair *pair, Directory *d1, Directory *d2) {
176179
if (s < sim)
177180
continue;
178181

182+
totalSim += s;
183+
file_count++;
184+
179185
pair->matches.emplace_back(&d1->sexps[i], &d2->sexps[j], s,
180186
MappingsVec2(t1, mapping));
181187
}
182188
}
189+
190+
if (file_count == 0)
191+
pair->match_ratio = 0.0;
192+
else
193+
pair->match_ratio = totalSim / file_count;
183194
}
184195

185196
std::ostream &dump_match(const Match &match, std::ostream &os) {
@@ -219,6 +230,7 @@ void dump_pairs(const std::vector<Pair> &pairs) {
219230

220231
f << "\"directory1\": \"" << pair.directory1->cc_path << "\",";
221232
f << "\"directory2\": \"" << pair.directory2->cc_path << "\",";
233+
f << "\"match_ratio\": " << pair.match_ratio << ",";
222234
f << "\"matches\": [";
223235
for (size_t i = 0; i < pair.matches.size(); i++) {
224236
dump_match(pair.matches[i], f);

0 commit comments

Comments
 (0)