Skip to content

Commit

Permalink
Merge pull request #1199 from IFRCGo/fix/appeal-stats
Browse files Browse the repository at this point in the history
Fix appeals statistics calculation
  • Loading branch information
frozenhelium authored Jun 20, 2024
2 parents a3e0bc8 + d9491a2 commit 0a68faa
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-panthers-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"go-web-app": patch
---

Fix appeals based statistics calculation
4 changes: 2 additions & 2 deletions app/src/components/domain/ActiveOperationMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ function ActiveOperationMap(props: Props) {

return {
...baseQuery,
region: isDefined(regionId) ? [regionId] : undefined,
country: isDefined(countryId) ? [countryId] : undefined,
region: isDefined(regionId) ? regionId : undefined,
country: isDefined(countryId) ? countryId : undefined,
};
},
[variant, regionId, filter, limit, countryId],
Expand Down
20 changes: 10 additions & 10 deletions app/src/components/domain/AppealsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function AppealsTable(props: Props) {

const columns = useMemo(
() => ([
createDateColumn<AppealListItem, string>(
createDateColumn<AppealListItem, number>(
'start_date',
strings.appealsTableStartDate,
(item) => item.start_date,
Expand All @@ -129,7 +129,7 @@ function AppealsTable(props: Props) {
columnClassName: styles.startDate,
},
),
createStringColumn<AppealListItem, string>(
createStringColumn<AppealListItem, number>(
'atype',
strings.appealsTableType,
(item) => item.atype_display,
Expand All @@ -138,15 +138,15 @@ function AppealsTable(props: Props) {
columnClassName: styles.appealType,
},
),
createStringColumn<AppealListItem, string>(
createStringColumn<AppealListItem, number>(
'code',
strings.appealsTableCode,
(item) => item.code,
{
columnClassName: styles.code,
},
),
createLinkColumn<AppealListItem, string>(
createLinkColumn<AppealListItem, number>(
'operation',
strings.appealsTableOperation,
(item) => item.name,
Expand All @@ -155,13 +155,13 @@ function AppealsTable(props: Props) {
urlParams: { emergencyId: item.event },
}),
),
createStringColumn<AppealListItem, string>(
createStringColumn<AppealListItem, number>(
'dtype',
strings.appealsTableDisastertype,
(item) => item.dtype?.name,
{ sortable: true },
),
createNumberColumn<AppealListItem, string>(
createNumberColumn<AppealListItem, number>(
'amount_requested',
strings.appealsTableRequestedAmount,
(item) => item.amount_requested,
Expand All @@ -170,7 +170,7 @@ function AppealsTable(props: Props) {
suffix: ' CHF',
},
),
createProgressColumn<AppealListItem, string>(
createProgressColumn<AppealListItem, number>(
'amount_funded',
strings.appealsTableFundedAmount,
(item) => (
Expand All @@ -182,7 +182,7 @@ function AppealsTable(props: Props) {
{ sortable: true },
),
variant !== 'country'
? createLinkColumn<AppealListItem, string>(
? createLinkColumn<AppealListItem, number>(
'country',
strings.appealsTableCountry,
(item) => item.country?.name,
Expand Down Expand Up @@ -225,8 +225,8 @@ function AppealsTable(props: Props) {

return {
...baseQuery,
country: isDefined(countryId) ? [countryId] : undefined,
region: isDefined(regionId) ? [regionId] : undefined,
country: isDefined(countryId) ? countryId : undefined,
region: isDefined(regionId) ? regionId : undefined,
};
},
[
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/domain/RegionKeyFigures/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ function RegionKeyFigures(props: Props) {
icon={<FundingCoverageIcon />}
className={styles.keyFigure}
value={getPercentage(
aggregatedAppealResponse?.amount_funded,
aggregatedAppealResponse?.amount_requested,
aggregatedAppealResponse?.amount_funded_dref_included,
aggregatedAppealResponse?.amount_requested_dref_included,
)}
suffix="%"
compactValue
Expand Down
20 changes: 10 additions & 10 deletions app/src/views/AllAppeals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export function Component() {
ordering,
atype: filterAppealType,
dtype: filterDisasterType,
country: isDefined(filterCountry) ? [filterCountry] : undefined,
region: isDefined(filterRegion) ? [filterRegion] : undefined,
country: isDefined(filterCountry) ? filterCountry : undefined,
region: isDefined(filterRegion) ? filterRegion : undefined,
start_date__gte: filter.startDateAfter,
start_date__lte: filter.startDateBefore,
}),
Expand All @@ -170,7 +170,7 @@ export function Component() {

const columns = useMemo(
() => ([
createDateColumn<AppealListItem, string>(
createDateColumn<AppealListItem, number>(
'start_date',
strings.allAppealsStartDate,
(item) => item.start_date,
Expand All @@ -179,7 +179,7 @@ export function Component() {
columnClassName: styles.startDate,
},
),
createStringColumn<AppealListItem, string>(
createStringColumn<AppealListItem, number>(
'atype',
strings.allAppealsType,
(item) => item.atype_display,
Expand All @@ -188,15 +188,15 @@ export function Component() {
columnClassName: styles.appealType,
},
),
createStringColumn<AppealListItem, string>(
createStringColumn<AppealListItem, number>(
'code',
strings.allAppealsCode,
(item) => item.code,
{
columnClassName: styles.code,
},
),
createLinkColumn<AppealListItem, string>(
createLinkColumn<AppealListItem, number>(
'operation',
strings.allAppealsOperation,
(item) => item.name,
Expand All @@ -206,12 +206,12 @@ export function Component() {
}),
{ sortable: true },
),
createStringColumn<AppealListItem, string>(
createStringColumn<AppealListItem, number>(
'dtype',
strings.allAppealsDisasterType,
(item) => item.dtype?.name,
),
createNumberColumn<AppealListItem, string>(
createNumberColumn<AppealListItem, number>(
'amount_requested',
strings.allAppealsRequestedAmount,
(item) => item.amount_requested,
Expand All @@ -220,7 +220,7 @@ export function Component() {
suffix: ' CHF',
},
),
createProgressColumn<AppealListItem, string>(
createProgressColumn<AppealListItem, number>(
'amount_funded',
strings.allAppealsFundedAmount,
// FIXME: use progress function
Expand All @@ -235,7 +235,7 @@ export function Component() {
columnClassName: styles.funding,
},
),
createLinkColumn<AppealListItem, string>(
createLinkColumn<AppealListItem, number>(
'country',
strings.allAppealsCountry,
(item) => item.country?.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ interface Props {
active_drefs: number | null;
active_appeals: number | null;
target_population: number | null;
amount_requested: number | null;
amount_requested_dref_included: number | null;
amount_funded: number | null;
amount_requested: number | null;
amount_funded_dref_included: number | null;
}
}

Expand Down Expand Up @@ -81,8 +82,8 @@ function CountryKeyFigures(props: Props) {
icon={<FundingCoverageIcon />}
className={styles.keyFigure}
value={getPercentage(
data.amount_funded,
data.amount_requested,
data.amount_funded_dref_included,
data.amount_requested_dref_included,
)}
suffix="%"
compactValue
Expand Down
16 changes: 8 additions & 8 deletions app/src/views/CountryOngoingActivitiesEmergencies/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function Component(props: BaseProps) {
return {
...baseQuery,
region: undefined,
country: countryId ? [Number(countryId)] : undefined,
country: countryId ? Number(countryId) : undefined,
};
},
[filter, limit, countryId],
Expand Down Expand Up @@ -232,7 +232,7 @@ export function Component(props: BaseProps) {

const columns = useMemo(
() => ([
createDateColumn<AppealListItem, string>(
createDateColumn<AppealListItem, number>(
'start_date',
strings.appealsTableStartDate,
(item) => item.start_date,
Expand All @@ -241,7 +241,7 @@ export function Component(props: BaseProps) {
columnClassName: styles.startDate,
},
),
createStringColumn<AppealListItem, string>(
createStringColumn<AppealListItem, number>(
'atype',
strings.appealsTableType,
(item) => item.atype_display,
Expand All @@ -250,15 +250,15 @@ export function Component(props: BaseProps) {
columnClassName: styles.appealType,
},
),
createStringColumn<AppealListItem, string>(
createStringColumn<AppealListItem, number>(
'code',
strings.appealsTableCode,
(item) => item.code,
{
columnClassName: styles.code,
},
),
createLinkColumn<AppealListItem, string>(
createLinkColumn<AppealListItem, number>(
'operation',
strings.appealsTableOperation,
(item) => item.name,
Expand All @@ -267,13 +267,13 @@ export function Component(props: BaseProps) {
urlParams: { emergencyId: item.event },
}),
),
createStringColumn<AppealListItem, string>(
createStringColumn<AppealListItem, number>(
'dtype',
strings.appealsTableDisastertype,
(item) => item.dtype?.name,
{ sortable: true },
),
createNumberColumn<AppealListItem, string>(
createNumberColumn<AppealListItem, number>(
'amount_requested',
strings.appealsTableRequestedAmount,
(item) => item.amount_requested,
Expand All @@ -282,7 +282,7 @@ export function Component(props: BaseProps) {
suffix: ' CHF',
},
),
createProgressColumn<AppealListItem, string>(
createProgressColumn<AppealListItem, number>(
'amount_funded',
strings.appealsTableFundedAmount,
// FIXME: use progress function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ function CountryHistoricalKeyFigures(props: Props) {
<KeyFigure
icon={<FundingIcon />}
className={styles.keyFigure}
value={data.total_amount_requested}
value={data.amount_funded_dref_included}
compactValue
label={strings.keyFiguresFundingRequirements}
/>
<KeyFigure
icon={<FundingCoverageIcon />}
className={styles.keyFigure}
value={getPercentage(
data.total_amount_funded,
data.total_amount_requested,
data.amount_funded_dref_included,
data.amount_requested_dref_included,
)}
suffix="%"
compactValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function EmergenciesOverMonth(props: Props) {
url: '/api/v2/country/{id}/disaster-monthly-count/',
pathVariables: { id: countryId },
query: {
start_date: startDate,
end_date: endDate,
start_date_from: startDate,
start_date_to: endDate,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ function PastEventsChart(props: Props) {
url: '/api/v2/country/{id}/historical-disaster/',
pathVariables: { id: countryId },
query: isDefined(selectedTimePeriod) ? {
start_date: encodeDate(selectedTimePeriod.startDate),
end_date: encodeDate(selectedTimePeriod.endDate),
start_date_from: encodeDate(selectedTimePeriod.startDate),
start_date_to: encodeDate(selectedTimePeriod.endDate),
} : undefined,
});

Expand Down
8 changes: 4 additions & 4 deletions app/src/views/CountryProfilePreviousEvents/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export function Component() {
url: '/api/v2/country/{id}/disaster-count/',
pathVariables: { id: countryId },
query: isDefined(selectedTimePeriod) ? ({
start_date: encodeDate(selectedTimePeriod.startDate),
end_date: encodeDate(selectedTimePeriod.endDate),
start_date_from: encodeDate(selectedTimePeriod.startDate),
start_date_to: encodeDate(selectedTimePeriod.endDate),
}) : undefined,
});

Expand All @@ -135,8 +135,8 @@ export function Component() {
url: '/api/v2/country/{id}/figure/',
pathVariables: { id: Number(countryId) },
query: isDefined(selectedTimePeriod) ? ({
start_date: encodeDate(selectedTimePeriod.startDate),
end_date: encodeDate(selectedTimePeriod.endDate),
start_date_from: encodeDate(selectedTimePeriod.startDate),
start_date_to: encodeDate(selectedTimePeriod.endDate),
}) : undefined,
});

Expand Down
4 changes: 2 additions & 2 deletions app/src/views/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export function Component() {
icon={<FundingCoverageIcon />}
className={styles.keyFigure}
value={getPercentage(
aggregatedAppealResponse?.amount_funded,
aggregatedAppealResponse?.amount_requested,
aggregatedAppealResponse?.amount_funded_dref_included,
aggregatedAppealResponse?.amount_requested_dref_included,
)}
suffix="%"
compactValue
Expand Down

0 comments on commit 0a68faa

Please sign in to comment.