Skip to content

Commit

Permalink
fix: indicateur1-simu (#1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
pom421 authored Dec 5, 2023
1 parent 85c4912 commit 2006980
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ export const CSPModeTable = ({ computer, staff }: CSPModeTableProps) => {
withTooltip
header={getCommonHeader({ firstColumnLabel: "Catégorie socio-professionnelle" })}
body={categories.map((categoryName, categoryIndex) => {
const categoryId = categoryName;
register(`remunerations.${categoryIndex}.categoryId`, { value: categoryId });
register(`remunerations.${categoryIndex}.name`, { value: categoryName });

return {
Expand Down Expand Up @@ -153,7 +151,6 @@ export const CSPModeTable = ({ computer, staff }: CSPModeTableProps) => {

return getCommonBodyColumns({
ageRange,
categoryId,
categoryIndex,
categoryName,
computer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export const Indic1Form = () => {
const {
formState: { isValid },
handleSubmit,
getValues,
watch,
resetField,
control,
Expand All @@ -115,12 +114,12 @@ export const Indic1Form = () => {
}

const currentMode = watch("mode");
const currentRemunerations = watch("remunerations");

// default values for CSP mode, set category to empty if no data only if count is >= 3
const defaultCspModeRemunerations = Object.keys(funnel.effectifs.csp).map<ExternalRemunerations[number]>(
categoryName => ({
name: categoryName,
categoryId: categoryName,
category: ageRanges.reduce(
(newAgeGroups, ageRange) => ({
...newAgeGroups,
Expand Down Expand Up @@ -195,8 +194,6 @@ export const Indic1Form = () => {
? lastCspRemunerations ?? defaultCspModeRemunerations
: lastOtherRemunerations ?? defaultOtherModesRemunerations;

const currentRemunerations = getValues("remunerations");

if (lastMode && currentRemunerations?.length) {
if (lastMode === RemunerationsMode.Enum.CSP) {
setLastCspRemunerations(currentRemunerations as ExternalRemunerations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ export const OtherModesTable = ({ computer, staff, defaultRemunerations }: Other
header={getCommonHeader({ firstColumnLabel: "Niveau ou coefficient hiérarchique" })}
body={remunerationsFields.map<AlternativeTableProps.BodyContent>(
(remunerationsField, remunerationsFieldIndex) => {
const categoryId = remunerationsField.categoryId || remunerationsField.id;
register(`remunerations.${remunerationsFieldIndex}.categoryId`, {
value: categoryId,
deps: `remunerations.${remunerationsFieldIndex}.name`,
});

return {
key: remunerationsField.id,
isDeletable: remunerationsFieldIndex > 0,
Expand Down Expand Up @@ -155,7 +149,6 @@ export const OtherModesTable = ({ computer, staff, defaultRemunerations }: Other

return getCommonBodyColumns({
ageRange,
categoryId,
categoryIndex: remunerationsFieldIndex,
categoryName: remunerationsField.name,
computer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export type Indic1FormType = z.infer<typeof createSteps.indicateur1>;

interface CommonBodyColumnsProps {
ageRange: AgeRange.Enum;
categoryId: string;
categoryIndex: number;
categoryName: string;
computer: IndicateurUnComputer;
Expand All @@ -77,7 +76,6 @@ export const getCommonBodyColumns = ({
menCount = 0,
categoryName,
categoryIndex,
categoryId,
ageRange,
errors,
computer,
Expand Down Expand Up @@ -132,7 +130,7 @@ export const getCommonBodyColumns = ({
},
},
(() => {
const { resultRaw: groupResult } = computer.computeGroup(buildRemunerationKey(categoryId, ageRange));
const { resultRaw: groupResult } = computer.computeGroup(buildRemunerationKey(categoryName, ageRange));
return !Number.isNaN(groupResult) && Number.isFinite(groupResult)
? precisePercentFormat.format(groupResult / 100)
: "-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ export const RecapSimu = () => {
body={remuWithCount.map(category => ({
categoryLabel:
funnel.indicateur1.mode === RemunerationsMode.Enum.CSP
? CSP.Label[category.categoryId as CSP.Enum]
? CSP.Label[category.name as CSP.Enum]
: category.name,
alignCols: "center",
cols: ageRanges.map(ageRange => {
const groupKey = buildRemunerationKey(category.categoryId, ageRange);
const groupKey = buildRemunerationKey(category.name, ageRange);
const canComputeGroup = computerIndicateurUn.canComputeGroup(groupKey);
const groupResult = computerIndicateurUn.computeGroup(groupKey);
return canComputeGroup ? precisePercentFormat.format(groupResult.resultRaw / 100) : "NC";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ export const simuFunnelToDeclarationDTO = (simulation: CreateSimulationDTO): Dec
? "remunerations-coefficient-autre"
: "remunerations-coefficient-branche"
] = {
catégories: indicateur1.remunerations.map(({ name: nom, categoryId }) => ({
catégories: indicateur1.remunerations.map(({ name: nom }) => ({
nom,
tranches: {
[AgeRange.Enum.LESS_THAN_30]: computeGroupIndicateurUn(computerIndicateurUn)(`${categoryId}::29`) || "",
[AgeRange.Enum.FROM_30_TO_39]: computeGroupIndicateurUn(computerIndicateurUn)(`${categoryId}:30:39`) || "",
[AgeRange.Enum.FROM_40_TO_49]: computeGroupIndicateurUn(computerIndicateurUn)(`${categoryId}:40:49`) || "",
[AgeRange.Enum.FROM_50_TO_MORE]: computeGroupIndicateurUn(computerIndicateurUn)(`${categoryId}:50:`) || "",
[AgeRange.Enum.LESS_THAN_30]: computeGroupIndicateurUn(computerIndicateurUn)(`${nom}::29`) || "",
[AgeRange.Enum.FROM_30_TO_39]: computeGroupIndicateurUn(computerIndicateurUn)(`${nom}:30:39`) || "",
[AgeRange.Enum.FROM_40_TO_49]: computeGroupIndicateurUn(computerIndicateurUn)(`${nom}:40:49`) || "",
[AgeRange.Enum.FROM_50_TO_MORE]: computeGroupIndicateurUn(computerIndicateurUn)(`${nom}:50:`) || "",
},
})),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const getCspRemuWithCount = (
) =>
Object.keys(funnelCsp).map<ExternalRemunerations[number]>(categoryName => ({
name: categoryName,
categoryId: categoryName,
category: ageRanges.reduce(
(newAgeGroups, ageRange) => {
const currentAgeRange = remunerations?.find(rem => rem?.name === categoryName)?.category?.[ageRange];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export abstract class AbstractGroupComputer<
const validGroups: ExtendedTotalMetadata["validGroups"] = [];
const additionalMetadata = {} as AdditionalMetadata;

for (const [categoryId, category] of Object.entries(this.input) as Array<[GroupKey, Group]>) {
for (const [categoryName, category] of Object.entries(this.input) as Array<[GroupKey, Group]>) {
const womenCount = category.womenCount || 0;
const menCount = category.menCount || 0;
totalEmployeeCount += menCount + womenCount;
Expand All @@ -77,7 +77,7 @@ export abstract class AbstractGroupComputer<

// Exclure les groupes qui n'ont pas au moins (this.GROUP_COUNT_THRESHOLD) hommes et (this.GROUP_COUNT_THRESHOLD) femmes. (e.g. 3 pour l'indicateur 1, 10 pour les indicateurs 2 ou 3)
if (category.menCount >= this.GROUP_COUNT_THRESHOLD && category.womenCount >= this.GROUP_COUNT_THRESHOLD) {
validGroups.push(categoryId as GroupKey);
validGroups.push(categoryName as GroupKey);
totalGroupCount += menCount + womenCount;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export class IndicateurDeuxComputer extends AbstractGroupComputer<Percentages, o
super();
}

public canComputeGroup(categoryId: CSP.Enum): boolean {
public canComputeGroup(categoryName: CSP.Enum): boolean {
if (!this.input) {
return false;
}
const category = this.input[categoryId];
const category = this.input[categoryName];

if (!category || !(category.menCount >= 10 && category.womenCount >= 10 && category.men && category.women)) {
return false;
Expand Down
9 changes: 4 additions & 5 deletions packages/app/src/common/core-domain/computers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ export const ageRanges = [

export type ExternalRemunerations = Array<{
category: Record<AgeRange.Enum, CountAndAverageSalaries>;
categoryId: string;
name: string;
}>;

export function flattenRemunerations(remunerations: ExternalRemunerations): InputRemunerations {
const flattened: InputRemunerations = {};
for (const { categoryId, category } of remunerations) {
for (const { name, category } of remunerations) {
if (category) {
for (const [ageRange, ageGroup] of Object.entries(category)) {
flattened[buildRemunerationKey(categoryId, ageRange as AgeRange.Enum)] = ageGroup;
flattened[buildRemunerationKey(name, ageRange as AgeRange.Enum)] = ageGroup;
}
}
}
return flattened;
}

export function buildRemunerationKey(categoryId: string, ageRange: AgeRange.Enum): string {
return `${categoryId}:${ageRange}`;
export function buildRemunerationKey(categoryName: string, ageRange: AgeRange.Enum): string {
return `${categoryName}:${ageRange}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ const otherAgeRangesSchema = zodFr
const otherAgeRangeNumbers = zodFr.array(
zodFr.object({
name: zodFr.string().min(1, "Le champ est requis"),
categoryId: zodFr.string().min(1),
category: zodFr.record(zodFr.nativeEnum(AgeRange.Enum), otherAgeRangesSchema),
}),
);
Expand Down Expand Up @@ -129,7 +128,6 @@ export const createSteps = {
remunerations: zodFr.array(
zodFr.object({
name: zodFr.nativeEnum(CSP.Enum),
categoryId: zodFr.string().min(1),
category: zodFr
.record(
zodFr.nativeEnum(AgeRange.Enum),
Expand Down

0 comments on commit 2006980

Please sign in to comment.