Skip to content

Commit

Permalink
GH-86 Replace stats display algorithm with list of top 15 requests an…
Browse files Browse the repository at this point in the history
…d release 2.4.4 (Resolve #86)
  • Loading branch information
dzikoysk committed May 27, 2020
1 parent a85d033 commit 11a1018
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ $ docker run -e JAVA_OPTS='-Xmx128M -Dreposilite.port="8080"' reposilite
List of available management commands

```bash
Reposilite 2.4.3 Commands:
Reposilite 2.4.4 Commands:
help - List available commands
status - Display metrics
tokens - List all generated tokens
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>org.panda-lang</groupId>
<artifactId>reposilite</artifactId>
<version>2.4.3</version>
<version>2.4.4</version>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public final class ReposiliteConstants {

public static final String VERSION = "2.4.3";
public static final String VERSION = "2.4.4";

public static final String REMOTE_VERSION = "https://repo.panda-lang.org/org/panda-lang/reposilite/latest";

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/panda_lang/reposilite/stats/StatsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@

public final class StatsCommand implements NanoCommand {

private static final int TOP_SIZE = 15;

private final String pattern;
private Long limiter;
private final long limiter;

public StatsCommand(long limiter, String pattern) {
this.limiter = limiter;
Expand All @@ -45,24 +47,22 @@ public StatsCommand(String pattern) {
@Override
public boolean call(Reposilite reposilite) {
StatsService statsService = reposilite.getStatsService();
int count = statsService.countRecords();
int sum = statsService.sumRecords();

if (limiter == -1) {
double avg = sum / (double) count;
limiter = (long) Math.floor(1.8 * avg);
}
Reposilite.getLogger().info("");
Reposilite.getLogger().info("Statistics: ");
Reposilite.getLogger().info(" Requests count: " + statsService.countRecords() + " (sum: " + statsService.sumRecords() + ")");

Map<String, Integer> stats = statsService.fetchStats(entry -> entry.getValue() >= limiter && entry.getKey().contains(pattern));
int order = 0;

Reposilite.getLogger().info("");
Reposilite.getLogger().info("Statistics: ");
Reposilite.getLogger().info(" Requests count: " + count + " (sum: " + sum + ")");
Reposilite.getLogger().info(" Recorded: " + (stats.isEmpty() ? "[] " : "") +" (limiter: " + highlight(limiter) + ", pattern: '" + highlight(pattern) + "')");

for (Entry<String, Integer> entry : stats.entrySet()) {
Reposilite.getLogger().info(" " + (++order) + ". (" + entry.getValue() + ") " + entry.getKey());

if (limiter == -1 && order == TOP_SIZE) {
break;
}
}

Reposilite.getLogger().info("");
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.3
2.4.4

0 comments on commit 11a1018

Please sign in to comment.