File "traitement0021.php"
Full Path: /home/analogde/www/VirtualKeyboardSample/Chart burndown/traitement0021.php
File size: 8.96 KB
MIME-type: text/html
Charset: utf-8
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interrogation DB</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@latest"></script> <!-- Inclure chartjs-plugin-zoom -->
<style>
#myChart {
width: 100%;
height: 400px; /* Utilisez des unités absolues */
}
</style>
<script>
async function estimation() {
try {
const response = await fetch("read_estimation_001.php");
const data = await response.json();
console.log("Data from read_estimation_001.php:", data);
if (!Array.isArray(data)) {
throw new Error("Data is not an array");
}
const nb_lignes = data.length;
console.log("Number of rows:", nb_lignes);
let x = [];
let y = [];
data.forEach(objet => {
if (objet && typeof objet.index !== 'undefined' && typeof objet.duration !== 'undefined') {
y.push(objet.index);
x.push(objet.duration);
} else {
console.warn("Invalid object in data:", objet);
}
});
console.log("Tableau a (index) :", y);
console.log("Tableau b (duration) :", x);
y.reverse();
x.reverse();
console.log("Tableau a (index) after reverse:", y);
console.log("Tableau b (duration) after reverse:", x);
y.push("0");
x.unshift("0");
console.log("Tableau a (index) after adding 0:", y);
console.log("Tableau b (duration) after adding 0:", x);
x = x.map(Number);
y = y.map(Number);
for (let i = 1; i < x.length; i++) {
x[i] = x[i] + x[i - 1];
}
console.log("Tableau b après addition :", x);
console.log("Tableau a après addition :", y);
const separate_x = x.join(', ');
const separate_y = y.join(', ');
console.log("Separate x:", separate_x);
console.log("Separate y:", separate_y);
return { separate_x, separate_y };
} catch (error) {
console.error("Erreur dans estimation:", error);
showMessageModal("Une erreur est survenue lors du chargement des données.");
}
}
async function loadAndProcessData() {
try {
const response = await fetch("load.php");
const data = await response.json();
console.log("Data from load.php:", data);
if (!Array.isArray(data)) {
throw new Error("Data is not an array");
}
const nb_lignes = data.length;
data.reverse();
data.forEach(item => {
if (Array.isArray(item) && item.length > 1) {
item.splice(1, 1);
}
});
let cumulativeData = [];
let cumulativeSum = 0;
data.forEach(item => {
if (Array.isArray(item) && item.length > 0) {
cumulativeSum += parseInt(item[item.length - 1], 10);
cumulativeData.push([item[0], cumulativeSum]);
}
});
let x1val = cumulativeData.map(item => item[1]);
let y1val = cumulativeData.map(item => item[0]);
x1val.unshift(0);
y1val.push(0);
console.log("x1val:", x1val);
console.log("y1val:", y1val);
return { x1val, y1val };
} catch (error) {
console.error("Erreur dans loadAndProcessData:", error);
showMessageModal("Une erreur est survenue lors du chargement des données.");
}
}
function load_temps_effectif() {
return fetch("load_mysql.php")
.then(response => response.json())
.then(data => {
console.log("Data from load_mysql.php:", data);
return data;
})
.catch(error => {
console.error("Erreur dans load_temps_effectif:", error);
showMessageModal("Une erreur est survenue lors du chargement des données.");
});
}
function countValueOneInCells(cells) {
let count = 0;
for (let i = 0; i < cells.length; i++) {
if (cells[i].value === "1") {
count++;
}
}
return count;
}
async function affiche_burndown() {
const { x1val, y1val } = await estimation();
let data = await load_temps_effectif();
let jsonData = [];
data.forEach((row, rowIndex) => {
const cells = row.cells;
const count = countValueOneInCells(cells);
jsonData.push([rowIndex + 1, count]);
});
let countValues = jsonData.map(row => row[1]);
countValues.reverse();
jsonData.forEach((row, index) => {
row[1] = countValues[index];
});
let y2val = jsonData.map(row => row[0]);
y2val.reverse();
y2val.push(0);
let x2val_tmp = jsonData.map(row => row[1]);
x2val_tmp.unshift(0);
let x2val = x2val_tmp.slice();
for (let i = 2; i < x2val.length; i++) {
x2val[i] = x2val[i] + x2val[i - 1];
}
double(x1val, x2val, y2val);
}
function double(x1, x2, y) {
const ctx = document.getElementById('myChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: 'Estimation temps',
data: x1.map((value, index) => ({ x: value, y: y[index] })),
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1,
fill: false,
showLine: true
}, {
label: 'Temps passé',
data: x2.map((value, index) => ({ x: value, y: y[index] })),
borderColor: 'rgba(153, 102, 255, 1)',
borderWidth: 1,
fill: false,
showLine: true
}]
},
options: {
scales: {
x: {
type: 'linear',
position: 'bottom'
},
y: {
beginAtZero: true
}
},
plugins: {
tooltip: {
callbacks: {
label: function(context) {
let label = context.dataset.label || '';
return label;
},
afterLabel: function(context) {
let xfin = context.raw.x;
let xdeb = context.raw.x;
if (context.dataIndex > 0) {
xdeb = context.dataset.data[context.dataIndex - 1].x;
}
let Xdiff = xfin - xdeb;
return `Différence = ${Xdiff}`;
}
}
}
}
}
});
}
affiche_burndown();
</script>
</head>
<body>
<div class="chart-container">
<canvas id="myChart"></canvas>
</div>
</body>
</html>