Improved PathPropertyList methods.

This commit is contained in:
Christian P. MOMON 2021-01-16 03:25:00 +01:00
parent abb9822cb1
commit 28fe19914c
4 changed files with 248 additions and 7 deletions

View file

@ -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.PieChart.Position;
import fr.devinsy.statoolinfos.htmlize.charts.PieChartView; import fr.devinsy.statoolinfos.htmlize.charts.PieChartView;
import fr.devinsy.statoolinfos.properties.PathProperty; import fr.devinsy.statoolinfos.properties.PathProperty;
import fr.devinsy.statoolinfos.properties.PathPropertyList;
import fr.devinsy.statoolinfos.stats.StatAgent; import fr.devinsy.statoolinfos.stats.StatAgent;
import fr.devinsy.statoolinfos.stats.country.CountryStats; import fr.devinsy.statoolinfos.stats.country.CountryStats;
import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats;
@ -267,13 +268,13 @@ public class Htmlizer
BarChart chart; BarChart chart;
chart = new BarChart("Nombre de membres"); chart = new BarChart("Nombre de membres");
for (PathProperty property : federation.getByPrefix("metrics.federation.members.count"))
{ PathPropertyList values = federation.getByYearPrefix("metrics.federation.members.count").sortByPath();
if (property.getLeaf().matches("\\d\\d\\d\\d"))
for (PathProperty property : values)
{ {
chart.add(property.getLeaf(), Double.parseDouble(property.getValue()), ChartColor.GREEN); chart.add(property.getLeaf(), Double.parseDouble(property.getValue()), ChartColor.GREEN);
} }
}
result = BarChartView.build(chart); result = BarChartView.build(chart);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org> * Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of StatoolInfos, simple service statistics tool. * 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() public String getLeaf()
{ {
String result; String result;

View file

@ -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<PathProperty>
{
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;
}
}

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org> * Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of StatoolInfos, simple service statistics tool. * This file is part of StatoolInfos, simple service statistics tool.
* *
@ -242,6 +242,38 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
return result; 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. * Gets the index property.
* *
@ -570,6 +602,75 @@ public class PathPropertyList extends ArrayList<PathProperty> 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. * To string list.
* *