Skip to content

Commit

Permalink
add chart "Taux de succès sur le nombre de coordinations de projets p…
Browse files Browse the repository at this point in the history
…ar pilier"
  • Loading branch information
jerem1508 committed Oct 9, 2024
1 parent 8645b7a commit d2e9ccc
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 9 deletions.
9 changes: 8 additions & 1 deletion client/src/pages/european-projects/charts-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@
"integrationURL": "/european-projects/components/pages/analysis/overview/charts/projects-types-2"
},
{
"id": "successRateForAmountsByPillar",
"id": "pillarsSubsidiesRequestedByRates",
"title": "",
"subtitle": "Taux de succès sur le montants par pilier",
"description": "Attention EIT",
"integrationURL": "/european-projects/components/pages/analysis/overview/charts/projects-types-2"
},
{
"id": "pillarsProjectCoordinationRequestedByRates",
"title": "",
"subtitle": "Taux de succès sur le nombre de coordinations de projets par pilier",
"description": "Attention EIT",
"integrationURL": "/european-projects/components/pages/analysis/overview/charts/projects-types-2"
},
{
"id": "pillarsSubsidiesRequestedByProjects",
"title": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,56 @@
import { useQuery } from "@tanstack/react-query";
import { useSearchParams } from "react-router-dom";
import { Col, Container, Row } from "@dataesr/dsfr-plus";

import { GetData } from "./query";
import options from "./options";
import optionsSubsidiesValues from "./options-subsidies-values";
import optionsCoordinationNumber from "./options-coordination_number-values";

import ChartWrapper from "../../../../../chart-wrapper";
import { getDefaultParams } from "./utils";
import { Col, Container, Row } from "@dataesr/dsfr-plus";
import DefaultSkeleton from "../../../../../charts-skeletons/default";

export default function SuccessRateForAmountsByPillar() {
export default function SuccessRateAndEvolutionByPillar({ indicateurId }) {
const [searchParams] = useSearchParams();
const params = getDefaultParams(searchParams);

const { data, isLoading } = useQuery({
queryKey: ["successRateForAmountsByPillar", params],
// queryKey: ["successRateForAmountsByPillar", params],
queryKey: [indicateurId, params],
queryFn: () => GetData(params),
});

if (isLoading || !data) return <DefaultSkeleton />;

let options;
// , optionsRates;
switch (indicateurId) {
case "pillarsSubsidiesRequestedByRates":
options = optionsSubsidiesValues(data);
// optionsEvolution = optionsSubsidiesRates(data);
break;

case "pillarsProjectCoordinationRequestedByRates":
options = optionsCoordinationNumber(data);
// optionsRates = OptionsCoordinationNumberRates(data);
break;

// case "pillarsApplicantsAndParticipantsRequestedByProjectsLines":
// options = optionsSubsidiesValues(data);
// // optionsEvolution = optionsSubsidiesRates(data);
// break;

default:
break;
}

return (
<Container fluid>
<Row>
<Col md={6}>
<ChartWrapper
id="successRateForAmountsByPillar"
options={options(data)}
id={indicateurId}
options={options}
legend={
<ul className="legend">
<li
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
export default function Options(data) {
console.log("data", data);

if (!data) return null;

// sort selectedCountry by action_id
const selectedCountry = data.selectedCountry
.filter((el) => el.ratio && el.ratio !== 0)
.sort((a, b) => a.id - b.id);

// sort otherCountries same as selectedCountry
data.otherCountries.sort((a, b) => {
return (
data.selectedCountry.findIndex((item) => item.id === a.id) -
data.selectedCountry.findIndex((item) => item.id === b.id)
);
});

const otherCountriesSorted = selectedCountry.map((item) => {
return data.otherCountries.find((otherItem) => otherItem.id === item.id);
});

return {
chart: {
type: "column",
height: 500,
backgroundColor: "transparent",
},
title: { text: "" },
legend: { enabled: false },
credits: { enabled: false },

xAxis: {
categories: selectedCountry.map((item) => item.id),
crosshair: true,
accessibility: {
description: "Actions",
},
},
yAxis: {
min: 0,
title: {
text: "(%)",
},
},
tooltip: {
valueSuffix: " (%)",
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0,
},
},
series: [
{
name: "Pays",
data: selectedCountry.map(
(item) =>
(item.total_coordination_number_successful * 100) /
item.total_coordination_number_evaluated
),
color: "#6DD897",
},
{
name: "UE & Etats associés",
data: otherCountriesSorted.map(
(item) =>
(item.total_coordination_number_successful * 100) /
item.total_coordination_number_evaluated
),
color: "#09622A",
},
],
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default function Options(data) {
console.log("data", data);

if (!data) return null;

// sort selectedCountry by action_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState } from "react";

import PillarsRequestedByProjects from "./charts/pillars-requested-by-projects";
import PillarsSubsidiesRequestedLines from "./charts/pillars-subsidies-requested-lines";
import SuccessRateForAmountsByPillar from "./charts/success-rate-for-amounts-by-pillar";
import SuccessRateAndEvolutionByPillar from "./charts/success-rate-and-evolution-by-pillar";

import TypeOfFinancingSubsidiesRequestedByProjects from "./charts/type-of-financing-subsidies-requested-by-projects";
import TypeOfFinancingSubsidiesRequestedLines from "./charts/type-of-financing-subsidies-requested-lines";
Expand Down Expand Up @@ -49,7 +49,9 @@ export default function ProjectsTypes() {
indicateurId={`pillars${selectedChart}RequestedByProjectsLines`}
/>
<div className="fr-my-5w" />
<SuccessRateForAmountsByPillar />
<SuccessRateAndEvolutionByPillar
indicateurId={`pillars${selectedChart}RequestedByRates`}
/>
<div className="fr-my-5w" />
<Title as="h2" look="h4">
Par type de projets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ router
pilier_name_en: "$pilier_name_en",
},
total_fund_eur: { $sum: "$fund_eur" },
total_coordination_number: { $sum: "$coordination_number" },
total_number_involved: { $sum: "$number_involved" },
},
},
{
Expand All @@ -333,6 +335,8 @@ router
total_fund_eur: 1,
pilier_name_fr: "$_id.pilier_name_fr",
pilier_name_en: "$_id.pilier_name_en",
total_coordination_number: 1,
total_number_involved: 1,
},
},
{
Expand All @@ -355,6 +359,42 @@ router
$cond: [{ $eq: ["$stage", "evaluated"] }, "$total_fund_eur", 0],
},
},
total_coordination_number_successful: {
$sum: {
$cond: [
{ $eq: ["$stage", "successful"] },
"$total_coordination_number",
0,
],
},
},
total_coordination_number_evaluated: {
$sum: {
$cond: [
{ $eq: ["$stage", "evaluated"] },
"$total_coordination_number",
0,
],
},
},
total_number_involved_successful: {
$sum: {
$cond: [
{ $eq: ["$stage", "successful"] },
"$total_number_involved",
0,
],
},
},
total_number_involved_evaluated: {
$sum: {
$cond: [
{ $eq: ["$stage", "evaluated"] },
"$total_number_involved",
0,
],
},
},
},
},
{
Expand All @@ -364,6 +404,10 @@ router
name: "$_id.name",
total_successful: 1,
total_evaluated: 1,
total_coordination_number_successful: 1,
total_coordination_number_evaluated: 1,
total_number_involved_successful: 1,
total_number_involved_evaluated: 1,
},
},
{ $sort: { id: 1 } },
Expand All @@ -382,6 +426,8 @@ router
pilier_name_en: "$pilier_name_en",
},
total_fund_eur: { $sum: "$fund_eur" },
total_coordination_number: { $sum: "$coordination_number" },
total_number_involved: { $sum: "$number_involved" },
},
},
{
Expand All @@ -391,6 +437,8 @@ router
total_fund_eur: 1,
pilier_name_fr: "$_id.pilier_name_fr",
pilier_name_en: "$_id.pilier_name_en",
total_coordination_number: 1,
total_number_involved: 1,
},
},
{
Expand All @@ -413,6 +461,42 @@ router
$cond: [{ $eq: ["$stage", "evaluated"] }, "$total_fund_eur", 0],
},
},
total_coordination_number_successful: {
$sum: {
$cond: [
{ $eq: ["$stage", "successful"] },
"$total_coordination_number",
0,
],
},
},
total_coordination_number_evaluated: {
$sum: {
$cond: [
{ $eq: ["$stage", "evaluated"] },
"$total_coordination_number",
0,
],
},
},
total_number_involved_successful: {
$sum: {
$cond: [
{ $eq: ["$stage", "successful"] },
"$total_number_involved",
0,
],
},
},
total_number_involved_evaluated: {
$sum: {
$cond: [
{ $eq: ["$stage", "evaluated"] },
"$total_number_involved",
0,
],
},
},
},
},
{
Expand All @@ -422,6 +506,10 @@ router
name: "$_id.name",
total_successful: 1,
total_evaluated: 1,
total_coordination_number_successful: 1,
total_coordination_number_evaluated: 1,
total_number_involved_successful: 1,
total_number_involved_evaluated: 1,
},
},
{ $sort: { id: 1 } },
Expand Down

0 comments on commit d2e9ccc

Please sign in to comment.