Skip to content

Commit

Permalink
#320, #322 update CRP, ACRP and RCPP to fit the new data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
pengyin-shan committed Sep 24, 2024
1 parent 566430e commit f4b07cf
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 201 deletions.
36 changes: 32 additions & 4 deletions src/components/ProgramDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ function CRPCheckboxList({ setCRPChecked, setShowPopUp, zeroCategory }) {

const CRPList = [
"Total CRP",
"Total General Sign-up",
"Total Continuous Sign-Up",
"General Sign-up",
"Continuous Sign-up",
"CREP Only",
"Continuous Non-CREP",
"Farmable Wetland",
Expand Down Expand Up @@ -512,10 +512,10 @@ function CRPCheckboxList({ setCRPChecked, setShowPopUp, zeroCategory }) {
</ListItem>
);
}
if (category !== "CREP Only" && category !== "Continuous Non-CREP" && category !== "Farmable Wetland") {
if (category === "Total CRP") {
return (
<ListItem key={category} disablePadding>
<ListItemButton role={undefined} onClick={handleToggle(value)} dense sx={{ pl: 4 }}>
<ListItemButton role={undefined} onClick={handleToggle(value)} dense>
<Radio
edge="start"
checked={checked === value}
Expand All @@ -537,6 +537,34 @@ function CRPCheckboxList({ setCRPChecked, setShowPopUp, zeroCategory }) {
</ListItem>
);
}
if (category === "General Sign-up" || category === "Continuous Sign-up" || category === "Grassland") {
return (
<Box key={category}>
<ListItem key={category} disablePadding>
<ListItemButton role={undefined} onClick={handleToggle(value)} dense sx={{ pl: 4 }}>
<Radio
edge="start"
checked={checked === value}
tabIndex={-1}
disableRipple
inputProps={{ "aria-labelledby": labelId }}
sx={{
"&.Mui-checked": {
color: "#2f7164"
}
}}
/>
<ListItemText
id={labelId}
primary={category}
primaryTypographyProps={{ fontWeight: 700 }}
className={checked === value ? classes.selected : classes.regular}
/>
</ListItemButton>
</ListItem>
</Box>
);
}
return (
<Box key={category}>
<ListItem key={category} disablePadding>
Expand Down
25 changes: 11 additions & 14 deletions src/components/acep/ACEPTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ function AcepProgramTable({
state = sValue.name;
}
});
let programData = null;
programData = stateData.programs.filter((p) => {
return p.programName.toString() === program;
});
hashmap[state] = {};
attributes.forEach((attribute) => {
const attributeData = programData[0][attribute];
const attributeData = stateData[attribute];
hashmap[state][attribute] = attributeData;
});
});
Expand All @@ -48,7 +44,7 @@ function AcepProgramTable({
Object.entries(hashmap[s]).forEach(([attr, value]) => {
if (attr.includes("Percentage")) {
newRecord[attr] = `${value.toString()}%`;
} else if (attr === "totalAcres" || attr === "totalContracts") {
} else if (attr === "totalAreaInAcres" || attr === "totalContracts") {
newRecord[attr] = `${
value.toLocaleString(undefined, { minimumFractionDigits: 2 }).toString().split(".")[0]
}`;
Expand All @@ -65,16 +61,17 @@ function AcepProgramTable({
attributes.forEach((attribute) => {
let sortMethod = compareWithDollarSign;
if (attribute.includes("Percentage")) sortMethod = compareWithPercentSign;
if (attribute.includes("totalContracts") || attribute.includes("totalAcres")) sortMethod = compareWithNumber;
if (attribute.includes("totalContracts") || attribute.includes("totalAreaInAcres"))
sortMethod = compareWithNumber;
let attrName = attribute
.replace(/([A-Z])/g, " $1")
.trim()
.split(" ")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(" ")
.toUpperCase();
if (attribute === "assistancePaymentInDollars") attrName = "Total Payment in Dollars".toUpperCase();
if (attribute === "assistancePaymentInPercentageNationwide")
if (attribute === "totalPaymentInDollars") attrName = "Total Payment in Dollars".toUpperCase();
if (attribute === "totalPaymentInPercentageNationwide")
attrName = "Total Payment In Percentage Nationwide".toUpperCase();
const json = {
Header: attrName,
Expand All @@ -84,12 +81,12 @@ function AcepProgramTable({
columnPrep.push(json);
});
const columns = React.useMemo(() => columnPrep, []);
const paymentsIndex = columns.findIndex((c) => c.accessor === "assistancePaymentInDollars");
const acresIndex = columns.findIndex((c) => c.accessor === "totalAcres");
const paymentsIndex = columns.findIndex((c) => c.accessor === "totalPaymentInDollars");
const acresIndex = columns.findIndex((c) => c.accessor === "totalAreaInAcres");
const contractsIndex = columns.findIndex((c) => c.accessor === "totalContracts");
const paymentsPercentageIndex = columns.findIndex((c) => c.accessor === "assistancePaymentInPercentageNationwide");
const contractsPercentageIndex = columns.findIndex((c) => c.accessor === "contractsInPercentageNationwide");
const acresPercentageIndex = columns.findIndex((c) => c.accessor === "acresInPercentageNationwide");
const paymentsPercentageIndex = columns.findIndex((c) => c.accessor === "totalPaymentInPercentageNationwide");
const contractsPercentageIndex = columns.findIndex((c) => c.accessor === "totalContractsInPercentageNationwide");
const acresPercentageIndex = columns.findIndex((c) => c.accessor === "totalAreaInPercentageNationwide");
const Styles = styled.div`
padding: 0;
margin: 0;
Expand Down
15 changes: 7 additions & 8 deletions src/components/acep/ACEPTotalMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const MapChart = (props) => {
if (record === undefined || record.length === 0) {
return null;
}
const totalPaymentInDollars = record.programs[0].assistancePaymentInDollars;
const assistancePaymentInPercentageNationwide =
record.programs[0].assistancePaymentInPercentageNationwide;
const totalPaymentInDollars = record.totalPaymentInDollars;
const totalPaymentInPercentageNationwide =
record.totalPaymentInPercentageNationwide;
const hoverContent = (
<div className="map_tooltip">
<div className={classes.tooltip_header}>
Expand All @@ -64,8 +64,8 @@ const MapChart = (props) => {
PCT. Nationwide:
</td>
<td className={classes.tooltip_regularcell_right}>
{assistancePaymentInPercentageNationwide
? `${assistancePaymentInPercentageNationwide} %`
{totalPaymentInPercentageNationwide
? `${totalPaymentInPercentageNationwide} %`
: "0%"}
</td>
</tr>
Expand Down Expand Up @@ -171,9 +171,8 @@ const ACEPTotalMap = ({
const quantizeArray: number[] = [];
const zeroPoints = [];
statePerformance[year].forEach((value) => {
const programRecord = value.programs;
const ACur = programRecord.find((s) => s.programName === program);
const key = "assistancePaymentInDollars";
const ACur = value;
const key = "totalPaymentInDollars";
quantizeArray.push(ACur[key]);
ACur[key] === 0 && zeroPoints.push(value.state);
return null;
Expand Down
23 changes: 12 additions & 11 deletions src/components/crp/CRPTotalMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const MapChart = (props) => {
if (record === undefined || record.length === 0) {
return null;
}
const totalPaymentInDollars = record.programs[0].totalPaymentInDollars;
const totalPaymentInDollars = record.totalPaymentInDollars;
const totalPaymentInPercentageNationwide =
record.programs[0].totalPaymentInPercentageNationwide;
record.totalPaymentInPercentageNationwide;
const hoverContent = (
<div className="map_tooltip">
<div className={classes.tooltip_header}>
Expand Down Expand Up @@ -171,17 +171,18 @@ const CRPTotalMap = ({
const [content, setContent] = useState("");
const quantizeArray: number[] = [];
const zeroPoints = [];
statePerformance[year].forEach((value) => {
const programRecord = value.programs;
const ACur = programRecord.find((s) => s.programName === program);
let key = getValueFromAttrDollar(ACur, attribute);
key = key !== "" ? key : attribute;
quantizeArray.push(ACur[key]);
ACur[key] === 0 && zeroPoints.push(value.state);
return null;
});
// statePerformance[year].forEach((value) => {
// const programRecord = value.programs;
// const ACur = programRecord.find((s) => s.programName === program);
// let key = getValueFromAttrDollar(ACur, attribute);
// key = key !== "" ? key : attribute;
// quantizeArray.push(ACur[key]);
// ACur[key] === 0 && zeroPoints.push(value.state);
// return null;
// });
const category = "Total CRP";
const years = "2018-2022";
statePerformance[year].forEach((value) => quantizeArray.push(value.totalPaymentInDollars));
const maxValue = Math.max(...quantizeArray);
const mapColor = ["#F0F9E8", "#BAE4BC", "#7BCCC4", "#43A2CA", "#0868AC"];
const customScale = legendConfig[category];
Expand Down
6 changes: 4 additions & 2 deletions src/components/crp/CRPTotalTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function App({

// eslint-disable-next-line no-restricted-syntax
statePerformance[year].forEach((value) => {
const totalCrp = value.programs.find((s) => s.programName === "Total CRP");
const totalCrp = value;
let stateName;
stateCodes.forEach((sValue) => {
if (sValue.code.toUpperCase() === value.state.toUpperCase()) {
Expand All @@ -159,7 +159,9 @@ function App({
.toLocaleString(undefined, { minimumFractionDigits: 0 })
.toString()}`,
noFarm: `${totalCrp.totalFarms.toLocaleString(undefined, { minimumFractionDigits: 0 }).toString()}`,
totAcre: `${totalCrp.totalAcre.toLocaleString(undefined, { minimumFractionDigits: 0 }).toString()}`
totAcre: `${totalCrp.totalAreaInAcres
.toLocaleString(undefined, { minimumFractionDigits: 0 })
.toString()}`
};
};
crpTableData.push(newRecord());
Expand Down
77 changes: 43 additions & 34 deletions src/components/crp/CategoryMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,29 @@ const MapChart = (props) => {
let DCur = {};
let ECur = {};
let FCur = {};
record.programs.forEach((value) => {
if (value.programName === "Total General Sign-Up") {
record.subPrograms.forEach((value) => {
if (value.subProgramName === "General Sign-up") {
ACur = value;
} else if (value.programName === "Total Continuous Sign-Up") {
} else if (value.subProgramName === "Continuous Sign-up") {
BCur = value;
value.subPrograms.forEach((subValue) => {
if (subValue.programName === "CREP Only") {
CCur = subValue;
} else if (subValue.programName === "Continuous Non-CREP") {
DCur = subValue;
} else if (subValue.programName === "Farmable Wetland") {
ECur = subValue;
}
});
} else if (value.programName === "Grassland") {
if (BCur.subSubPrograms !== undefined) {
BCur.subSubPrograms.forEach((subSubValue) => {
if (subSubValue.subSubProgramName === "CREP Only") {
CCur = subSubValue;
} else if (subSubValue.subSubProgramName === "Continuous Non-CREP") {
DCur = subSubValue;
} else if (subSubValue.subSubProgramName === "Farmable Wetland") {
ECur = subSubValue;
}
});
}
} else if (value.subProgramName === "Grassland") {
FCur = value;
}
});
if (category === "Total General Sign-Up") {
if (category === "General Sign-up") {
categoryRecord = ACur;
} else if (category === "Total Continuous Sign-Up") {
} else if (category === "Continuous Sign-up") {
categoryRecord = BCur;
} else if (category === "CREP Only") {
categoryRecord = CCur;
Expand All @@ -81,6 +83,12 @@ const MapChart = (props) => {
} else {
categoryRecord = FCur;
}
if (categoryRecord === undefined || Object.values(categoryRecord).length === 0) {
categoryRecord = {
totalPaymentInDollars: 0,
totalPaymentInPercentageNationwide: 0
};
}
const categoryPayment = categoryRecord.totalPaymentInDollars;
const nationwidePercentage = categoryRecord.totalPaymentInPercentageNationwide;
const hoverContent = (
Expand Down Expand Up @@ -205,28 +213,29 @@ const CategoryMap = ({
const zeroPoints = [];

statePerformance[year].forEach((value) => {
const programRecord = value.programs;
const programRecord = value.subPrograms;
let ACur = {};
if (
category === "Total General Sign-Up" ||
category === "Total Continuous Sign-Up" ||
category === "Grassland"
) {
ACur = programRecord.find((s) => s.programName === category);
if (category === "General Sign-up" || category === "Continuous Sign-up" || category === "Grassland") {
ACur = programRecord.find((s) => s.subProgramName === category);
} else if (category === "CREP Only" || category === "Continuous Non-CREP" || category === "Farmable Wetland") {
const contSingUp = programRecord.find((s) => s.programName === "Total Continuous Sign-Up");
const subPrograms = contSingUp.subPrograms;
title = `CRP Total Continuous, ${category} from ${year}`;
subPrograms.forEach((subValue) => {
if (subValue.programName === category) {
ACur = subValue;
}
});
const contSingUp = programRecord.find((s) => s.subProgramName === "Continuous Sign-up");
if (contSingUp) {
const subSubPrograms = contSingUp.subSubPrograms;
title = `CRP Continuous Sign-up, ${category} from ${year}`;

subSubPrograms.forEach((subValue) => {
if (subValue.subSubProgramName === category) {
ACur = subValue;
}
});
}
}
if (ACur) {
let key = getValueFromAttrDollar(ACur, attribute);
key = key !== "" ? key : attribute;
quantizeArray.push(ACur[key]);
ACur[key] === 0 && zeroPoints.push(value.state);
}
let key = getValueFromAttrDollar(ACur, attribute);
key = key !== "" ? key : attribute;
quantizeArray.push(ACur[key]);
ACur[key] === 0 && zeroPoints.push(value.state);
return null;
});
const years = "2018-2022";
Expand Down
Loading

0 comments on commit f4b07cf

Please sign in to comment.