Skip to content

Commit

Permalink
fix: stats évolutives - on gère les cas 0 et infini + bug fix du mult…
Browse files Browse the repository at this point in the history
…i-choix 'Non renseigné'
  • Loading branch information
Arnaud AMBROSELLI committed Feb 8, 2024
1 parent d8befde commit a7c38b2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
47 changes: 26 additions & 21 deletions dashboard/src/components/EvolutiveStatsViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,32 @@ export default function EvolutiveStatsViewer({ evolutiveStatsIndicators, period,
<p>{fieldStart}</p>
</div>
</div>
<div className="tw-flex tw-basis-1/2 tw-flex-col tw-items-center tw-justify-end tw-gap-y-4">
<div className="tw-flex tw-flex-col tw-items-center tw-justify-around tw-p-4">
<p className="tw-text-6xl tw-font-bold tw-text-main">{Math.round((valueEnd / valueStart) * 1000) / 10}%</p>
<p className="tw-m-0 tw-text-center">
des{' '}
<strong>
{field?.label}: {fieldStart}
</strong>{' '}
au {startDateFormatted.format('DD/MM/YYYY')}
<br />
ont évolué vers <strong>{fieldEnd}</strong> au {endDateFormatted.format('DD/MM/YYYY')}
</p>
</div>
</div>
<div className="tw-flex tw-shrink-0 tw-basis-1/4 tw-flex-col tw-items-center tw-justify-end tw-gap-y-4">
<h5>Au {endDateFormatted.format('DD/MM/YYYY')}</h5>
<div className="tw-flex tw-w-full tw-flex-col tw-items-center tw-justify-around tw-rounded-lg tw-border tw-p-4">
<p className="tw-text-6xl tw-font-bold tw-text-main">{valueEnd}</p>
<p>{fieldEnd}</p>
</div>
</div>
{valueStart !== 0 && (
<>
<div className="tw-flex tw-basis-1/2 tw-flex-col tw-items-center tw-justify-end tw-gap-y-4">
<div className="tw-flex tw-flex-col tw-items-center tw-justify-around tw-p-4">
<p className="tw-text-6xl tw-font-bold tw-text-main">{Math.round((valueEnd / valueStart) * 1000) / 10}%</p>
<p className="tw-m-0 tw-text-center">
des{' '}
<strong>
{field?.label}: {fieldStart}
</strong>{' '}
au {startDateFormatted.format('DD/MM/YYYY')}
<br />
{fieldStart === fieldEnd ? ' sont restés à ' : ' ont évolué vers '}
<strong>{fieldEnd}</strong> au {endDateFormatted.format('DD/MM/YYYY')}
</p>
</div>
</div>
<div className="tw-flex tw-shrink-0 tw-basis-1/4 tw-flex-col tw-items-center tw-justify-end tw-gap-y-4">
<h5>Au {endDateFormatted.format('DD/MM/YYYY')}</h5>
<div className="tw-flex tw-w-full tw-flex-col tw-items-center tw-justify-around tw-rounded-lg tw-border tw-p-4">
<p className="tw-text-6xl tw-font-bold tw-text-main">{valueEnd}</p>
<p>{fieldEnd}</p>
</div>
</div>
</>
)}
</div>
);
}
Expand Down
19 changes: 16 additions & 3 deletions dashboard/src/recoil/evolutiveStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,17 @@ function getValueByField(fieldName: CustomOrPredefinedField['name'], fieldsMap:
if (value === true) return 'Oui';
return 'Non';
}
if (current.type === 'multi-choice') {
if (Array.isArray(value)) {
if (value.length === 0) return ['Non renseigné'];
return value;
}
if (value == null || value === '') {
return ['Non renseigné'];
}
return [value];
}
if (value == null || value === '') {
if (current.type === 'multi-choice') return [];
return 'Non renseigné'; // we cover the case of undefined, null, empty string
}
if (value.includes('Choisissez un genre')) return 'Non renseigné';
Expand Down Expand Up @@ -145,7 +154,10 @@ export const evolutiveStatsPersonSelector = selectorFamily({
// how do we calculate ?
// we start by the most recent version of the person, and we go back in time, day by day, to the beginning of the history

const indicatorsBase = get(evolutiveStatsIndicatorsBaseSelector);
const indicatorsBase = get(evolutiveStatsIndicatorsBaseSelector).filter((f) => {
if (evolutiveStatsIndicators.find((i) => i.fieldName === f.name)) return true;
return false;
});
const fieldsMap: FieldsMap = indicatorsBase.reduce((acc, field) => {
acc[field.name] = field;
return acc;
Expand Down Expand Up @@ -178,7 +190,8 @@ export const evolutiveStatsPersonSelector = selectorFamily({
persons = persons.filter((p) => {
const snapshot = getPersonSnapshotAtDate({ person: p, snapshotDate: minimumDateForEvolutiveStats, fieldsMap });
if (!snapshot) return false;
return getValueByField(indicatorFieldName, fieldsMap, p[indicatorFieldName]).includes(indicator.fromValue);
const isGood = getValueByField(indicatorFieldName, fieldsMap, snapshot[indicatorFieldName]).includes(indicator.fromValue);
return isGood;
});
}

Expand Down

0 comments on commit a7c38b2

Please sign in to comment.