Skip to content

Commit c1b2dd9

Browse files
committed
fix(fundings): Remove / bypass "is_coordinator" aggregation for graphs about "Region"
1 parent eb71f70 commit c1b2dd9

18 files changed

Lines changed: 627 additions & 253 deletions

File tree

client/src/boards/financements-par-aap/charts/classifications/index.tsx

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { Title } from "@dataesr/dsfr-plus";
2-
import { useQuery } from "@tanstack/react-query";
3-
import type HighchartsInstance from "highcharts/es-modules/masters/highcharts.src.js";
4-
import { useState } from "react";
5-
import { useSearchParams } from "react-router-dom";
1+
import { Title } from "@dataesr/dsfr-plus"
2+
import { useQuery } from "@tanstack/react-query"
3+
import type HighchartsInstance from "highcharts/es-modules/masters/highcharts.src.js"
4+
import { useState } from "react"
5+
import { useSearchParams } from "react-router-dom"
66

7-
import DefaultSkeleton from "../../../../components/charts-skeletons/default.tsx";
8-
import { useChartColor } from "../../../../hooks/useChartColor.tsx";
9-
import { getI18nLabel } from "../../../../utils.tsx";
10-
import ChartWrapperFundings from "../../components/chart-wrapper-fundings/index.tsx";
11-
import SegmentedControl from "../../components/segmented-control/index.tsx";
12-
import i18n from "../../i18n.json";
13-
import { formatCompactNumber, funders, getCssColor, getEsQuery, getYearRangeLabel, pattern } from "../../utils.ts";
7+
import DefaultSkeleton from "../../../../components/charts-skeletons/default.tsx"
8+
import { useChartColor } from "../../../../hooks/useChartColor.tsx"
9+
import { getI18nLabel } from "../../../../utils.tsx"
10+
import ChartWrapperFundings from "../../components/chart-wrapper-fundings/index.tsx"
11+
import SegmentedControl from "../../components/segmented-control/index.tsx"
12+
import i18n from "../../i18n.json"
13+
import { formatCompactNumber, funders, getCssColor, getEsQuery, getYearRangeLabel, pattern } from "../../utils.ts"
1414

15-
const { VITE_APP_ES_INDEX_PARTICIPATIONS, VITE_APP_SERVER_URL } = import.meta.env;
15+
const { VITE_APP_ES_INDEX_PARTICIPATIONS, VITE_APP_SERVER_URL } = import.meta.env
1616

1717
export default function Classifications({ name }: { name: string | undefined }) {
1818
const [selectedControl, setSelectedControl] = useState("projects")
@@ -42,13 +42,18 @@ export default function Classifications({ name }: { name: string | undefined })
4242
field: "participation_is_coordinator",
4343
},
4444
aggregations: {
45-
unique_projects: {
45+
by_unique_project: {
4646
cardinality: {
4747
field: "project_id.keyword",
4848
},
4949
},
5050
},
5151
},
52+
by_unique_project: {
53+
cardinality: {
54+
field: "project_id.keyword",
55+
},
56+
},
5257
},
5358
},
5459
},
@@ -90,18 +95,31 @@ export default function Classifications({ name }: { name: string | undefined })
9095
},
9196
},
9297
},
98+
should_ignore_budget: {
99+
terms: {
100+
field: structure ? "participant_ignore_total_budget" : "region_ignore_total_budget",
101+
missing: 0,
102+
},
103+
aggregations: {
104+
sum_budget: {
105+
sum: {
106+
field: "project_budgetFinanced",
107+
},
108+
},
109+
},
110+
},
93111
},
94112
},
95113
},
96114
},
97115
by_classifications_funding: {
98116
terms: {
99117
field: "project_classification.primary_field.keyword",
100-
order: { "sum_budget_funding": "desc" },
118+
order: { "sum_funding": "desc" },
101119
size: 15,
102120
},
103121
aggregations: {
104-
sum_budget_funding: {
122+
sum_funding: {
105123
sum: {
106124
field: "participation_funding",
107125
},
@@ -122,7 +140,7 @@ export default function Classifications({ name }: { name: string | undefined })
122140
missing: 0,
123141
},
124142
aggregations: {
125-
sum_budget_funding: {
143+
sum_funding: {
126144
sum: {
127145
field: "participation_funding",
128146
},
@@ -131,6 +149,19 @@ export default function Classifications({ name }: { name: string | undefined })
131149
},
132150
},
133151
},
152+
should_ignore_funding: {
153+
terms: {
154+
field: structure ? "participant_ignore_funding" : "region_ignore_funding",
155+
missing: 0,
156+
},
157+
aggregations: {
158+
sum_funding: {
159+
sum: {
160+
field: "participation_funding",
161+
},
162+
},
163+
},
164+
},
134165
},
135166
},
136167
},
@@ -181,54 +212,51 @@ export default function Classifications({ name }: { name: string | undefined })
181212
color: getCssColor({ name: funder, prefix: "funder" }),
182213
data: classificationsBudget.map((classification) => classification
183214
?.by_project_type.buckets?.find((project) => project.key === funder)
184-
?.is_coordinator?.buckets?.reduce((acc, curr) => acc + (curr?.should_ignore_budget?.buckets?.find((bucket) => bucket.key == 0)?.sum_budget?.value ?? 0), 0)
185-
?? 0),
215+
?.should_ignore_budget?.buckets?.find((bucket) => bucket.key.toString() === '0')?.sum_budget?.value ?? 0),
186216
name: funder,
187217
});
188218
seriesFunding.push({
189219
color: { pattern: { ...pattern, backgroundColor: getCssColor({ name: funder, prefix: "funder" }) } },
190220
data: classificationsFunding.map((classification) => classification.by_project_type.buckets
191221
?.find((project) => project.key === funder)?.is_coordinator?.buckets
192222
?.find((bucket) => bucket.key === 1)?.should_ignore_funding?.buckets
193-
?.find((bucket) => bucket.key.toString() === '0')?.sum_budget_funding?.value ?? 0),
223+
?.find((bucket) => bucket.key.toString() === '0')?.sum_funding?.value ?? 0),
194224
name: [funder, getI18nLabel(i18n, 'coordinator')].join(' - '),
195225
});
196226
seriesFunding.push({
197227
color: getCssColor({ name: funder, prefix: "funder" }),
198228
data: classificationsFunding.map((classification) => classification.by_project_type.buckets
199229
?.find((project) => project.key === funder)?.is_coordinator?.buckets
200230
?.find((bucket) => bucket.key === 0)?.should_ignore_funding?.buckets
201-
?.find((bucket) => bucket.key.toString() === '0')?.sum_budget_funding?.value ?? 0),
231+
?.find((bucket) => bucket.key.toString() === '0')?.sum_funding?.value ?? 0),
202232
name: [funder, getI18nLabel(i18n, 'not-coordinator')].join(' - '),
203233
});
204234
seriesFundingRegion.push({
205235
color: getCssColor({ name: funder, prefix: "funder" }),
206236
data: classificationsFunding.map((classification) => classification
207237
?.by_project_type.buckets?.find((project) => project.key === funder)
208-
?.is_coordinator?.buckets?.reduce((acc, curr) => acc + (curr?.should_ignore_funding?.buckets?.find((bucket) => bucket.key == 0)?.sum_budget_funding?.value ?? 0), 0)
209-
?? 0),
238+
?.should_ignore_funding?.buckets?.find((bucket) => bucket.key.toString() === '0')?.sum_funding?.value ?? 0),
210239
name: funder,
211240
});
212241
seriesProject.push({
213242
color: { pattern: { ...pattern, backgroundColor: getCssColor({ name: funder, prefix: "funder" }) } },
214243
data: classificationsProject.map((classification) => classification.by_project_type.buckets
215244
?.find((project) => project.key === funder)?.is_coordinator?.buckets
216-
?.find((bucket) => bucket.key === 1)?.unique_projects?.value ?? 0),
245+
?.find((bucket) => bucket.key === 1)?.by_unique_project?.value ?? 0),
217246
name: [funder, getI18nLabel(i18n, 'coordinator')].join(' - '),
218247
});
219248
seriesProject.push({
220249
color: getCssColor({ name: funder, prefix: "funder" }),
221250
data: classificationsProject.map((classification) => classification.by_project_type.buckets
222251
?.find((project) => project.key === funder)?.is_coordinator?.buckets
223-
?.find((bucket) => bucket.key === 0)?.unique_projects?.value ?? 0),
252+
?.find((bucket) => bucket.key === 0)?.by_unique_project?.value ?? 0),
224253
name: [funder, getI18nLabel(i18n, 'not-coordinator')].join(' - '),
225254
});
226255
seriesProjectRegion.push({
227256
color: getCssColor({ name: funder, prefix: "funder" }),
228257
data: classificationsProject.map((classification) => classification
229258
?.by_project_type.buckets?.find((project) => project.key === funder)
230-
?.is_coordinator?.buckets?.reduce((acc, curr) => acc + (curr?.unique_projects?.value ?? 0), 0)
231-
?? 0),
259+
?.by_unique_project?.value ?? 0),
232260
name: funder,
233261
});
234262
});

client/src/boards/financements-par-aap/charts/classifications2/index.tsx

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { Title } from "@dataesr/dsfr-plus";
2-
import { useQuery } from "@tanstack/react-query";
3-
import type HighchartsInstance from "highcharts/es-modules/masters/highcharts.src.js";
4-
import { useState } from "react";
5-
import { useSearchParams } from "react-router-dom";
1+
import { Title } from "@dataesr/dsfr-plus"
2+
import { useQuery } from "@tanstack/react-query"
3+
import type HighchartsInstance from "highcharts/es-modules/masters/highcharts.src.js"
4+
import { useState } from "react"
5+
import { useSearchParams } from "react-router-dom"
66

7-
import DefaultSkeleton from "../../../../components/charts-skeletons/default.tsx";
8-
import { useChartColor } from "../../../../hooks/useChartColor.tsx";
9-
import { getI18nLabel } from "../../../../utils.tsx";
10-
import ChartWrapperFundings from "../../components/chart-wrapper-fundings/index.tsx";
11-
import SegmentedControl from "../../components/segmented-control/index.tsx";
12-
import i18n from "../../i18n.json";
13-
import { formatCompactNumber, funders, getCssColor, getEsQuery, getYearRangeLabel, pattern } from "../../utils.ts";
7+
import DefaultSkeleton from "../../../../components/charts-skeletons/default.tsx"
8+
import { useChartColor } from "../../../../hooks/useChartColor.tsx"
9+
import { getI18nLabel } from "../../../../utils.tsx"
10+
import ChartWrapperFundings from "../../components/chart-wrapper-fundings/index.tsx"
11+
import SegmentedControl from "../../components/segmented-control/index.tsx"
12+
import i18n from "../../i18n.json"
13+
import { formatCompactNumber, funders, getCssColor, getEsQuery, getYearRangeLabel, pattern } from "../../utils.ts"
1414

15-
const { VITE_APP_ES_INDEX_PARTICIPATIONS, VITE_APP_SERVER_URL } = import.meta.env;
15+
const { VITE_APP_ES_INDEX_PARTICIPATIONS, VITE_APP_SERVER_URL } = import.meta.env
1616

1717
export default function Classifications2({ name }: { name: string | undefined }) {
1818
const [selectedControl, setSelectedControl] = useState("projects")
@@ -42,13 +42,18 @@ export default function Classifications2({ name }: { name: string | undefined })
4242
field: "participation_is_coordinator",
4343
},
4444
aggregations: {
45-
unique_projects: {
45+
by_unique_project: {
4646
cardinality: {
4747
field: "project_id.keyword",
4848
},
4949
},
5050
},
5151
},
52+
by_unique_project: {
53+
cardinality: {
54+
field: "project_id.keyword",
55+
},
56+
},
5257
},
5358
},
5459
},
@@ -90,18 +95,31 @@ export default function Classifications2({ name }: { name: string | undefined })
9095
},
9196
},
9297
},
98+
should_ignore_budget: {
99+
terms: {
100+
field: structure ? "participant_ignore_total_budget" : "region_ignore_total_budget",
101+
missing: 0,
102+
},
103+
aggregations: {
104+
sum_budget: {
105+
sum: {
106+
field: "project_budgetFinanced",
107+
},
108+
},
109+
},
110+
},
93111
},
94112
},
95113
},
96114
},
97-
by_classifications_participation: {
115+
by_classifications_funding: {
98116
terms: {
99117
field: "project_classification.primary_field.keyword",
100-
order: { "sum_budget_funding": "desc" },
118+
order: { "sum_funding": "desc" },
101119
size: 15,
102120
},
103121
aggregations: {
104-
sum_budget_funding: {
122+
sum_funding: {
105123
sum: {
106124
field: "participation_funding",
107125
},
@@ -122,7 +140,7 @@ export default function Classifications2({ name }: { name: string | undefined })
122140
missing: 0,
123141
},
124142
aggregations: {
125-
sum_budget_funding: {
143+
sum_funding: {
126144
sum: {
127145
field: "participation_funding",
128146
},
@@ -131,6 +149,19 @@ export default function Classifications2({ name }: { name: string | undefined })
131149
},
132150
},
133151
},
152+
should_ignore_funding: {
153+
terms: {
154+
field: structure ? "participant_ignore_funding" : "region_ignore_funding",
155+
missing: 0,
156+
},
157+
aggregations: {
158+
sum_funding: {
159+
sum: {
160+
field: "participation_funding",
161+
},
162+
},
163+
},
164+
},
134165
},
135166
},
136167
},
@@ -158,7 +189,7 @@ export default function Classifications2({ name }: { name: string | undefined })
158189
const seriesFundingRegion: any = [];
159190
const seriesProjectRegion: any = [];
160191
const classificationsBudget = data?.aggregations?.by_classifications_budget?.buckets ?? [];
161-
const classificationsFunding = data?.aggregations?.by_classifications_participation?.buckets ?? [];
192+
const classificationsFunding = data?.aggregations?.by_classifications_funding?.buckets ?? [];
162193
const classificationsProject = data?.aggregations?.by_classifications_project?.buckets ?? [];
163194
classificationsBudget.forEach((classification) => {
164195
seriesBudget.push({
@@ -181,8 +212,7 @@ export default function Classifications2({ name }: { name: string | undefined })
181212
color: getCssColor({ name: classification.key, prefix: "classification" }),
182213
data: funders.map((funder) => classification
183214
?.by_project_type.buckets?.find((project) => project.key === funder)
184-
?.is_coordinator?.buckets?.reduce((acc, curr) => acc + (curr?.should_ignore_budget?.buckets?.find((bucket) => bucket.key == 0)?.sum_budget?.value ?? 0), 0)
185-
?? 0),
215+
?.should_ignore_budget?.buckets?.find((bucket) => bucket.key.toString() === '0')?.sum_budget?.value ?? 0),
186216
name: classification.key,
187217
});
188218
});
@@ -192,23 +222,22 @@ export default function Classifications2({ name }: { name: string | undefined })
192222
data: funders.map((funder) => classification?.by_project_type?.buckets
193223
?.find((bucket) => bucket.key === funder)?.is_coordinator?.buckets
194224
?.find((bucket) => bucket.key === 1)?.should_ignore_funding?.buckets
195-
?.find((bucket) => bucket.key.toString() === '0')?.sum_budget_funding?.value ?? 0),
225+
?.find((bucket) => bucket.key.toString() === '0')?.sum_funding?.value ?? 0),
196226
name: [classification.key, getI18nLabel(i18n, 'coordinator')].join(' - '),
197227
});
198228
seriesFunding.push({
199229
color: getCssColor({ name: classification.key, prefix: "classification" }),
200230
data: funders.map((funder) => classification?.by_project_type?.buckets
201231
?.find((bucket) => bucket.key === funder)?.is_coordinator?.buckets
202232
?.find((bucket) => bucket.key === 0)?.should_ignore_funding?.buckets
203-
?.find((bucket) => bucket.key.toString() === '0')?.sum_budget_funding?.value ?? 0),
233+
?.find((bucket) => bucket.key.toString() === '0')?.sum_funding?.value ?? 0),
204234
name: [classification.key, getI18nLabel(i18n, 'not-coordinator')].join(' - '),
205235
});
206236
seriesFundingRegion.push({
207237
color: getCssColor({ name: classification.key, prefix: "classification" }),
208238
data: funders.map((funder) => classification
209239
?.by_project_type.buckets?.find((project) => project.key === funder)
210-
?.is_coordinator?.buckets?.reduce((acc, curr) => acc + (curr?.should_ignore_funding?.buckets?.find((bucket) => bucket.key == 0)?.sum_budget_funding?.value ?? 0), 0)
211-
?? 0),
240+
?.should_ignore_funding?.buckets?.find((bucket) => bucket.key.toString() === '0')?.sum_funding?.value ?? 0),
212241
name: classification.key,
213242
});
214243
});
@@ -217,22 +246,21 @@ export default function Classifications2({ name }: { name: string | undefined })
217246
color: { pattern: { ...pattern, backgroundColor: getCssColor({ name: classification.key, prefix: "classification" }) } },
218247
data: funders.map((funder) => classification?.by_project_type?.buckets
219248
?.find((bucket) => bucket.key === funder)?.is_coordinator?.buckets
220-
?.find((bucket) => bucket.key === 1)?.unique_projects?.value ?? 0),
249+
?.find((bucket) => bucket.key === 1)?.by_unique_project?.value ?? 0),
221250
name: [classification.key, getI18nLabel(i18n, 'coordinator')].join(' - '),
222251
});
223252
seriesProject.push({
224253
color: getCssColor({ name: classification.key, prefix: "classification" }),
225254
data: funders.map((funder) => classification?.by_project_type?.buckets
226255
?.find((bucket) => bucket.key === funder)?.is_coordinator?.buckets
227-
?.find((bucket) => bucket.key === 0)?.unique_projects?.value ?? 0),
256+
?.find((bucket) => bucket.key === 0)?.by_unique_project?.value ?? 0),
228257
name: [classification.key, getI18nLabel(i18n, 'not-coordinator')].join(' - '),
229258
});
230259
seriesProjectRegion.push({
231260
color: getCssColor({ name: classification.key, prefix: "classification" }),
232261
data: funders.map((funder) => classification
233262
?.by_project_type.buckets?.find((project) => project.key === funder)
234-
?.is_coordinator?.buckets?.reduce((acc, curr) => acc + (curr?.unique_projects?.value ?? 0), 0)
235-
?? 0),
263+
?.by_unique_project?.value ?? 0),
236264
name: classification.key,
237265
});
238266
});

0 commit comments

Comments
 (0)