-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryAggregator.cpp
63 lines (41 loc) · 1.65 KB
/
QueryAggregator.cpp
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
//
// Created by Matthieu Rudelle on 07/06/16.
//
#include "QueryAggregator.h"
QueryAggregator::QueryAggregator(db_feature* feature) {
repoRank = feature->reporank;
fileId = feature->file_id;
startLine = feature->line_nb;
endLine = feature->line_nb;
featureSet.emplace(feature->feature_id);
lines.emplace_back(feature->line_nb);
}
void QueryAggregator::addFeature(db_feature* feature) {
featureSet.emplace(feature->feature_id);
lines.emplace_back(feature->line_nb);
if (startLine > feature->line_nb) {
startLine = feature->line_nb;
}
if (endLine < feature->line_nb) {
endLine = feature->line_nb;
}
}
void QueryAggregator::finalize(int qLength, agg_result* out) {
double ratioOfMatches = featureSet.size() / (float) qLength;
double sizeScore = lines.size();
double densityScore = sizeScore / (endLine-startLine+1);
densityScore = (densityScore > 5.0 ? 5.0 : densityScore) / 5.0;
sizeScore = (sizeScore > 100.0? 100.0 : sizeScore) / 100.0;
out->score = .6 * densityScore + .4 * sizeScore /*+ .3 * rarityScore */+ .1 * ratioOfMatches + .4 * repoRank;
out->scoreBreakdown.emplace("repoRank", .4 * repoRank);
out->scoreBreakdown.emplace("ratioOfMatches", .1 * ratioOfMatches);
out->scoreBreakdown.emplace("rarity", 0.0);
out->scoreBreakdown.emplace("density", densityScore);
out->scoreBreakdown.emplace("size", .4 * sizeScore);
out->scoreBreakdown.emplace("final", out->score);
out->lineEnd = endLine;
out->lineStart = startLine;
out->featureIDs.assign(featureSet.begin(), featureSet.end());
out->fileId = fileId;
out->lines = lines;
}