Skip to content

Commit

Permalink
connect real data
Browse files Browse the repository at this point in the history
  • Loading branch information
jerem1508 committed Feb 27, 2024
1 parent 5d2258b commit 99d6d6e
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
font-size: 12px;
color: #333;
font-style: italic;
}

figure {
margin: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,22 @@ import { GetHorizon2020Participation } from "./query";
import options from "./options";

import ChartWrapper from "../../../../../chart-wrapper";
import { getColorByPillierName } from "./utils";

export default function Horizon2020Participation() {
const [searchParams] = useSearchParams();
const params = [...searchParams].map(([key, value]) => `${key}=${value}`).join('&');

let params = [...searchParams].map(([key, value]) => `${key}=${value}`).join('&');
params += '&stage=successful';
const { data, isLoading } = useQuery({
queryKey: ["GetHorizon2020Participation", params],
queryFn: () => GetHorizon2020Participation(params)
})

if (isLoading) return <Template />
if (isLoading || !data) return <Template />

const getColorByPillierName = (name) => {
if (name === "Science d'excellence") {
return "#9ef9be";
} else if (name === "Problématiques mondiales et compétitivité industrielle européenne") {
return "#4b5d67";
} else if (name === "Europe plus innovante") {
return "#87556f";
} else {
return "#cecece";
}
};

const pillierLegend = [
{ name: "Science d'excellence", color: getColorByPillierName("Science d'excellence") },
{ name: "Excellence scientifique", color: getColorByPillierName("Excellence scientifique") },
{ name: "Problématiques mondiales et compétitivité industrielle européenne", color: getColorByPillierName("Problématiques mondiales et compétitivité industrielle européenne") },
{ name: "Europe plus innovante", color: getColorByPillierName("Europe plus innovante") },
{ name: "Élargir la participation et renforcer l'espace européen de la recherche", color: getColorByPillierName("Élargir la participation et renforcer l'espace européen de la recherche") },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,44 @@
import { getColorByPillierName } from "./utils";

export default function Options(data) {
if (!data) return null;

const sortedData = data[0].data.sort((a, b) => b.share_signed - a.share_signed);
const categories = sortedData.map((item) => item.programme_name_fr);
const percentages = sortedData.map((item) => item.share_signed);
const pillierName = sortedData.map((item) => item.pilier_name_fr);

const getColorByPillierName = (name) => {
if (name === "Science d'excellence") {
return "#9ef9be";
} else if (name === "Problématiques mondiales et compétitivité industrielle européenne") {
return "#4b5d67";
} else if (name === "Europe plus innovante") {
return "#87556f";
} else {
return "#cecece";
}
};

return {
chart: {
type: "bar",
height: 500,
},
title: { text: "" },
xAxis: {
categories: categories,
title: { text: "" }
categories: data.map((item) => item.programme_name_fr),
title: { text: "" },

},
yAxis: [
{ title: { text: "" } },
],
yAxis: {
title: { text: "" },
endOnTick: false,
},


legend: { enabled: false },
credits: { enabled: false },
plotOptions: {
series: {
pointWidth: 20,
dataLabels: {
enabled: true,
color: "#FFFFFF",
},
states: {
hover: {
color: "#a4edba",
},
},
groupPadding: 0.1,
pointPadding: 0.1
},
},
series: [
{
name: "Part captée en %",
data: percentages.map((value, index) => ({
y: value,
color: getColorByPillierName(pillierName[index]),
data: data.map((item) => ({
y: item.total_funding,
color: getColorByPillierName(item.pilier_name_fr),
})),
dataLabels: {
enabled: false,

},
yAxis: 0,
showInLegend: false,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { VITE_APP_SERVER_URL } = import.meta.env;

export async function GetHorizon2020Participation(params: string) {
let url = `${VITE_APP_SERVER_URL}/european-projects/funding_programme`;
let url = `${VITE_APP_SERVER_URL}/european-projects/analysis-synthese-funding_programme`;
if (params !== '') {
url = `${VITE_APP_SERVER_URL}/european-projects/funding_programme?${params}`;
url = `${VITE_APP_SERVER_URL}/european-projects/analysis-synthese-funding_programme?${params}`;
}

return fetch(url).then((response) => (response.json()))
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function getColorByPillierName(name) {
if (name === "Excellence scientifique") {
return "#CECECE";
} else if (name === "Problématiques mondiales et compétitivité industrielle européenne") {
return "#4B5D67";
} else if (name === "Europe plus innovante") {
return "#FFCA00";
} else {
return "#9EF9BE";
}
}
122 changes: 88 additions & 34 deletions server/src/routes/tableaux/european-projects/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from "express";
import { db } from "../../../services/mongo";

import evol_all_pc_coordination_EVAL from './data/evol_all_pc_coordination_EVAL.json' assert { type: "json" };
import evol_all_pc_coordination_SIGNED from './data/evol_all_pc_coordination_SIGNED.json' assert { type: "json" };
Expand All @@ -15,42 +16,95 @@ import funding_programme from './data/funding_programme.json' assert { type: "js
const router = new express.Router();

router.route('/european-projects')
.get((req, res) => {
const allData = {};

if (req.query.countryCode) {
// filtre de toutes les data sur le pays
allData['evol_all_pc_coordination_EVAL'] = evol_all_pc_coordination_EVAL.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_coordination_SIGNED'] = evol_all_pc_coordination_SIGNED.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_funding_EVAL'] = evol_all_pc_funding_EVAL.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_funding_SIGNED'] = evol_all_pc_funding_SIGNED.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_participant_EVAL'] = evol_all_pc_participant_EVAL.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_participant_SIGNED'] = evol_all_pc_participant_SIGNED.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_project_EVAL'] = evol_all_pc_project_EVAL.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_project_SIGNED'] = evol_all_pc_project_SIGNED.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['funding_participant_share_actions'] = funding_participant_share_actions.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['funding_programme'] = funding_programme.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
} else {
allData['evol_all_pc_coordination_EVAL'] = evol_all_pc_coordination_EVAL.data;
allData['evol_all_pc_coordination_SIGNED'] = evol_all_pc_coordination_SIGNED.data;
allData['evol_all_pc_funding_EVAL'] = evol_all_pc_funding_EVAL.data;
allData['evol_all_pc_funding_SIGNED'] = evol_all_pc_funding_SIGNED.data;
allData['evol_all_pc_participant_EVAL'] = evol_all_pc_participant_EVAL.data;
allData['evol_all_pc_participant_SIGNED'] = evol_all_pc_participant_SIGNED.data;
allData['evol_all_pc_project_EVAL'] = evol_all_pc_project_EVAL.data;
allData['evol_all_pc_project_SIGNED'] = evol_all_pc_project_SIGNED.data;
allData['funding_participant_share_actions'] = funding_participant_share_actions;
allData['funding_programme'] = funding_programme;
}
res.json(allData);
});
.get((req, res) => {
const allData = {};

if (req.query.countryCode) {
// filtre de toutes les data sur le pays
allData['evol_all_pc_coordination_EVAL'] = evol_all_pc_coordination_EVAL.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_coordination_SIGNED'] = evol_all_pc_coordination_SIGNED.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_funding_EVAL'] = evol_all_pc_funding_EVAL.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_funding_SIGNED'] = evol_all_pc_funding_SIGNED.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_participant_EVAL'] = evol_all_pc_participant_EVAL.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_participant_SIGNED'] = evol_all_pc_participant_SIGNED.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_project_EVAL'] = evol_all_pc_project_EVAL.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['evol_all_pc_project_SIGNED'] = evol_all_pc_project_SIGNED.data.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['funding_participant_share_actions'] = funding_participant_share_actions.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
allData['funding_programme'] = funding_programme.filter((el) => el.country_code.toLowerCase() === req.query.countryCode.toLowerCase());
} else {
allData['evol_all_pc_coordination_EVAL'] = evol_all_pc_coordination_EVAL.data;
allData['evol_all_pc_coordination_SIGNED'] = evol_all_pc_coordination_SIGNED.data;
allData['evol_all_pc_funding_EVAL'] = evol_all_pc_funding_EVAL.data;
allData['evol_all_pc_funding_SIGNED'] = evol_all_pc_funding_SIGNED.data;
allData['evol_all_pc_participant_EVAL'] = evol_all_pc_participant_EVAL.data;
allData['evol_all_pc_participant_SIGNED'] = evol_all_pc_participant_SIGNED.data;
allData['evol_all_pc_project_EVAL'] = evol_all_pc_project_EVAL.data;
allData['evol_all_pc_project_SIGNED'] = evol_all_pc_project_SIGNED.data;
allData['funding_participant_share_actions'] = funding_participant_share_actions;
allData['funding_programme'] = funding_programme;
}
res.json(allData);
});

router.route('/european-projects/funding_programme')
.get((req, res) => {
const iso2 = req.query.country_code || 'FR';
res.json(funding_programme.filter((item) =>
item.country_code.toLowerCase() === iso2.toLowerCase())
);
.get((req, res) => {
const iso2 = req.query.country_code || 'FR';
res.json(funding_programme.filter((item) =>
item.country_code.toLowerCase() === iso2.toLowerCase())
);
});

router.route('/european-projects/fr-esr-all-projects-synthese')
.get((req, res) => {

db.collection('EP-fr-esr-all-projects-synthese').distinct("stage").then((data) => {
res.json(data);
});
});

router.route('/european-projects/analysis-synthese-funding_programme')
.get(async (req, res) => {
if (!req.query.country_code) {
res.status(400).send('country_code is required');
return;
}
if (!req.query.stage) {
res.status(400).send('stage is required');
return;
}
if (req.query.country_code) {
req.query.country_code = req.query.country_code.toUpperCase();
}
const data = await db.collection('EP-fr-esr-all-projects-synthese')
.aggregate([
{ $match: req.query },
// { $match: { stage: "successful", country_code: "FRA" } },
{
$group: {
_id: {
programme_name_en: "$programme_name_en",
programme_name_fr: "$programme_name_fr",
pilier_name_en: "$pilier_name_en",
pilier_name_fr: "$pilier_name_fr",
},
total_funding: { $sum: "$fund_eur" },
},
},
{
$project: {
_id: 0,
programme_name_en: "$_id.programme_name_en",
programme_name_fr: "$_id.programme_name_fr",
pilier_name_en: "$_id.pilier_name_en",
pilier_name_fr: "$_id.pilier_name_fr",
total_funding: 1,
}

},
{ $sort: { total_funding: -1 } }
]).toArray();
res.json(data);

});

export default router;

0 comments on commit 99d6d6e

Please sign in to comment.