Skip to content

Commit

Permalink
Merge pull request #960 from bcgov/fix/EDX-2791
Browse files Browse the repository at this point in the history
Large FTE values (1xx,xxx.xx) causing issues with some downloadable reports
  • Loading branch information
arcshiftsolutions committed Jul 17, 2024
2 parents a8f594c + c5a846d commit 2a050a0
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.text.ParseException;
import java.util.*;

@Service
Expand Down Expand Up @@ -102,11 +103,20 @@ protected void setValueForGrade(HashMap<String, HeadcountChildNode> nodeMap, Ban
int runningTotalHeadcount = 0;
if (headcountsList != null) {
for (BandResidenceHeadcountResult each : headcountsList) {
String bandKey = each.getBandCode();
runningTotalFTE += Double.parseDouble(each.getFteTotal());
runningTotalHeadcount += Integer.parseInt(each.getHeadcount());
nodeMap.get(bandKey + HEADING).setValueForBand("FTE", each.getFteTotal());
nodeMap.get(bandKey + HEADING).setValueForBand("Headcount", each.getHeadcount());
try {
String bandKey = each.getBandCode();
double fteTotal = numberFormat.parse(each.getFteTotal()).doubleValue();
int headcountTotal = numberFormat.parse(each.getHeadcount()).intValue();

runningTotalFTE += fteTotal;
runningTotalHeadcount += headcountTotal;

nodeMap.get(bandKey + HEADING).setValueForBand("FTE", String.format("%.4f", fteTotal));
nodeMap.get(bandKey + HEADING).setValueForBand("Headcount", String.valueOf(headcountTotal));
} catch (ParseException e) {
log.error("Error parsing number in setValueForGrade - Band of Residence Report: " + e.getMessage());
throw new StudentDataCollectionAPIRuntimeException("Error parsing number in setValueForGrade - Band of Residence Report: " + e.getMessage());
}
}
}
nodeMap.get("allBandsHeading").setValueForBand("FTE", String.format("%.4f", runningTotalFTE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
Expand All @@ -40,6 +41,7 @@ public abstract class BaseReportGenerationService<T> {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

protected static final String FALSE = "false";
protected static final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);

private ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.text.ParseException;
import java.util.*;

@Service
Expand All @@ -39,7 +40,6 @@ public class GradeEnrollmentHeadcountPerSchoolReportService extends BaseReportGe
private static final String TOTALFTE = "totalFTE";
private static final String ALLSCHOOLS = "allSchools";
private static final String SCHOOLTITLE = "schoolTitle";
private static final String DOUBLE_FORMAT = "%,.4f";
private final SdcDistrictCollectionRepository sdcDistrictCollectionRepository;
private final SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository;
private final RestUtils restUtils;
Expand Down Expand Up @@ -165,18 +165,28 @@ protected void setValueForGrade(HashMap<String, HeadcountChildNode> nodeMap, Enr
HeadcountChildNode allSchoolsFTENode = nodeMap.get("totalFTEallSchools");

String schoolID = gradeResult.getSchoolID();
if (nodeMap.containsKey(HEADCOUNT + schoolID)) {
nodeMap.get(HEADCOUNT + schoolID).setValueForGrade(code, gradeResult.getTotalHeadcount());
}
if (nodeMap.containsKey(TOTALFTE + schoolID) && gradeResult.getTotalFteTotal() != null) {
nodeMap.get(TOTALFTE + schoolID).setValueForGrade(code, String.format(DOUBLE_FORMAT, Double.valueOf(gradeResult.getTotalFteTotal())));
}

int currentHeadcountTotal = Integer.parseInt(gradeResult.getTotalHeadcount());
double currentFTETotal = Double.parseDouble(gradeResult.getTotalFteTotal());
int accumulatedHeadcountTotal = Integer.parseInt(allSchoolsHeadcountNode.getValueForGrade(code));
double accumulatedFTETotal = Double.parseDouble(allSchoolsFTENode.getValueForGrade(code));
allSchoolsHeadcountNode.setValueForGrade(code, String.valueOf(accumulatedHeadcountTotal + currentHeadcountTotal));
allSchoolsFTENode.setValueForGrade(code, String.format(DOUBLE_FORMAT, accumulatedFTETotal + currentFTETotal));
try {
if (nodeMap.containsKey(HEADCOUNT + schoolID)) {
nodeMap.get(HEADCOUNT + schoolID).setValueForGrade(code, gradeResult.getTotalHeadcount());
}

if (nodeMap.containsKey(TOTALFTE + schoolID) && gradeResult.getTotalFteTotal() != null) {
double fteTotal = numberFormat.parse(gradeResult.getTotalFteTotal()).doubleValue();
nodeMap.get(TOTALFTE + schoolID).setValueForGrade(code, String.format("%.4f", fteTotal));
}

int currentHeadcountTotal = Integer.parseInt(gradeResult.getTotalHeadcount().replace(",", ""));
double currentFTETotal = numberFormat.parse(gradeResult.getTotalFteTotal()).doubleValue();

int accumulatedHeadcountTotal = Integer.parseInt(allSchoolsHeadcountNode.getValueForGrade(code).replace(",", ""));
double accumulatedFTETotal = numberFormat.parse(allSchoolsFTENode.getValueForGrade(code)).doubleValue();

allSchoolsHeadcountNode.setValueForGrade(code, String.valueOf(accumulatedHeadcountTotal + currentHeadcountTotal));
allSchoolsFTENode.setValueForGrade(code, String.format("%.4f", accumulatedFTETotal + currentFTETotal));
} catch (ParseException e) {
log.error("Exception occurred while writing PDF report for grade enrollment dis per school - parse error :: " + e.getMessage());
throw new StudentDataCollectionAPIRuntimeException("Exception occurred while writing PDF report for grade enrollment dis per school - parse error:: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.text.ParseException;
import java.util.*;

@Service
@Slf4j
Expand All @@ -40,7 +38,6 @@ public class GradeEnrollmentHeadcountReportService extends BaseReportGenerationS
private final SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository;
private final SdcDistrictCollectionRepository sdcDistrictCollectionRepository;
private JasperReport gradeEnrollmentHeadcountReport;
private static final String DOUBLE_FORMAT = "%,.4f";
private ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter();

public GradeEnrollmentHeadcountReportService(SdcSchoolCollectionRepository sdcSchoolCollectionRepository, SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository, SdcDistrictCollectionRepository sdcDistrictCollectionRepository, RestUtils restUtils) {
Expand Down Expand Up @@ -148,22 +145,27 @@ private void addValuesForSectionToMap(HashMap<String, HeadcountChildNode> nodeMa
nodeMap.put(sectionPrefix + "FTETotal", new HeadcountChildNode("FTE Total", FALSE, sequencePrefix + "3", true, true, true, includeKH));
}

public void setValueForGrade(HashMap<String, HeadcountChildNode> nodeMap, EnrollmentHeadcountResult gradeResult){
public void setValueForGrade(HashMap<String, HeadcountChildNode> nodeMap, EnrollmentHeadcountResult gradeResult) {
Optional<SchoolGradeCodes> optionalCode = SchoolGradeCodes.findByValue(gradeResult.getEnrolledGradeCode());
var code = optionalCode.orElseThrow(() ->
new EntityNotFoundException(SchoolGradeCodes.class, "Grade Value", gradeResult.getEnrolledGradeCode()));

nodeMap.get("schoolAgedHeadcount").setValueForGrade(code, gradeResult.getSchoolAgedHeadcount());
nodeMap.get("schoolAgedEligibleForFTE").setValueForGrade(code, gradeResult.getSchoolAgedEligibleForFte());
nodeMap.get("schoolAgedFTETotal").setValueForGrade(code, String.format(DOUBLE_FORMAT, Double.valueOf(gradeResult.getSchoolAgedFteTotal())));

nodeMap.get("adultHeadcount").setValueForGrade(code, gradeResult.getAdultHeadcount());
nodeMap.get("adultEligibleForFTE").setValueForGrade(code, gradeResult.getAdultEligibleForFte());
nodeMap.get("adultFTETotal").setValueForGrade(code, String.format(DOUBLE_FORMAT, Double.valueOf(gradeResult.getAdultFteTotal())));

nodeMap.get("allHeadcount").setValueForGrade(code, gradeResult.getTotalHeadcount());
nodeMap.get("allEligibleForFTE").setValueForGrade(code, gradeResult.getTotalEligibleForFte());
nodeMap.get("allFTETotal").setValueForGrade(code, String.format(DOUBLE_FORMAT, Double.valueOf(gradeResult.getTotalFteTotal())));
try {
nodeMap.get("schoolAgedHeadcount").setValueForGrade(code, gradeResult.getSchoolAgedHeadcount());
nodeMap.get("schoolAgedEligibleForFTE").setValueForGrade(code, gradeResult.getSchoolAgedEligibleForFte());
nodeMap.get("schoolAgedFTETotal").setValueForGrade(code, String.format("%.4f", numberFormat.parse(gradeResult.getSchoolAgedFteTotal()).doubleValue()));

nodeMap.get("adultHeadcount").setValueForGrade(code, gradeResult.getAdultHeadcount());
nodeMap.get("adultEligibleForFTE").setValueForGrade(code, gradeResult.getAdultEligibleForFte());
nodeMap.get("adultFTETotal").setValueForGrade(code, String.format("%.4f", numberFormat.parse(gradeResult.getAdultFteTotal()).doubleValue()));

nodeMap.get("allHeadcount").setValueForGrade(code, gradeResult.getTotalHeadcount());
nodeMap.get("allEligibleForFTE").setValueForGrade(code, gradeResult.getTotalEligibleForFte());
nodeMap.get("allFTETotal").setValueForGrade(code, String.format("%.4f", numberFormat.parse(gradeResult.getTotalFteTotal()).doubleValue()));
} catch (ParseException e) {
log.error("Exception occurred while writing PDF report for grade enrollment dis - parse error :: " + e.getMessage());
throw new StudentDataCollectionAPIRuntimeException("Exception occurred while writing PDF report for grade enrollment dis - parse error :: " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.text.ParseException;
import java.util.*;

@Service
Expand Down Expand Up @@ -141,20 +142,25 @@ protected void setValueForGrade(HashMap<String, HeadcountChildNode> nodeMap, Ref
int totalELL = 0;

for (RefugeeHeadcountResult each : refugeeHeadcounts) {
String schoolKey = each.getSchoolID();
int schoolHeadcount = Integer.parseInt(each.getHeadcount());
double schoolFTE = Double.parseDouble(each.getFteTotal());
int schoolELL = Integer.parseInt(each.getEll());

totalHeadcount += schoolHeadcount;
totalFTE += schoolFTE;
totalELL += schoolELL;

HeadcountChildNode node = nodeMap.getOrDefault(schoolKey + HEADING, new HeadcountChildNode());
node.setValueForRefugee(HEADCOUNT, String.valueOf(schoolHeadcount));
node.setValueForRefugee("FTE", String.format("%.4f", schoolFTE));
node.setValueForRefugee("ELL", String.valueOf(schoolELL));
nodeMap.put(schoolKey + HEADING, node);
try {
String schoolKey = each.getSchoolID();
int schoolHeadcount = numberFormat.parse(each.getHeadcount()).intValue();
double schoolFTE = numberFormat.parse(each.getFteTotal()).doubleValue();
int schoolELL = numberFormat.parse(each.getEll()).intValue();

totalHeadcount += schoolHeadcount;
totalFTE += schoolFTE;
totalELL += schoolELL;

HeadcountChildNode node = nodeMap.getOrDefault(schoolKey + HEADING, new HeadcountChildNode());
node.setValueForRefugee(HEADCOUNT, String.valueOf(schoolHeadcount));
node.setValueForRefugee("FTE", String.format("%.4f", schoolFTE));
node.setValueForRefugee("ELL", String.valueOf(schoolELL));
nodeMap.put(schoolKey + HEADING, node);
} catch (ParseException e) {
log.error("Error parsing number in setValueForGrade - Refugee Report: " + e.getMessage());
throw new StudentDataCollectionAPIRuntimeException("Error parsing number in setValueForGrade - Refugee Report: " + e.getMessage());
}
}

HeadcountChildNode totalNode = nodeMap.getOrDefault(ALL_REFUGEE_HEADING, new HeadcountChildNode());
Expand Down

0 comments on commit 2a050a0

Please sign in to comment.