Search in sources :

Example 6 with GovernmentBodyAnnualSummary

use of com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary in project cia by Hack23.

the class EsvApiImpl method getGovernmentBodyNames.

@Override
public List<String> getGovernmentBodyNames() {
    final Set<String> governmentBodyNameSet = new HashSet<>();
    final Map<Integer, List<GovernmentBodyAnnualSummary>> data = getData();
    for (final List<GovernmentBodyAnnualSummary> list : data.values()) {
        for (final GovernmentBodyAnnualSummary governmentBodyAnnualSummary : list) {
            if (!governmentBodyNameSet.contains(governmentBodyAnnualSummary.getName()) && governmentBodyAnnualSummary.getHeadCount() > 0) {
                governmentBodyNameSet.add(governmentBodyAnnualSummary.getName());
            }
        }
    }
    return new ArrayList<>(governmentBodyNameSet);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) GovernmentBodyAnnualSummary(com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary) HashSet(java.util.HashSet)

Example 7 with GovernmentBodyAnnualSummary

use of com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary in project cia by Hack23.

the class EsvApiImpl method getGovernmentBodyNames.

@Override
public List<String> getGovernmentBodyNames(final String ministry) {
    Map<String, Set<String>> governmentBodyNameSetMinistryMap = new HashMap<>();
    final Set<String> governmentBodyNameSetMapEntry = new HashSet<>();
    governmentBodyNameSetMinistryMap.put(ministry, governmentBodyNameSetMapEntry);
    final Map<Integer, List<GovernmentBodyAnnualSummary>> data = getData();
    for (final List<GovernmentBodyAnnualSummary> list : data.values()) {
        for (final GovernmentBodyAnnualSummary governmentBodyAnnualSummary : list) {
            if (ministry.equalsIgnoreCase(governmentBodyAnnualSummary.getMinistry()) && !governmentBodyNameSetMapEntry.contains(governmentBodyAnnualSummary.getName()) && governmentBodyAnnualSummary.getHeadCount() > 0) {
                governmentBodyNameSetMapEntry.add(governmentBodyAnnualSummary.getName());
            }
        }
    }
    return new ArrayList<>(governmentBodyNameSetMinistryMap.get(ministry));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) GovernmentBodyAnnualSummary(com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary) HashSet(java.util.HashSet)

Example 8 with GovernmentBodyAnnualSummary

use of com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary in project cia by Hack23.

the class GovernmentBodyChartDataManagerImpl method createMinistryGovernmentBodyHeadcountSummaryChart.

@Override
public void createMinistryGovernmentBodyHeadcountSummaryChart(final AbstractOrderedLayout content, final String name) {
    final Map<Integer, List<GovernmentBodyAnnualSummary>> map = esvApi.getDataPerMinistry(name);
    final List<String> governmentBodyNames = esvApi.getGovernmentBodyNames(name);
    final DataSeries dataSeries = new DataSeries();
    final Series series = new Series();
    for (final String govBodyName : governmentBodyNames) {
        series.addSeries(new XYseries().setLabel(govBodyName));
        dataSeries.newSeries();
        for (final Entry<Integer, List<GovernmentBodyAnnualSummary>> entry : map.entrySet()) {
            final List<GovernmentBodyAnnualSummary> item = entry.getValue();
            final Integer totalHeadcount = item.stream().filter((final GovernmentBodyAnnualSummary p) -> p.getName().equalsIgnoreCase(govBodyName)).mapToInt(GovernmentBodyAnnualSummary::getHeadCount).sum();
            if (entry.getKey() != null && totalHeadcount > 0) {
                dataSeries.add(FIRST_OF_JAN + entry.getKey(), totalHeadcount);
            }
        }
    }
    addChart(content, name + ANNUAL_HEADCOUNT_SUMMARY_ALL_GOVERNMENT_BODIES, new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true);
}
Also used : DataSeries(org.dussan.vaadin.dcharts.data.DataSeries) Series(org.dussan.vaadin.dcharts.options.Series) List(java.util.List) DataSeries(org.dussan.vaadin.dcharts.data.DataSeries) GovernmentBodyAnnualSummary(com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary) DCharts(org.dussan.vaadin.dcharts.DCharts) XYseries(org.dussan.vaadin.dcharts.base.elements.XYseries)

Example 9 with GovernmentBodyAnnualSummary

use of com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary in project cia by Hack23.

the class EsvExcelReaderImpl method getDataPerGovernmentBody.

@Override
public Map<Integer, GovernmentBodyAnnualSummary> getDataPerGovernmentBody(final String name) {
    final Map<Integer, GovernmentBodyAnnualSummary> map = new TreeMap<>();
    try {
        final HSSFWorkbook myWorkBook = createGovermentBodyWorkBook();
        for (int sheetNr = 0; sheetNr < myWorkBook.getNumberOfSheets(); sheetNr++) {
            final HSSFSheet mySheet = myWorkBook.getSheetAt(sheetNr);
            addDataForYearToMap(name, map, mySheet);
        }
        myWorkBook.close();
    } catch (final IOException e) {
        LOGGER.warn("Problem loading", e);
    }
    return map;
}
Also used : GovernmentBodyAnnualSummary(com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) IOException(java.io.IOException) TreeMap(java.util.TreeMap) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 10 with GovernmentBodyAnnualSummary

use of com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary in project cia by Hack23.

the class EsvApiTest method getDataDefenceMinistrySuccessTest.

/**
 * Gets the data defence ministry success test.
 *
 * @return the data defence ministry success test
 */
@Test
public void getDataDefenceMinistrySuccessTest() {
    final Map<Integer, List<GovernmentBodyAnnualSummary>> governmentBodyAnnualSummaryData = esvApi.getDataPerMinistry("Försvarsdepartementet");
    assertNotNull(governmentBodyAnnualSummaryData);
    assertEquals(20, governmentBodyAnnualSummaryData.size());
    for (final List<GovernmentBodyAnnualSummary> list : governmentBodyAnnualSummaryData.values()) {
        for (final GovernmentBodyAnnualSummary governmentBodyAnnualSummary : list) {
            assertNotNull(governmentBodyAnnualSummary);
        }
    }
}
Also used : List(java.util.List) GovernmentBodyAnnualSummary(com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary) Test(org.junit.Test)

Aggregations

GovernmentBodyAnnualSummary (com.hack23.cia.service.external.esv.api.GovernmentBodyAnnualSummary)14 List (java.util.List)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 DCharts (org.dussan.vaadin.dcharts.DCharts)2 XYseries (org.dussan.vaadin.dcharts.base.elements.XYseries)2 DataSeries (org.dussan.vaadin.dcharts.data.DataSeries)2 Series (org.dussan.vaadin.dcharts.options.Series)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1