You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2021/05/22 04:08:21 UTC
[tomee-site-generator] 02/08: Ability to aggregate committer stats
This is an automated email from the ASF dual-hosted git repository.
dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee-site-generator.git
commit 64ddeb048d47edb2824f784b4124a94484b9d8b8
Author: David Blevins <da...@gmail.com>
AuthorDate: Fri May 21 18:23:33 2021 -0700
Ability to aggregate committer stats
---
.../website/contributors/ContributorData.java | 7 +++
.../apache/tomee/website/contributors/Stats.java | 66 ++++++++++++++++++++++
.../website/contributors/ContributorDataTest.java | 17 ++++++
.../tomee/website/contributors/StatsTest.java | 57 +++++++++++++++++++
4 files changed, 147 insertions(+)
diff --git a/src/main/java/org/apache/tomee/website/contributors/ContributorData.java b/src/main/java/org/apache/tomee/website/contributors/ContributorData.java
index 93b7078..3ace899 100644
--- a/src/main/java/org/apache/tomee/website/contributors/ContributorData.java
+++ b/src/main/java/org/apache/tomee/website/contributors/ContributorData.java
@@ -41,6 +41,13 @@ public class ContributorData {
@JsonbProperty("weeks")
private List<Week> weeks;
+ public Stats getStats() {
+ return weeks.stream()
+ .map(week -> new Stats(week.c, week.a, week.d))
+ .reduce(Stats::add)
+ .orElse(new Stats(0, 0, 0));
+ }
+
@Data
@NoArgsConstructor
@AllArgsConstructor
diff --git a/src/main/java/org/apache/tomee/website/contributors/Stats.java b/src/main/java/org/apache/tomee/website/contributors/Stats.java
new file mode 100644
index 0000000..e035c72
--- /dev/null
+++ b/src/main/java/org/apache/tomee/website/contributors/Stats.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.website.contributors;
+
+import lombok.Data;
+
+/**
+ * We add a contributor's commits, lines added and lines removed together
+ * across all repos to create an overall score that is used to sort contributors.
+ */
+@Data
+@lombok.Builder(builderClassName = "Builder", toBuilder = true)
+public class Stats {
+ private final int commits;
+ private final int linesAdded;
+ private final int linesRemoved;
+
+ /**
+ * Aggregate the stats from one git repo with the same
+ * contributors stats on another repo
+ */
+ public Stats add(final Stats that) {
+ return new Stats(
+ this.commits + that.commits,
+ this.linesAdded + that.linesAdded,
+ this.linesRemoved + that.linesRemoved);
+ }
+
+ public Stats max(final Stats that) {
+ return new Stats(
+ Math.max(this.commits, that.commits),
+ Math.max(this.linesAdded, that.linesAdded),
+ Math.max(this.linesRemoved, that.linesRemoved));
+ }
+
+ /**
+ * Assumes this instance of Stats holds the max (highest)
+ * possible values for commits, lines added, and lines removed.
+ *
+ * The passed in stats will be evaluated against these numbers
+ * a percentage (0-100) will be returned. The return value is
+ * intentionally an int so it can easily be used for sorting.
+ */
+ public int score(final Stats that) {
+ final double commitsPercentage = that.commits / (double) this.commits;
+ final double linesAddedPercentage = that.linesAdded / (double) this.linesAdded;
+ final double linesRemovedPercentage = that.linesRemoved / (double) this.linesRemoved;
+ final double average = (commitsPercentage + linesAddedPercentage + linesRemovedPercentage) / 3;
+
+ return (int) Math.round(average * 100);
+ }
+}
diff --git a/src/test/java/org/apache/tomee/website/contributors/ContributorDataTest.java b/src/test/java/org/apache/tomee/website/contributors/ContributorDataTest.java
index 4cf0f93..5669e44 100644
--- a/src/test/java/org/apache/tomee/website/contributors/ContributorDataTest.java
+++ b/src/test/java/org/apache/tomee/website/contributors/ContributorDataTest.java
@@ -43,4 +43,21 @@ public class ContributorDataTest {
assertEquals(6, data[3].getWeeks().get(135).getC());
}
+ @Test
+ public void getStats() throws Exception {
+
+ final URL resource = this.getClass().getClassLoader().getResource("contributor-data.json");
+ final String json = IO.slurp(resource);
+ final Jsonb jsonb = JsonbBuilder.create();
+ final ContributorData[] data = jsonb.fromJson(json, ContributorData[].class);
+
+ assertEquals(12, data.length);
+ assertEquals("djencks", data[3].getAuthor().getLogin());
+
+ final Stats stats = data[3].getStats();
+ assertEquals(36, stats.getCommits());
+ assertEquals(35243, stats.getLinesAdded());
+ assertEquals(25020, stats.getLinesRemoved());
+ }
+
}
diff --git a/src/test/java/org/apache/tomee/website/contributors/StatsTest.java b/src/test/java/org/apache/tomee/website/contributors/StatsTest.java
new file mode 100644
index 0000000..8e4424d
--- /dev/null
+++ b/src/test/java/org/apache/tomee/website/contributors/StatsTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.website.contributors;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class StatsTest {
+
+ @Test
+ public void add() {
+ final Stats a = new Stats(3, 5, 7);
+ final Stats b = new Stats(11, 13, 17);
+
+ final Stats c = a.add(b);
+ assertEquals(14, c.getCommits());
+ assertEquals(18, c.getLinesAdded());
+ assertEquals(24, c.getLinesRemoved());
+ }
+
+ @Test
+ public void max() {
+ final Stats a = new Stats(157, 241, 37);
+ final Stats b = new Stats(211, 113, 23);
+
+ final Stats c = a.max(b);
+ assertEquals(211, c.getCommits());
+ assertEquals(241, c.getLinesAdded());
+ assertEquals(37, c.getLinesRemoved());
+ }
+
+ @Test
+ public void score() {
+ final Stats max = new Stats(157, 241, 37);
+
+ assertEquals(0, max.score(new Stats(0, 0, 0)));
+ assertEquals(33, max.score(new Stats(157, 0, 0)));
+ assertEquals(67, max.score(new Stats(157, 241, 0)));
+ assertEquals(100, max.score(new Stats(157, 241, 37)));
+ assertEquals(43, max.score(new Stats(50, 40, 30)));
+ }
+}