forked from patricklam/cloneanalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats_cc.js
More file actions
85 lines (80 loc) · 3.16 KB
/
stats_cc.js
File metadata and controls
85 lines (80 loc) · 3.16 KB
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
#!/usr/bin/env mongo
var thresholds = [0.5, 0.6, 0.7, 0.8, 0.9];
db = new Mongo().getDB("ccanalysis");
var collection = db.getCollection(project);
if (undefined == collection)
return;
var result = {
project : project,
others : collection.aggregate(
{ $match : { _class : "clone.analysis.Stats"} },
{ $project : {
_id : 0,
totalStaticCalls : 1,
totalMethods : 1,
totalClasses : 1,
totalPackages : 1,
totalClassesNotDirectlyInheritingTestCase : 1,
totalClassesContainingNonEmptySetupOrTeardown : 1,
totalMethodsWithAtLeast5Asserts : 1,
totalMethodsWithBranches : 1,
totalMethodsWithLoops : 1,
totalMethodsWithNoStaticCalls : 1,
totalMethodsWithNetworkAccess : 1,
totalMethodsWithFilesystemAccess : 1
}
}
).toArray()[0],
details : []
};
for (var j = 0; j < thresholds.length; ++j) {
var detail = { threshold : thresholds[j] };
var filter = { _class : "clone.analysis.similarity.CallChainMatchSet", score : { $gte : thresholds[j] } };
detail.sets = collection.count(filter);
detail.classes = collection.aggregate(
{ $match : filter },
{ $unwind : "$set" },
{ $group : { _id : {className : "$set.className"} } }
).itcount();
detail.methods = collection.aggregate(
{ $match : filter },
{ $unwind : "$set" },
{ $group : { _id : {className : "$set.className", methodName : "$set.methodName"} } }
).itcount();
detail.asserts = collection.aggregate(
{ $match : filter },
{ $unwind : "$set" },
{ $group : { _id : "$set" } }
).itcount();
detail.assertInCloneRatio = detail.asserts/result.others.totalStaticCalls;
detail.scores = collection.aggregate(
{ $match : filter },
{ $group : {_id : "$score", count_ : {$sum : 1} } },
{ $sort : {_id : -1} },
{ $project : {_id : 0, score : "$_id", count : "$count_"} }
).toArray()
detail.ccsizes = collection.aggregate(
{ $match : filter },
{ $group : {_id : "$ccsize", count_ : {$sum : 1} } },
{ $sort : {_id : -1} },
{ $project : {_id : 0, ccsize : "$_id", count : "$count_"} }
).toArray()
detail.scoreAssertAvgs = collection.aggregate(
{ $match : filter },
{ $unwind : "$set" },
{ $group : {_id : {_id : "$_id", score : "$score"}, count_ : {$sum : 1} } },
{ $group : {_id : "$_id.score", avgcount_ : {$avg : "$count_"} } },
{ $sort : {_id : -1} },
{ $project : {_id : 0, score : "$_id", avgAssertSize : "$avgcount_"} }
).toArray()
detail.ccsizeAssertAvgs = collection.aggregate(
{ $match : filter },
{ $unwind : "$set" },
{ $group : {_id : {_id : "$_id", ccsize : "$ccsize"}, count_ : {$sum : 1} } },
{ $group : {_id : "$_id.ccsize", avgcount_ : {$avg : "$count_"} } },
{ $sort : {_id : -1} },
{ $project : {_id : 0, ccsize : "$_id", avgAssertSize : "$avgcount_"} }
).toArray()
result.details.push(detail);
}
printjson(result);