mirror of
https://git.roussel.pro/telecom-paris/pact.git
synced 2026-02-09 02:20:17 +01:00
page stats fonctionelle et connectée a la bdd
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
import React from 'react'
|
||||
import { Bar } from 'react-chartjs-2'
|
||||
import Chart from 'chart.js/auto';
|
||||
import Chart from 'chart.js/auto'; //NE SURTOUT PAS SUPPRIMER CET IMPORT
|
||||
|
||||
export default function ComparativeBarChart({ xlabels, data0, label0, data1, label1}) {
|
||||
return (
|
||||
<Bar
|
||||
options={{
|
||||
// plugins: {
|
||||
// title: {
|
||||
// display: true,
|
||||
// text: title
|
||||
// },
|
||||
// },
|
||||
responsive: true,
|
||||
interaction: {
|
||||
intersect: false,
|
||||
|
||||
34
code/interface_admin/components/StatBarChart.jsx
Normal file
34
code/interface_admin/components/StatBarChart.jsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React, { useRef } from 'react'
|
||||
import { Bar } from 'react-chartjs-2'
|
||||
import Chart from 'chart.js/auto'; //NE SURTOUT PAS SUPPRIMER CET IMPORT
|
||||
|
||||
export default function StatBarChart({labels, data}) {
|
||||
return (
|
||||
<Bar
|
||||
options={{
|
||||
redraw: true,
|
||||
responsive: true,
|
||||
interaction: {
|
||||
intersect: false,
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
stacked: true,
|
||||
},
|
||||
y: {
|
||||
stacked: true
|
||||
}
|
||||
}
|
||||
}}
|
||||
data={{
|
||||
labels: labels,
|
||||
datasets: [
|
||||
{
|
||||
data: data,
|
||||
backgroundColor: "#FF3B30",
|
||||
},
|
||||
]
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -20,7 +20,7 @@ export default function useStats(limit, interval) {
|
||||
|
||||
useEffect(() => {
|
||||
fetchData(limit, interval);
|
||||
}, [])
|
||||
}, [limit, interval])
|
||||
|
||||
return {stats, loading, error};
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Card, Container, Form, Row, Table } from 'react-bootstrap'
|
||||
import { Card, Container, Form, Row } from 'react-bootstrap'
|
||||
import AvisList from '../../components/AvisList';
|
||||
import useReviews from '../../hooks/reviews';
|
||||
import styles from '../../styles/AvisListPage.module.css'
|
||||
|
||||
@@ -115,7 +115,7 @@ export default function Home() {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Create Next App</title>
|
||||
<title>Telereview</title>
|
||||
<meta name="description" content="Page d'accueil" />
|
||||
</Head>
|
||||
<Container fluid>
|
||||
@@ -131,4 +131,3 @@ export default function Home() {
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,69 @@
|
||||
import React from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Card, Container, Form, Row } from 'react-bootstrap';
|
||||
import StatBarChart from '../components/StatBarChart';
|
||||
import useStats from '../hooks/stats';
|
||||
|
||||
export default function Stats() {
|
||||
const [statName,setStatName] = useState("moyenne_globale")
|
||||
const [timeInterval, setTimeInterval] = useState("jour")
|
||||
const [chartReady, setChartReady] = useState(false);
|
||||
const [xlabels, setXlabels] = useState([]);
|
||||
const [plotData, setPlotData] = useState([]);
|
||||
|
||||
const {loading, error, stats} = useStats(10,timeInterval);
|
||||
|
||||
useEffect(() => {
|
||||
if(!loading && !error) {
|
||||
let newXlabels = [];
|
||||
let newPlotData = [];
|
||||
for(let i = 0; i < stats.length; i++) {
|
||||
newXlabels.push(stats[i].date);
|
||||
newPlotData.push(stats[i][statName]);
|
||||
}
|
||||
setXlabels(newXlabels);
|
||||
setPlotData(newPlotData);
|
||||
setChartReady(true);
|
||||
console.log(timeInterval, stats, plotData, xlabels);
|
||||
}else {
|
||||
setChartReady(false);
|
||||
}
|
||||
}, [stats, statName, timeInterval, loading, error])
|
||||
|
||||
|
||||
return (
|
||||
<div>stats</div>
|
||||
<Container fluid>
|
||||
<Card>
|
||||
<Card.Header>Tous les avis</Card.Header>
|
||||
<Card.Body>
|
||||
<Row>
|
||||
<Form>
|
||||
<Form.Group>
|
||||
<Form.Label>Statistique</Form.Label>
|
||||
<Form.Select value={statName} onChange={(e) => setStatName(e.target.value)}>
|
||||
<option value="moyenne_globale">Moyenne globale</option>
|
||||
<option value="nb_avis">Nombre d'avis</option>
|
||||
<option value="moyenne_site">Moyenne du formulaire</option>
|
||||
<option value = "moyenne_borne">Moyenne sur la borne</option>
|
||||
<option value="dist_sexes">Distribution sexes</option>
|
||||
</Form.Select>
|
||||
</Form.Group>
|
||||
<Form.Group>
|
||||
<Form.Label>Periode</Form.Label>
|
||||
<Form.Select value={timeInterval} onChange={(e) => setTimeInterval(e.target.value)}>
|
||||
<option value="jour">Jour</option>
|
||||
<option value="semaine">Semaine</option>
|
||||
<option value="mois">Mois</option>
|
||||
<option value = "annee">Année</option>
|
||||
</Form.Select>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</Row>
|
||||
<Row>
|
||||
{error && <p>Error</p>}
|
||||
{chartReady && <StatBarChart data={plotData} labels={xlabels} />}
|
||||
</Row>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
3
docs/charte_graphique.md
Normal file
3
docs/charte_graphique.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Codes hex couleurs
|
||||
#6B8000
|
||||
#A6CC00
|
||||
Reference in New Issue
Block a user