Skip to content

Commit

Permalink
Merge pull request #376 from bcgov/fix/csf-headcounts
Browse files Browse the repository at this point in the history
Adds separate headcounts for CSF vs non CSF schools
  • Loading branch information
mightycox authored Dec 22, 2023
2 parents 4d3ed0f + c51050a commit d8ee062
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package ca.bc.gov.educ.studentdatacollection.api.helpers;

import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolGradeCodes;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity;
import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionRepository;
import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionStudentRepository;
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.*;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.function.Function;

@Component
@Slf4j
@EqualsAndHashCode(callSuper = true)
public class CsfFrenchHeadcountHelper extends HeadcountHelper<CsfFrenchHeadcountResult> {
private static final String FRANCO_TITLE = "Programme Francophone";
private static final String ADULT_TITLE = "Adult";
private static final String SCHOOL_AGED_TITLE = "School-Aged";
private static final String FRANCO_TOTAL_TITLE = "totalFrancophone";
private static final String FRANCO_SCHOOL_AGE_TITLE = "schoolAgedFrancophone";
private static final String FRANCO_ADULT_TITLE = "adultFrancophone";
private static final String ELIGIBLE_TITLE = "Eligible";
private static final String REPORTED_TITLE = "Reported";
private static final String NOT_REPORTED_TITLE = "Not Reported";
private static final List<String> HEADER_COLUMN_TITLES = List.of(ELIGIBLE_TITLE, REPORTED_TITLE, NOT_REPORTED_TITLE);

public CsfFrenchHeadcountHelper(SdcSchoolCollectionRepository sdcSchoolCollectionRepository, SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository) {
super(sdcSchoolCollectionRepository, sdcSchoolCollectionStudentRepository);
headcountMethods = getHeadcountMethods();
sectionTitles = getSelectionTitles();
rowTitles = getRowTitles();
gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList();
}
public void setComparisonValues(SdcSchoolCollectionEntity sdcSchoolCollectionEntity, List<HeadcountHeader> headcountHeaderList) {
UUID previousCollectionID = getPreviousSeptemberCollectionID(sdcSchoolCollectionEntity);
List<HeadcountHeader> previousHeadcountHeaderList = getHeaders(previousCollectionID);
setComparisonValues(headcountHeaderList, previousHeadcountHeaderList);
}

public List<HeadcountHeader> getHeaders(UUID sdcSchoolCollectionID) {
FrenchHeadcountHeaderResult result = sdcSchoolCollectionStudentRepository.getFrenchHeadersBySchoolId(sdcSchoolCollectionID);
List<HeadcountHeader> headcountHeaderList = new ArrayList<>();
HeadcountHeader headcountHeader = new HeadcountHeader();
headcountHeader.setColumns(new HashMap<>());
headcountHeader.setTitle(FRANCO_TITLE);
headcountHeader.setOrderedColumnTitles(HEADER_COLUMN_TITLES);
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalFrancophone()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedFrancophone()).build());
headcountHeader.getColumns().put(NOT_REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(Long.parseLong(result.getAllStudents()) - Long.parseLong(result.getReportedFrancophone()))).build());
headcountHeaderList.add(headcountHeader);
return headcountHeaderList;
}

private Map<String, Function<CsfFrenchHeadcountResult, String>> getHeadcountMethods() {
Map<String, Function<CsfFrenchHeadcountResult, String>> headcountMethods = new HashMap<>();
headcountMethods.put(FRANCO_TOTAL_TITLE, CsfFrenchHeadcountResult::getTotalFrancophone);
headcountMethods.put(FRANCO_SCHOOL_AGE_TITLE, CsfFrenchHeadcountResult::getSchoolAgedFrancophone);
headcountMethods.put(FRANCO_ADULT_TITLE, CsfFrenchHeadcountResult::getAdultFrancophone);
return headcountMethods;
}

private Map<String, String> getSelectionTitles() {
Map<String, String> sectionTitles = new HashMap<>();
sectionTitles.put(FRANCO_TOTAL_TITLE, FRANCO_TITLE);
sectionTitles.put(FRANCO_SCHOOL_AGE_TITLE, FRANCO_TITLE);
sectionTitles.put(FRANCO_ADULT_TITLE, FRANCO_TITLE);
return sectionTitles;
}
private Map<String, String> getRowTitles() {
Map<String, String> rowTitles = new LinkedHashMap<>();
rowTitles.put(FRANCO_TOTAL_TITLE, FRANCO_TITLE);
rowTitles.put(FRANCO_SCHOOL_AGE_TITLE, SCHOOL_AGED_TITLE);
rowTitles.put(FRANCO_ADULT_TITLE, ADULT_TITLE);
return rowTitles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class FrenchHeadcountHelper extends HeadcountHelper<FrenchHeadcountResult
private static final String CORE_FRENCH_TITLE = "Core French";
private static final String EARLY_FRENCH_TITLE = "Early French Immersion";
private static final String LATE_FRENCH_TITLE = "Late French Immersion";
private static final String FRANCO_TITLE = "Programme Francophone";
private static final String TOTAL_FRENCH_TITLE = "All French Programs";
private static final String ADULT_TITLE = "Adult";
private static final String SCHOOL_AGED_TITLE = "School-Aged";
Expand All @@ -40,9 +39,6 @@ public class FrenchHeadcountHelper extends HeadcountHelper<FrenchHeadcountResult
private static final String LATE_TOTAL_TITLE = "totalLateFrench";
private static final String LATE_SCHOOL_AGE_TITLE = "schoolAgedLateFrench";
private static final String LATE_ADULT_TITLE = "adultLateFrench";
private static final String FRANCO_TOTAL_TITLE = "totalFrancophone";
private static final String FRANCO_SCHOOL_AGE_TITLE = "schoolAgedFrancophone";
private static final String FRANCO_ADULT_TITLE = "adultFrancophone";
private static final String ALL_TOTAL_TITLE = "allTotal";
private static final String ALL_SCHOOL_AGE_TITLE = "allSchoolAged";
private static final String ALL_ADULT_TITLE = "allAdult";
Expand All @@ -64,7 +60,7 @@ public void setComparisonValues(SdcSchoolCollectionEntity sdcSchoolCollectionEnt
public List<HeadcountHeader> getHeaders(UUID sdcSchoolCollectionID) {
FrenchHeadcountHeaderResult result = sdcSchoolCollectionStudentRepository.getFrenchHeadersBySchoolId(sdcSchoolCollectionID);
List<HeadcountHeader> headcountHeaderList = new ArrayList<>();
Arrays.asList(CORE_FRENCH_TITLE, EARLY_FRENCH_TITLE, LATE_FRENCH_TITLE, FRANCO_TITLE).forEach(headerTitle -> {
Arrays.asList(CORE_FRENCH_TITLE, EARLY_FRENCH_TITLE, LATE_FRENCH_TITLE).forEach(headerTitle -> {
HeadcountHeader headcountHeader = new HeadcountHeader();
headcountHeader.setColumns(new HashMap<>());
headcountHeader.setTitle(headerTitle);
Expand All @@ -85,11 +81,6 @@ public List<HeadcountHeader> getHeaders(UUID sdcSchoolCollectionID) {
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedLateFrench()).build());
headcountHeader.getColumns().put(NOT_REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(Long.parseLong(result.getAllStudents()) - Long.parseLong(result.getReportedLateFrench()))).build());
}
case FRANCO_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalFrancophone()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedFrancophone()).build());
headcountHeader.getColumns().put(NOT_REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(Long.parseLong(result.getAllStudents()) - Long.parseLong(result.getReportedFrancophone()))).build());
}
default -> {
log.error("Unexpected header title. This cannot happen::" + headerTitle);
throw new StudentDataCollectionAPIRuntimeException("Unexpected header title. This cannot happen::" + headerTitle);
Expand All @@ -112,9 +103,6 @@ private Map<String, Function<FrenchHeadcountResult, String>> getHeadcountMethods
headcountMethods.put(LATE_TOTAL_TITLE, FrenchHeadcountResult::getTotalLateFrench);
headcountMethods.put(LATE_SCHOOL_AGE_TITLE, FrenchHeadcountResult::getSchoolAgedLateFrench);
headcountMethods.put(LATE_ADULT_TITLE, FrenchHeadcountResult::getAdultLateFrench);
headcountMethods.put(FRANCO_TOTAL_TITLE, FrenchHeadcountResult::getTotalFrancophone);
headcountMethods.put(FRANCO_SCHOOL_AGE_TITLE, FrenchHeadcountResult::getSchoolAgedFrancophone);
headcountMethods.put(FRANCO_ADULT_TITLE, FrenchHeadcountResult::getAdultFrancophone);
headcountMethods.put(ALL_TOTAL_TITLE, FrenchHeadcountResult::getTotalTotals);
headcountMethods.put(ALL_SCHOOL_AGE_TITLE, FrenchHeadcountResult::getSchoolAgedTotals);
headcountMethods.put(ALL_ADULT_TITLE, FrenchHeadcountResult::getAdultTotals);
Expand All @@ -131,9 +119,6 @@ private Map<String, String> getSelectionTitles() {
sectionTitles.put(LATE_TOTAL_TITLE, LATE_FRENCH_TITLE);
sectionTitles.put(LATE_SCHOOL_AGE_TITLE, LATE_FRENCH_TITLE);
sectionTitles.put(LATE_ADULT_TITLE, LATE_FRENCH_TITLE);
sectionTitles.put(FRANCO_TOTAL_TITLE, FRANCO_TITLE);
sectionTitles.put(FRANCO_SCHOOL_AGE_TITLE, FRANCO_TITLE);
sectionTitles.put(FRANCO_ADULT_TITLE, FRANCO_TITLE);
sectionTitles.put(ALL_TOTAL_TITLE, TOTAL_FRENCH_TITLE);
sectionTitles.put(ALL_SCHOOL_AGE_TITLE, TOTAL_FRENCH_TITLE);
sectionTitles.put(ALL_ADULT_TITLE, TOTAL_FRENCH_TITLE);
Expand All @@ -150,9 +135,6 @@ private Map<String, String> getRowTitles() {
rowTitles.put(LATE_TOTAL_TITLE, LATE_FRENCH_TITLE);
rowTitles.put(LATE_SCHOOL_AGE_TITLE, SCHOOL_AGED_TITLE);
rowTitles.put(LATE_ADULT_TITLE, ADULT_TITLE);
rowTitles.put(FRANCO_TOTAL_TITLE, FRANCO_TITLE);
rowTitles.put(FRANCO_SCHOOL_AGE_TITLE, SCHOOL_AGED_TITLE);
rowTitles.put(FRANCO_ADULT_TITLE, ADULT_TITLE);
rowTitles.put(ALL_TOTAL_TITLE, TOTAL_FRENCH_TITLE);
rowTitles.put(ALL_SCHOOL_AGE_TITLE, SCHOOL_AGED_TITLE);
rowTitles.put(ALL_ADULT_TITLE, ADULT_TITLE);
Expand Down
Loading

0 comments on commit d8ee062

Please sign in to comment.