Skip to content

Commit 57c0a8f

Browse files
authored
Merge pull request #86 from adamtornhill/sort-entity-ownership-in-descending-order
Sort entity-effort by a second key to present the main author first
2 parents 4297037 + c435209 commit 57c0a8f

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

src/code_maat/analysis/effort.clj

+20-9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
[name author revs total-revs])
2626
effort))
2727

28+
(defn- entity-name-from
29+
[[name _]]
30+
name)
31+
32+
(defn- revs-from
33+
[[_name _author revs _]]
34+
revs)
35+
2836
(defn- sum-revs-by-author
2937
"Sums the given dataset by a given group and churn.
3038
The given dataset, grouped-ds, is grouped by the column
@@ -49,13 +57,16 @@
4957
[entity author-revs]))
5058

5159
(defn as-revisions-per-author
52-
[ds options]
60+
[ds _options]
5361
(->>
5462
(ds/-group-by :entity ds)
5563
sum-effort-by-author
5664
(mapcat normalize-effort)
57-
(ds/-dataset [:entity :author :author-revs :total-revs])
58-
(ds/-order-by :entity :asc)))
65+
; note: Clojure implements stable sort which is why this works
66+
(sort-by revs-from >)
67+
(sort-by entity-name-from)
68+
(ds/-dataset [:entity :author :author-revs :total-revs])))
69+
;(ds/-order-by :entity :asc)))
5970

6071
(defn- contributed-revs
6172
[author-changes]
@@ -73,13 +84,13 @@
7384
(defn as-main-developer-by-revisions
7485
"Identifies the main developers, together with their
7586
ownership percentage, of each module."
76-
[ds options]
87+
[ds _options]
7788
(->>
78-
(ds/-group-by :entity ds)
79-
sum-effort-by-author
80-
(map pick-main-dev-by-rev)
81-
(ds/-dataset [:entity :main-dev :added :total-added :ownership])
82-
(ds/-order-by :entity :asc)))
89+
(ds/-group-by :entity ds)
90+
sum-effort-by-author
91+
(map pick-main-dev-by-rev)
92+
(ds/-dataset [:entity :main-dev :added :total-added :ownership])
93+
(ds/-order-by :entity :asc)))
8394

8495
(defn- as-author-fractals
8596
[[_ ai nc]]

test/code_maat/analysis/effort_test.clj

+24-8
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,19 @@
1616
{:entity "B" :rev 3 :author "at" :date "2013-11-15"}])
1717

1818
(ds/def-ds multi-effort
19-
[{:entity "A" :rev 1 :author "at" :date "2013-11-10"}
19+
[{:entity "Z" :rev 4 :author "zt" :date "2013-11-15"}
20+
{:entity "Z" :rev 5 :author "xy" :date "2013-11-15"}
21+
{:entity "Z" :rev 6 :author "xy" :date "2013-11-16"}
22+
23+
{:entity "C" :rev 4 :author "zt" :date "2013-11-15"}
24+
{:entity "C" :rev 5 :author "zt" :date "2013-11-15"}
25+
26+
{:entity "A" :rev 1 :author "at" :date "2013-11-10"}
2027
{:entity "A" :rev 2 :author "xy" :date "2013-11-11"}
21-
{:entity "A" :rev 3 :author "zt" :date "2013-11-15"}])
28+
{:entity "A" :rev 3 :author "zt" :date "2013-11-15"}
29+
{:entity "A" :rev 4 :author "zt" :date "2013-11-15"}
30+
{:entity "A" :rev 5 :author "xy" :date "2013-11-15"}
31+
{:entity "A" :rev 6 :author "xy" :date "2013-11-16"}])
2232

2333
(deftest calculates-effort-for-single-author
2434
(is (= (effort/as-revisions-per-author single-effort options)
@@ -27,11 +37,15 @@
2737
["B" "at" 2 2]]))))
2838

2939
(deftest calculates-effort-for-multiple-authors
30-
(is (= (effort/as-revisions-per-author multi-effort options)
31-
(ds/-dataset [:entity :author :author-revs :total-revs]
32-
[["A" "at" 1 3]
33-
["A" "xy" 1 3]
34-
["A" "zt" 1 3]]))))
40+
(testing "With multiple authors, the effort is sorted in descending order (main author first)"
41+
(is (= (effort/as-revisions-per-author multi-effort options)
42+
(ds/-dataset [:entity :author :author-revs :total-revs]
43+
[["A" "xy" 3 6]
44+
["A" "zt" 2 6]
45+
["A" "at" 1 6]
46+
["C" "zt" 2 2]
47+
["Z" "xy" 2 3]
48+
["Z" "zt" 1 3]])))))
3549

3650
(deftest calculates-entity-fragmentation-for-single-author
3751
"The fractal value is a measurement of how
@@ -44,7 +58,9 @@
4458
(deftest calculates-entity-fragmentation-for-multiple-authors
4559
(is (= (effort/as-entity-fragmentation multi-effort options)
4660
(ds/-dataset [:entity :fractal-value :total-revs]
47-
[["A" 0.67 3]]))))
61+
[["A" 0.61 6]
62+
["Z" 0.44 3]
63+
["C" 0.0 2]]))))
4864

4965
(ds/def-ds shared-effort
5066
[{:entity "A" :rev 1 :author "zt" :date "2013-11-10"}

0 commit comments

Comments
 (0)