Improved federation service count.

This commit is contained in:
Christian P. MOMON 2022-07-25 15:32:56 +02:00
parent 92f6674bfc
commit c98fc07e1b
8 changed files with 449 additions and 88 deletions

View file

@ -386,6 +386,23 @@ public class Federation extends PathPropertyList
return result;
}
/**
* Gets the member organizations.
*
* @param year
* the year
* @return the member organizations
*/
public Organizations getMemberOrganizations(final Year year)
{
Organizations result;
result = this.organizations.filterMemberFor(year);
//
return result;
}
/**
* Gets the metric month values all.
*
@ -506,6 +523,40 @@ public class Federation extends PathPropertyList
return result;
}
/**
* Gets the service count by.
*
* @param year
* the year
* @return the service count by
*/
public long getServiceCountBy(final Year year)
{
long result;
Organizations organizations = this.organizations.filterMemberFor(year);
result = 0;
for (Organization organization : organizations)
{
for (Service service : organization.getServices().getBy(year))
{
Year memberStart = organization.getMemberStartYear();
Year memberEnd = organization.getMemberEndYear();
Year serviceStart = service.getStartYear();
Year serviceEnd = service.getEndYear();
if (StatoolInfosUtils.overlapp(memberStart, memberEnd, serviceStart, serviceEnd))
{
result += 1;
}
}
}
//
return result;
}
/**
* Gets the all services.
*

View file

@ -501,10 +501,7 @@ public class Organization extends PathPropertyList
{
String result;
LocalDate startDate = StatoolInfosUtils.parseDate(getMemberStartDate());
LocalDate endDate = StatoolInfosUtils.parseDate(getMemberEndDate());
result = StatoolInfosUtils.toHumanDuration(startDate, endDate);
result = StatoolInfosUtils.toHumanDuration(getMemberStartDate(), getMemberEndDate());
//
return result;
@ -515,7 +512,39 @@ public class Organization extends PathPropertyList
*
* @return the member end date
*/
public String getMemberEndDate()
public LocalDate getMemberEndDate()
{
LocalDate result;
result = getDate("organization.memberof." + this.federation.getName() + ".enddate");
//
return result;
}
/**
* Gets the member end date.
*
* @param entityName
* the entity name
* @return the member end date
*/
public LocalDate getMemberEndDate(final String entityName)
{
LocalDate result;
result = getDate("organization.memberof." + entityName + ".enddate");
//
return result;
}
/**
* Gets the member end date.
*
* @return the member end date
*/
public String getMemberEndDateValue()
{
String result;
@ -525,12 +554,67 @@ public class Organization extends PathPropertyList
return result;
}
/**
* Gets the member end year.
*
* @return the member end year
*/
public Year getMemberEndYear()
{
Year result;
LocalDate date = getMemberEndDate();
if (date == null)
{
result = null;
}
else
{
result = Year.from(date);
}
//
return result;
}
/**
* Gets the member start date.
*
* @return the member start date
*/
public String getMemberStartDate()
public LocalDate getMemberStartDate()
{
LocalDate result;
result = getDate("organization.memberof." + this.federation.getName() + ".startdate");
//
return result;
}
/**
* Gets the member start date.
*
* @param entityName
* the entity name
* @return the member start date
*/
public LocalDate getMemberStartDate(final String entityName)
{
LocalDate result;
result = getDate("organization.memberof." + entityName + ".startdate");
//
return result;
}
/**
* Gets the member start date.
*
* @return the member start date
*/
public String getMemberStartDateValue()
{
String result;
@ -540,6 +624,29 @@ public class Organization extends PathPropertyList
return result;
}
/**
* Gets the member start year.
*
* @return the member start year
*/
public Year getMemberStartYear()
{
Year result;
LocalDate date = getMemberStartDate();
if (date == null)
{
result = null;
}
else
{
result = Year.from(date);
}
//
return result;
}
/**
* Gets the status member of.
*
@ -1224,6 +1331,51 @@ public class Organization extends PathPropertyList
return result;
}
/**
* Checks if is member.
*
* @param year
* the year
* @return true, if is member
*/
public boolean isMember(final Year year)
{
boolean result;
if (year == null)
{
result = false;
}
else
{
Year startYear = getMemberStartYear();
if (startYear == null)
{
result = false;
}
else
{
Year endYear = getMemberEndYear();
if (endYear == null)
{
endYear = Year.now();
}
if ((year.isBefore(startYear)) || (year.isAfter(endYear)))
{
result = false;
}
else
{
result = true;
}
}
}
//
return result;
}
/**
* Checks if is valid.
*

View file

@ -18,6 +18,7 @@
*/
package fr.devinsy.statoolinfos.core;
import java.time.Year;
import java.util.ArrayList;
import java.util.Collections;
@ -182,6 +183,31 @@ public class Organizations extends ArrayList<Organization>
return result;
}
/**
* Filter member for.
*
* @param year
* the year
* @return the organizations
*/
public Organizations filterMemberFor(final Year year)
{
Organizations result;
result = new Organizations();
for (Organization organization : this)
{
if (organization.isMember(year))
{
result.add(organization);
}
}
//
return result;
}
/**
* Gets the active service count.
*

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
* Copyright (C) 2020-2022 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of StatoolInfos, simple service statistics tool.
*
@ -18,6 +18,8 @@
*/
package fr.devinsy.statoolinfos.core;
import java.time.LocalDate;
import java.time.Year;
import java.util.ArrayList;
import java.util.Collections;
@ -40,6 +42,42 @@ public class Services extends ArrayList<Service>
super();
}
/**
* Count by year.
*
* @param year
* the year
* @return the long
*/
public long countBy(final Year year)
{
long result;
result = 0;
Year now = Year.now();
for (Service service : this)
{
Year start = service.getStartYear();
Year end = service.getEndYear();
if (start != null)
{
if (end == null)
{
end = now;
}
if ((!start.isAfter(year) && (!end.isBefore(year))))
{
result += 1;
}
}
}
//
return result;
}
/**
* Gets the by.
*
@ -117,6 +155,95 @@ public class Services extends ArrayList<Service>
return result;
}
/**
* Gets the by.
*
* @param year
* the year
* @return the by
*/
public Services getBy(final Year year)
{
Services result;
result = new Services();
if (year != null)
{
for (Service service : this)
{
Year startYear = service.getStartYear();
Year endYear = service.getEndYear();
if (endYear == null)
{
endYear = Year.now();
}
if ((startYear != null) && (!year.isBefore(startYear)) && (!year.isAfter(endYear)))
{
result.add(service);
}
}
}
//
return result;
}
/**
* Gets the older.
*
* @return the older
*/
public Service getOldestService()
{
Service result;
result = null;
LocalDate oldestDate = null;
for (Service current : this)
{
LocalDate date = current.getStartDate();
if (date != null)
{
LocalDate currentDate = current.getStartDate();
if ((result == null) || (currentDate.isBefore(oldestDate)))
{
result = current;
oldestDate = currentDate;
}
}
}
//
return result;
}
/**
* Gets the oldest year.
*
* @return the oldest year
*/
public Year getOldestStartYear()
{
Year result;
Service oldestService = getOldestService();
if (oldestService == null)
{
result = null;
}
else
{
result = oldestService.getStartYear();
}
//
return result;
}
/**
* Reverse.
*

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
* Copyright (C) 2020-2022 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of StatoolInfos, simple service statistics tool.
*
@ -27,6 +27,7 @@ import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.Year;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@ -206,6 +207,63 @@ public class StatoolInfosUtils
return new Date().getTime();
}
/**
* Overlapp.
*
* @param start1
* the start 1
* @param end1
* the end 1
* @param start2
* the start 2
* @param end2
* the end 2
* @return true, if successful
*/
public static boolean overlapp(final Year start1, final Year end1, final Year start2, final Year end2)
{
boolean result;
if ((start1 == null) || (start2 == null))
{
result = false;
}
else
{
Year end11;
if (end1 == null)
{
end11 = Year.now();
}
else
{
end11 = end1;
}
Year end22;
if (end2 == null)
{
end22 = Year.now();
}
else
{
end22 = end2;
}
if ((end22.isBefore(start1)) || (start2.isAfter(end11)))
{
result = false;
}
else
{
result = true;
}
}
//
return result;
}
/**
* Parses the date.
*
@ -235,6 +293,10 @@ public class StatoolInfosUtils
{
result = LocalDate.parse("01/" + date, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
}
else if (date.matches("\\d{4}-\\d{2}"))
{
result = LocalDate.parse(date + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
else
{
result = null;

View file

@ -1451,7 +1451,23 @@ public class ChartHtmlizer
{
String result;
result = htmlizeServiceCountYearChart(federation.getServices(), federation.getStartYear());
BarChart chart;
chart = new BarChart("Nombre de services");
chart.addDataset("Services");
Year current = federation.getStartYear();
Year now = Year.now();
while (!current.isAfter(now))
{
long count = federation.getServiceCountBy(current);
chart.add(String.valueOf(current), count, ChartColor.YELLOW);
current = current.plusYears(1);
}
result = BarChartView.build(chart);
//
return result;
@ -1531,36 +1547,11 @@ public class ChartHtmlizer
if (first != null)
{
int now = LocalDate.now().getYear();
int now = Year.now().getValue();
int current = first;
while (current <= now)
{
long count = 0;
for (Service service : services)
{
LocalDate startDate = service.getStartDate();
LocalDate endDate = service.getEndDate();
if (startDate != null)
{
int start = startDate.getYear();
int end;
if (endDate == null)
{
end = now;
}
else
{
end = endDate.getYear();
}
if ((current >= start) && (current <= end))
{
count += 1;
}
}
}
long count = services.countBy(Year.of(current));
chart.add(String.valueOf(current), count, ChartColor.YELLOW);
current += 1;

View file

@ -84,10 +84,10 @@ public class OrganizationHeaderView
data.setContent("organizationMemberOfWord", ":");
}
data.setContent("organizationMemberStartDate", StringUtils.defaultIfBlank(organization.getMemberStartDate(), "n/a"));
data.setContent("organizationMemberEndDate", StringUtils.defaultIfBlank(organization.getMemberEndDate(), "n/a"));
data.setContent("organizationMemberStartDate", StringUtils.defaultIfBlank(organization.getMemberStartDateValue(), "n/a"));
data.setContent("organizationMemberEndDate", StringUtils.defaultIfBlank(organization.getMemberEndDateValue(), "n/a"));
data.setContent("organizationMemberAge", StringUtils.defaultIfBlank(organization.getMemberAge(), "n/a"));
if (StringUtils.isBlank(organization.getMemberEndDate()))
if (StringUtils.isBlank(organization.getMemberEndDateValue()))
{
data.setAttribute("organizationMemberEndDateData", "style", "display: none;");
}

View file

@ -24,8 +24,6 @@ import java.net.URL;
import java.time.LocalDate;
import java.time.Year;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Matcher;
@ -315,53 +313,7 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
{
LocalDate result;
String value = get(path);
if (value == null)
{
result = null;
}
else
{
String pattern;
if (value.matches("\\d{1,2}/\\d{1,2}/\\d{4}"))
{
pattern = "dd/MM/yyyy";
}
else if (value.matches("\\d{4}-\\d{2}-\\d{2}"))
{
pattern = "yyyy-MM-dd";
}
else if (value.matches("\\d{1,2}/\\d{4}"))
{
value = "01/" + value;
pattern = "dd/MM/yyyy";
}
else if (value.matches("\\d{4}-\\d{2}"))
{
value = value + "-01";
pattern = "yyyy-MM-dd";
}
else
{
pattern = null;
}
if (pattern == null)
{
result = null;
}
else
{
try
{
result = LocalDate.parse(value, DateTimeFormatter.ofPattern(pattern));
}
catch (DateTimeParseException exception)
{
result = null;
}
}
}
result = StatoolInfosUtils.parseDate(get(path));
//
return result;