diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 616febb..15abeeb 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -43,6 +43,7 @@ import fr.devinsy.statoolinfos.htmlize.charts.PieChart; import fr.devinsy.statoolinfos.htmlize.charts.PieChart.Position; import fr.devinsy.statoolinfos.htmlize.charts.PieChartView; import fr.devinsy.statoolinfos.properties.PathProperty; +import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.statoolinfos.stats.StatAgent; import fr.devinsy.statoolinfos.stats.country.CountryStats; import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; @@ -267,12 +268,12 @@ public class Htmlizer BarChart chart; chart = new BarChart("Nombre de membres"); - for (PathProperty property : federation.getByPrefix("metrics.federation.members.count")) + + PathPropertyList values = federation.getByYearPrefix("metrics.federation.members.count").sortByPath(); + + for (PathProperty property : values) { - if (property.getLeaf().matches("\\d\\d\\d\\d")) - { - chart.add(property.getLeaf(), Double.parseDouble(property.getValue()), ChartColor.GREEN); - } + chart.add(property.getLeaf(), Double.parseDouble(property.getValue()), ChartColor.GREEN); } result = BarChartView.build(chart); diff --git a/src/fr/devinsy/statoolinfos/properties/PathProperty.java b/src/fr/devinsy/statoolinfos/properties/PathProperty.java index 36f5130..16bac92 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathProperty.java +++ b/src/fr/devinsy/statoolinfos/properties/PathProperty.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -49,6 +49,11 @@ public class PathProperty } } + /** + * Gets the leaf. + * + * @return the leaf + */ public String getLeaf() { String result; diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyComparator.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyComparator.java new file mode 100644 index 0000000..60e4dec --- /dev/null +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyComparator.java @@ -0,0 +1,134 @@ +/* + * + */ +package fr.devinsy.statoolinfos.properties; + +import java.util.Comparator; + +import fr.devinsy.statoolinfos.util.CompareUtils; + +/** + * The Class PathPropertyComparator. + */ +public class PathPropertyComparator implements Comparator +{ + public enum Sorting + { + PATH, + VALUE + } + + private Sorting sorting; + + public PathPropertyComparator(final Sorting sorting) + { + // + this.sorting = sorting; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @return the int + */ + @Override + public int compare(final PathProperty alpha, final PathProperty bravo) + { + int result; + + result = compare(alpha, bravo, this.sorting); + + // + return result; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @param sorting + * the sorting + * @return the int + */ + public static int compare(final PathProperty alpha, final PathProperty bravo, final Sorting sorting) + { + int result; + + if (sorting == null) + { + result = 0; + } + else + { + switch (sorting) + { + default: + case PATH: + result = CompareUtils.compare(getPath(alpha), getPath(bravo)); + break; + + case VALUE: + result = CompareUtils.compare(getValue(alpha), getValue(bravo)); + break; + } + } + + // + return result; + } + + /** + * Gets the path. + * + * @param source + * the source + * @return the path + */ + public static String getPath(final PathProperty source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.getPath(); + } + + // + return result; + } + + /** + * Gets the value. + * + * @param source + * the source + * @return the value + */ + public static String getValue(final PathProperty source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.getValue(); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java index b20f2c7..ad9603d 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -242,6 +242,38 @@ public class PathPropertyList extends ArrayList implements PathPro return result; } + /** + * Gets the year leafs. + * + * @param prefix + * the prefix + * @return the year leafs + */ + public PathPropertyList getByYearPrefix(final String prefix) + { + PathPropertyList result; + + result = new PathPropertyList(); + + if (StringUtils.isNotBlank(prefix)) + { + String pattern; + if (prefix.endsWith(".")) + { + pattern = "^" + prefix + "\\d\\d\\d\\d$"; + } + else + { + pattern = "^" + prefix + "\\.\\d\\d\\d\\d$"; + } + + result = getByPattern(pattern); + } + + // + return result; + } + /** * Gets the index property. * @@ -570,6 +602,75 @@ public class PathPropertyList extends ArrayList implements PathPro } } + /** + * Shrink to leaf. + * + * @return the path property list + */ + public PathPropertyList shrinkToLeaf() + { + PathPropertyList result; + + for (PathProperty property : this) + { + property.setPath(property.getLeaf()); + } + + result = this; + + // + return result; + } + + /** + * Sort. + * + * @param sorting + * the sorting + * @return the path property list + */ + public PathPropertyList sort(final PathPropertyComparator.Sorting sorting) + { + PathPropertyList result; + + sort(new PathPropertyComparator(sorting)); + + result = this; + + // + return result; + } + + /** + * Sort by path. + * + * @return the path property list + */ + public PathPropertyList sortByPath() + { + PathPropertyList result; + + result = sort(PathPropertyComparator.Sorting.PATH); + + // + return result; + } + + /** + * Sort by value. + * + * @return the path property list + */ + public PathPropertyList sortByValue() + { + PathPropertyList result; + + result = sort(PathPropertyComparator.Sorting.VALUE); + + // + return result; + } + /** * To string list. *