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:27 UTC

[tomee-site-generator] 08/08: Sort the contributors list by score

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 ec968626510cf5356db69276c940875873d961a4
Author: David Blevins <da...@gmail.com>
AuthorDate: Fri May 21 21:08:02 2021 -0700

    Sort the contributors list by score
---
 .../org/apache/tomee/website/Configuration.java    |  2 +-
 .../tomee/website/contributors/Contributors.java   | 23 +++++++++++++++++++++-
 .../apache/tomee/website/contributors/Stats.java   |  2 +-
 .../tomee/website/contributors/StatsTest.java      |  8 ++++----
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/tomee/website/Configuration.java b/src/main/java/org/apache/tomee/website/Configuration.java
index 9323bfe..d137778 100644
--- a/src/main/java/org/apache/tomee/website/Configuration.java
+++ b/src/main/java/org/apache/tomee/website/Configuration.java
@@ -89,7 +89,7 @@ public class Configuration {
                 new Source("https://github.com/eclipse-ee4j/websocket-api.git", "master", "websocket-api-ee9")
         };
 
-        if (1 == 1) return new Source[0];
+//        if (1 == 1) return new Source[0];
         return new Source[]{
 //                new Source("https://github.com/apache/tomee.git", "master", "tomee-8.0"),
                 new Source("https://github.com/apache/tomee.git", "master", "tomee-9.0").label("milestone").related(microProfile2).related(jakartaEE9).javadoc("^org.apache.(openejb|tomee).*"),
diff --git a/src/main/java/org/apache/tomee/website/contributors/Contributors.java b/src/main/java/org/apache/tomee/website/contributors/Contributors.java
index 8718b4b..1c26dee 100755
--- a/src/main/java/org/apache/tomee/website/contributors/Contributors.java
+++ b/src/main/java/org/apache/tomee/website/contributors/Contributors.java
@@ -55,7 +55,8 @@ public class Contributors {
          * Try getting the full list from Github across all repositories
          */
         try {
-            return new Github().getContributors();
+            final List<Contributor> contributors = new Github().getContributors();
+            return sort(contributors);
         } catch (Exception e) {
             log.log(Level.SEVERE, "Unable to fetch contributors from github.com", e);
         }
@@ -94,4 +95,24 @@ public class Contributors {
         return contributors;
     }
 
+    public static List<Contributor> sort(final List<Contributor> list) {
+        final Stats max = list.stream()
+                .map(Contributor::getStats)
+                .reduce(Stats::max)
+                .orElse(new Stats(0, 0, 0));
+
+        list.sort(Comparator.<Contributor, Integer>comparing(contributor -> max.score(contributor.getStats())).reversed());
+
+        final boolean debug = false;
+        if (debug){
+            for (final Contributor contributor : list) {
+                final Stats stats = contributor.getStats();
+                System.out.printf("Contributor: %-7s %-20s %5s %7s %7s%n",
+                        max.score(contributor.getStats()), contributor.getName(),
+                        stats.getCommits(), stats.getLinesAdded(),
+                        stats.getLinesRemoved());
+            }
+        }
+        return list;
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/org/apache/tomee/website/contributors/Stats.java b/src/main/java/org/apache/tomee/website/contributors/Stats.java
index e035c72..447c7e0 100644
--- a/src/main/java/org/apache/tomee/website/contributors/Stats.java
+++ b/src/main/java/org/apache/tomee/website/contributors/Stats.java
@@ -61,6 +61,6 @@ public class Stats {
         final double linesRemovedPercentage = that.linesRemoved / (double) this.linesRemoved;
         final double average = (commitsPercentage + linesAddedPercentage + linesRemovedPercentage) / 3;
 
-        return (int) Math.round(average * 100);
+        return (int) Math.round(average * 1000000);
     }
 }
diff --git a/src/test/java/org/apache/tomee/website/contributors/StatsTest.java b/src/test/java/org/apache/tomee/website/contributors/StatsTest.java
index 8e4424d..f66efb7 100644
--- a/src/test/java/org/apache/tomee/website/contributors/StatsTest.java
+++ b/src/test/java/org/apache/tomee/website/contributors/StatsTest.java
@@ -49,9 +49,9 @@ public class StatsTest {
         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)));
+        assertEquals(333333, max.score(new Stats(157, 0, 0)));
+        assertEquals(666667, max.score(new Stats(157, 241, 0)));
+        assertEquals(1000000, max.score(new Stats(157, 241, 37)));
+        assertEquals(431752, max.score(new Stats(50, 40, 30)));
     }
 }