add stats, and add history import details
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php include('../../Connections/repnew.php'); ?>
|
||||
<?php include('../../Connections/repnew.php');
|
||||
include('../include/class/rating_definitions.php'); ?>
|
||||
<?php
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
// error_reporting(1);
|
||||
@@ -238,6 +239,63 @@ while ($row = $topFailingAnalysisResult->fetch_assoc()) {
|
||||
$topFailingAnalysis[] = ['name' => $analysisName, 'failCount' => $row['failCount']];
|
||||
}
|
||||
|
||||
// Query per il grafico a barre orizzontali con raggruppamento basato su products_season
|
||||
// Gestione del raggruppamento dinamico dal POST
|
||||
$groupingField = isset($_POST['groupingField']) ? $_POST['groupingField'] : 'products_season';
|
||||
$passConditions = implode("', '", array_map('addslashes', RATING_PASS));
|
||||
$failConditions = implode("', '", array_map('addslashes', RATING_FAIL));
|
||||
$otherConditions = implode("', '", array_map('addslashes', RATING_OTHER));
|
||||
|
||||
// Query per il grafico a barre orizzontali con sezioni multicolore
|
||||
$horizontalBarQuery = "
|
||||
SELECT
|
||||
p.$groupingField AS groupingValue,
|
||||
SUM(CASE WHEN UPPER(r.reportsRating) IN ('$passConditions') THEN 1 ELSE 0 END) AS passCount,
|
||||
SUM(CASE WHEN UPPER(r.reportsRating) IN ('$failConditions') THEN 1 ELSE 0 END) AS failCount,
|
||||
SUM(CASE WHEN UPPER(r.reportsRating) NOT IN ('$passConditions', '$failConditions') THEN 1 ELSE 0 END) AS otherCount
|
||||
FROM reports r
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters
|
||||
GROUP BY p.$groupingField
|
||||
";
|
||||
|
||||
|
||||
$horizontalBarResult = $conn->query($horizontalBarQuery);
|
||||
$horizontalBarData = [];
|
||||
while ($row = $horizontalBarResult->fetch_assoc()) {
|
||||
$horizontalBarData[] = [
|
||||
'groupingValue' => $row['groupingValue'],
|
||||
'passCount' => $row['passCount'],
|
||||
'failCount' => $row['failCount'],
|
||||
'otherCount' => $row['otherCount']
|
||||
];
|
||||
}
|
||||
|
||||
// Query per ottenere il conteggio di Pass, Fail e altri dalle analisi
|
||||
$horizontalBarAnalysisQuery = "
|
||||
SELECT
|
||||
p.$groupingField AS groupingValue,
|
||||
SUM(CASE WHEN UPPER(ap.test_Rating) IN ('PASS', 'P', 'COMPLIES') THEN 1 ELSE 0 END) AS passCount,
|
||||
SUM(CASE WHEN UPPER(ap.test_Rating) IN ('FAIL', 'F', 'DOESN\'T COMPLY') THEN 1 ELSE 0 END) AS failCount,
|
||||
SUM(CASE WHEN UPPER(ap.test_Rating) NOT IN ('PASS', 'P', 'COMPLIES', 'FAIL', 'F', 'DOESN\'T COMPLY') THEN 1 ELSE 0 END) AS otherCount
|
||||
FROM analysis_project ap
|
||||
LEFT JOIN reports r ON ap.idreports = r.idreports
|
||||
LEFT JOIN products p ON r.idproducts = p.idproducts
|
||||
$filters
|
||||
GROUP BY p.$groupingField
|
||||
";
|
||||
|
||||
$horizontalBarAnalysisResult = $conn->query($horizontalBarAnalysisQuery);
|
||||
$horizontalBarAnalysisData = [];
|
||||
while ($row = $horizontalBarAnalysisResult->fetch_assoc()) {
|
||||
$horizontalBarAnalysisData[] = [
|
||||
'groupingValue' => $row['groupingValue'],
|
||||
'passCount' => (int)$row['passCount'],
|
||||
'failCount' => (int)$row['failCount'],
|
||||
'otherCount' => (int)$row['otherCount']
|
||||
];
|
||||
}
|
||||
|
||||
// Statistic for worst suppliers based on % of failed reports
|
||||
$worstSuppliersQuery = "
|
||||
SELECT p.namesupplier AS supplier, COUNT(r.idreports) AS totalReports,
|
||||
@@ -451,7 +509,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
'tesType' => $tesType,
|
||||
'numberLabs' => $numberLabs,
|
||||
'failedAnalytes' => $failedAnalytes,
|
||||
'analysisDistribution' => $analysisDistribution // Distribuzione delle analisi per il grafico a torta
|
||||
'analysisDistribution' => $analysisDistribution, // Distribuzione delle analisi per il grafico a torta
|
||||
'horizontalBarData' => $horizontalBarData, // Dati per il grafico a barre orizzontali
|
||||
'horizontalBarAnalysisData' => $horizontalBarAnalysisData // Nuovi dati per le analisi
|
||||
]);
|
||||
exit; // Ferma l'esecuzione del resto dello script dopo aver risposto all'AJAX
|
||||
}
|
||||
|
||||
@@ -607,6 +607,37 @@ include('parsedatachart.php');
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row chart-box" id="chart7" data-id="7">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" id="dynamicChartTitle">Rating Distribution by Group</h5>
|
||||
|
||||
<!-- Inserisci il dropdown direttamente all'interno della card -->
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<label for="groupingField">Group by:</label>
|
||||
<select id="groupingField" class="form-control">
|
||||
<option value="products_season">Product Season</option>
|
||||
<option value="agerange">Age Range</option>
|
||||
<option value="namesupplier">Name Supplier</option>
|
||||
<!-- Aggiungi altri campi se necessario -->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Area per il grafico -->
|
||||
<br>
|
||||
<h6 class="mt-4">Report Rating Distribution</h6> <!-- Titolo per il primo grafico -->
|
||||
<div id="horizontalBarChart"></div>
|
||||
|
||||
<h6 class="mt-4">Analysis Rating Distribution</h6> <!-- Titolo per il secondo grafico -->
|
||||
<div id="horizontalBarAnalysisChart"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
@@ -707,6 +738,13 @@ include('parsedatachart.php');
|
||||
var reportsLabName = $('#reportsLabName').val();
|
||||
var reportsTestType = $('#reportsTestType').val();
|
||||
var reportsNumberLab = $('#reportsNumberLab').val();
|
||||
var groupingField = $('#groupingField').val();
|
||||
|
||||
// Aggiorna il titolo dinamicamente in base alla selezione del dropdown
|
||||
var groupingText = $('#groupingField option:selected').text(); // Ottieni il testo dell'opzione selezionata
|
||||
$('#dynamicChartTitle').text(`Rating Distribution by Group: ${groupingText}`); // Aggiorna il titolo
|
||||
|
||||
|
||||
|
||||
$.ajax({
|
||||
url: 'parsedatachart.php',
|
||||
@@ -720,7 +758,8 @@ include('parsedatachart.php');
|
||||
ageRange: ageRange,
|
||||
reportsLabName: reportsLabName,
|
||||
reportsTestType: reportsTestType,
|
||||
reportsNumberLab: reportsNumberLab
|
||||
reportsNumberLab: reportsNumberLab,
|
||||
groupingField: groupingField
|
||||
},
|
||||
success: function(response) {
|
||||
if (!response) {
|
||||
@@ -867,6 +906,102 @@ include('parsedatachart.php');
|
||||
var chart = new ApexCharts(document.querySelector("#worsttenanalysis"), options);
|
||||
chart.render();
|
||||
|
||||
// Genera il nuovo grafico a barre orizzontali
|
||||
$('#horizontalBarChart').html('');
|
||||
var horizontalBarData = data.horizontalBarData;
|
||||
var categories = horizontalBarData.map(item => item.groupingValue);
|
||||
var passData = horizontalBarData.map(item => item.passCount);
|
||||
var failData = horizontalBarData.map(item => item.failCount);
|
||||
var otherData = horizontalBarData.map(item => item.otherCount);
|
||||
|
||||
var options = {
|
||||
series: [{
|
||||
name: 'Pass',
|
||||
data: passData
|
||||
},
|
||||
{
|
||||
name: 'Fail',
|
||||
data: failData
|
||||
},
|
||||
{
|
||||
name: 'Others',
|
||||
data: otherData
|
||||
}
|
||||
],
|
||||
chart: {
|
||||
type: 'bar',
|
||||
height: 400,
|
||||
stacked: true,
|
||||
horizontal: true
|
||||
},
|
||||
xaxis: {
|
||||
categories: categories
|
||||
},
|
||||
colors: ['#28A745', '#FF4D4D', '#FFA500'],
|
||||
plotOptions: {
|
||||
bar: {
|
||||
horizontal: true,
|
||||
dataLabels: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
position: 'top'
|
||||
},
|
||||
};
|
||||
|
||||
var chart = new ApexCharts(document.querySelector("#horizontalBarChart"), options);
|
||||
chart.render();
|
||||
|
||||
// Dati per il grafico delle analisi
|
||||
var horizontalBarAnalysisData = data.horizontalBarAnalysisData;
|
||||
var categoriesAnalysis = horizontalBarAnalysisData.map(item => item.groupingValue);
|
||||
var passDataAnalysis = horizontalBarAnalysisData.map(item => item.passCount);
|
||||
var failDataAnalysis = horizontalBarAnalysisData.map(item => item.failCount);
|
||||
var otherDataAnalysis = horizontalBarAnalysisData.map(item => item.otherCount);
|
||||
|
||||
// Crea o aggiorna il grafico delle analisi
|
||||
$('#horizontalBarAnalysisChart').html('');
|
||||
var optionsAnalysis = {
|
||||
series: [{
|
||||
name: 'Pass',
|
||||
data: passDataAnalysis
|
||||
},
|
||||
{
|
||||
name: 'Fail',
|
||||
data: failDataAnalysis
|
||||
},
|
||||
{
|
||||
name: 'Others',
|
||||
data: otherDataAnalysis
|
||||
}
|
||||
],
|
||||
chart: {
|
||||
type: 'bar',
|
||||
height: 400,
|
||||
stacked: true,
|
||||
horizontal: true
|
||||
},
|
||||
xaxis: {
|
||||
categories: categoriesAnalysis
|
||||
},
|
||||
colors: ['#28A745', '#FF4D4D', '#FFA500'],
|
||||
plotOptions: {
|
||||
bar: {
|
||||
horizontal: true,
|
||||
dataLabels: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
position: 'top'
|
||||
},
|
||||
};
|
||||
var chartAnalysis = new ApexCharts(document.querySelector("#horizontalBarAnalysisChart"), optionsAnalysis);
|
||||
chartAnalysis.render();
|
||||
|
||||
// remove bar chart and create a new one
|
||||
$('#worstSuppliersChart').html('');
|
||||
|
||||
@@ -1144,8 +1279,8 @@ include('parsedatachart.php');
|
||||
|
||||
|
||||
|
||||
// Eventi per applicare i filtri
|
||||
$('#startDate, #endDate, #supplierFilter, #productsRefnumber, #productsSeason, #ageRange, #reportsLabName, #reportsTestType, #reportsNumberLab').on('change', function() {
|
||||
// Eventi per applicare i filtri e il cambio di raggruppamento
|
||||
$('#startDate, #endDate, #supplierFilter, #productsRefnumber, #productsSeason, #ageRange, #reportsLabName, #reportsTestType, #reportsNumberLab, #groupingField').on('change', function() {
|
||||
updateData();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user