-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Highcharts from "highcharts"; | ||
import HighchartsReact from "highcharts-react-official"; | ||
import useGetContributionData from "../../api/contribution-api/useGetObjectContributeData"; | ||
import { Contribution } from "../../types"; | ||
import { contributionUrl } from "../../config/api"; | ||
|
||
const ContributionsGraphByName = () => { | ||
const { data, isLoading, isError } = useGetContributionData( | ||
contributionUrl, | ||
0 | ||
); | ||
const contributions: Contribution[] = (data as { data: Contribution[] }) | ||
?.data; | ||
if (isLoading) { | ||
return <div>Chargement...</div>; | ||
} | ||
|
||
if (isError) { | ||
return <div>Une erreur s'est produite</div>; | ||
} | ||
|
||
if (!Array.isArray(contributions)) { | ||
return <div>Les données ne sont pas disponibles</div>; | ||
} | ||
|
||
const contributionsByName = contributions.reduce((acc, contribution) => { | ||
const name = contribution.name; | ||
|
||
if (!acc[name]) { | ||
acc[name] = 0; | ||
} | ||
|
||
acc[name]++; | ||
|
||
return acc; | ||
}, {}); | ||
|
||
let names: string[] = Object.keys(contributionsByName); | ||
let contributionCounts: number[] = Object.values(contributionsByName); | ||
|
||
let pairs: [string, number][] = names.map((name, index) => [ | ||
name, | ||
contributionCounts[index], | ||
]); | ||
|
||
pairs.sort((a, b) => b[1] - a[1]); | ||
pairs = pairs.slice(0, 15); | ||
|
||
names = pairs.map((pair) => pair[0]); | ||
contributionCounts = pairs.map((pair) => pair[1]); | ||
|
||
const options = { | ||
chart: { | ||
type: "bar", | ||
}, | ||
title: { | ||
text: "Top 15 des contributeurs via le formulaire de contribution par objet", | ||
}, | ||
xAxis: { | ||
categories: names, | ||
title: { | ||
text: "Noms", | ||
}, | ||
}, | ||
yAxis: { | ||
title: { | ||
text: "Nombre de contributions", | ||
}, | ||
}, | ||
series: [ | ||
{ | ||
name: "Contributions", | ||
data: contributionCounts, | ||
}, | ||
], | ||
}; | ||
|
||
return <HighchartsReact highcharts={Highcharts} options={options} />; | ||
}; | ||
|
||
export default ContributionsGraphByName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Highcharts from "highcharts"; | ||
import HighchartsReact from "highcharts-react-official"; | ||
import useGetContributionData from "../../api/contribution-api/useGetObjectContributeData"; | ||
import { contributionUrl } from "../../config/api"; | ||
|
||
const ContributionsGraphByYear = () => { | ||
const { data, isLoading, isError } = useGetContributionData( | ||
contributionUrl, | ||
0 | ||
); | ||
const contributions = (data as { data: [] })?.data; | ||
if (isLoading) { | ||
return <div>Chargement...</div>; | ||
} | ||
|
||
if (isError) { | ||
return <div>Une erreur s'est produite</div>; | ||
} | ||
|
||
if (!Array.isArray(contributions)) { | ||
return <div>Les données ne sont pas disponibles</div>; | ||
} | ||
|
||
const contributionsByMonth = ( | ||
contributions as { created_at: string }[] | ||
).reduce((acc, contribution) => { | ||
const date = new Date(contribution.created_at); | ||
const year = date.getFullYear(); | ||
const month = date.getMonth() + 1; | ||
|
||
if (!acc[year]) { | ||
acc[year] = Array(12).fill(0); | ||
} | ||
|
||
acc[year][month - 1]++; | ||
|
||
return acc; | ||
}, {}); | ||
|
||
const options = { | ||
chart: { | ||
type: "column", | ||
}, | ||
title: { | ||
text: "Nombre de contributions par mois via formulaire de contribution par objet", | ||
}, | ||
xAxis: { | ||
categories: [ | ||
"Jan", | ||
"Fev", | ||
"Mar", | ||
"Avr", | ||
"Mai", | ||
"Jun", | ||
"Jul", | ||
"Aou", | ||
"Sep", | ||
"Oct", | ||
"Nov", | ||
"Dec", | ||
], | ||
}, | ||
series: Object.entries(contributionsByMonth).map( | ||
([year, contributions]) => ({ | ||
name: year, | ||
data: contributions, | ||
}) | ||
), | ||
}; | ||
|
||
return <HighchartsReact highcharts={Highcharts} options={options} />; | ||
}; | ||
|
||
export default ContributionsGraphByYear; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
const API_KEY = import.meta.env.VITE_SCANR_API_AUTHORIZATION; | ||
export const headers = API_KEY ? { Authorization: `Basic ${API_KEY}` } : {}; | ||
export const postHeaders = { ...headers, "Content-Type": "application/json" }; | ||
|
||
export const contributionUrl = | ||
"https://scanr-api.dataesr.ovh/contribute?max_results=2000"; | ||
export const contactUrl = | ||
"https://scanr-api.dataesr.ovh/contact?max_results=2000"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters