-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
170 additions
and
83 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/koko/yayu/component/StatisticsGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package koko.yayu.component; | ||
|
||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import freemarker.template.TemplateMethodModelEx; | ||
import freemarker.template.TemplateModelException; | ||
import koko.yayu.config.FreeMarkerConfig; | ||
import org.json.JSONObject; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.apache.commons.text.WordUtils; | ||
|
||
public class StatisticsGenerator { | ||
|
||
private final String title; | ||
private final int size; | ||
List<Pair<String, Integer>> stats; | ||
|
||
public StatisticsGenerator(String title, int size, String property, List<JSONObject> data) { | ||
this.title = title; | ||
this.size = size; | ||
stats = | ||
data.stream().collect(Collectors.groupingBy( | ||
jsonObject -> jsonObject.getString(property) | ||
)).entrySet().stream().map( | ||
entry -> Pair.of(entry.getKey(), entry.getValue().size())) | ||
.sorted(Map.Entry.comparingByValue()) | ||
.limit(size) | ||
.toList(); | ||
} | ||
|
||
public String generate() { | ||
String re = "<article class=\"message\"><div class=\"message-header\"><p>" | ||
+ String.format("TOP %s %s", size, title) | ||
+ "</p></div><div class=\"message-body\"><table class=\"table is-striped is-fullwidth\">"; | ||
for (Pair<String, Integer> pair : stats) { | ||
re += "<tr class=\"is-dark\"><td>" + pair.getKey() + "</td><td>" + pair.getValue() + "</td></tr>"; | ||
} | ||
re += "</table></div></article>"; | ||
return re; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.