Updated report system to analyse subsets

This commit is contained in:
Peter Edmond 2025-06-01 20:46:42 +01:00
parent 7d571d240d
commit bf17427cc4
8 changed files with 84 additions and 21 deletions

40
db.php
View File

@ -130,10 +130,50 @@ $stmt = $pdo->prepare("
'text' => $text,
'value' => $value
]);
if ($qid == "QID68"){
updateResponseQ1($pdo, $value, $responseId);
}
if ($qid == "QID69"){
updateResponseQ2($pdo, $value, $responseId);
}
if ($qid == "QID70"){
updateResponseQ3($pdo, $value, $responseId);
}
}
}
}
function updateResponseQ1(PDO $pdo, int $q1Value, string $responseId): bool {
$sql = "UPDATE Responses SET Q1 = :q1 WHERE id = :responseId";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':q1', $q1Value, PDO::PARAM_INT);
$stmt->bindParam(':responseId', $responseId, PDO::PARAM_STR);
return $stmt->execute();
}
function updateResponseQ2(PDO $pdo, int $q2Value, string $responseId): bool {
$sql = "UPDATE Responses SET Q2 = :q2 WHERE id = :responseId";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':q2', $q2Value, PDO::PARAM_INT);
$stmt->bindParam(':responseId', $responseId, PDO::PARAM_STR);
return $stmt->execute();
}
function updateResponseQ3(PDO $pdo, int $q3Value, string $responseId): bool {
$sql = "UPDATE Responses SET Q3 = :q3 WHERE id = :responseId";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':q3', $q3Value, PDO::PARAM_INT);
$stmt->bindParam(':responseId', $responseId, PDO::PARAM_STR);
return $stmt->execute();
}
?>

View File

@ -28,8 +28,8 @@ SOFTWARE.
function drawBar(id,data) {
console.log(id);
console.log(data);
//console.log(id);
//console.log(data);
const svg = d3.select(`${id}`);
const backgroundwidth = +svg.attr("width");
const backgroundradius = 10;
@ -297,7 +297,7 @@ function doBarData(id,qid, survey, Q1=0, Q2=0, Q3=0 ) {
.then(response => response.text())
.then(data => {
// Output result
console.log(data);
//console.log(data);
const parsed = JSON.parse(data);
// 2. Clean the keys and build a usable object
@ -308,9 +308,9 @@ function doBarData(id,qid, survey, Q1=0, Q2=0, Q3=0 ) {
bardata[cleanKey] = entry[rawKey];
});
console.log(bardata);
//console.log(bardata);
const total = Object.values(bardata).reduce((sum, value) => sum + value, 0);
console.log(total);
//console.log(total);
document.getElementById("record_no").textContent = total;
if (total < 9){
return;

View File

@ -43,7 +43,7 @@ if (rag !== "")
{
polycolour = rag;
textcolour = "black";
console.log("rag: "+rag);
//console.log("rag: "+rag);
opacity = 0.6;
}

View File

@ -43,7 +43,7 @@ if (rag !== "")
{
polycolour = rag;
textcolour = "black";
console.log("rag: "+rag);
//console.log("rag: "+rag);
opacity = 0.6;
}

View File

@ -4,6 +4,7 @@ header('Content-Type: application/json');
if (php_sapi_name() === 'cli') {
echo "Running from command line.\n";
$qid="QID2_7";
$survey="SV_cwKjMqAqGxImjMG";
$q1 = 1;
$q2 = 2;
$q3 = 0;
@ -70,18 +71,16 @@ try {
$baseSql = "
SELECT
a.value,
COUNT(*) AS count,
r.Q1,
r.Q2,
r.Q3
COUNT(*) AS count
FROM Answers a
INNER JOIN Responses r ON a.responseId = r.id
INNER JOIN Surveys s ON a.surveyId = s.id
WHERE a.QID = :qid
";
//GROUP BY a.value, r.Q1, r.Q2, r.Q3
$sql = $baseSql . $qualifier . "
GROUP BY a.value, r.Q1, r.Q2, r.Q3
GROUP BY a.value
ORDER BY a.value;
";

View File

@ -27,7 +27,7 @@ function insertQualifiers(){
// Output result
console.log(data);
const parsed = JSON.parse(data);
console.log (parsed["1"]);
document.querySelector('label[for="location"]').textContent = parsed["1"][0];
// .shift(); //

View File

@ -12,7 +12,7 @@ function RAGGED(average){
function getAverage(prefix) {
console.log("Prefix:", prefix);
//console.log("Prefix:", prefix);
const elements = Array.from(document.querySelectorAll(`svg[id^="${prefix}"] tspan.average`));
@ -48,7 +48,6 @@ function getSurveyData(){
let Q3=document.getElementById("gov").value;
let amber = '#ffbf00';
//doBigWhiteTriangle('svg1');
//drawtriangle('#svg1','Roles','#008845',[0.5,0.6,0.5],'red', { x: 0, y: 350 },-0.7);

View File

@ -14,11 +14,30 @@
<style>
body {
font-family: sans-serif;
margin: 0;
margin: 5px;
padding: 0;
background-color: white;
}
#surveyForm {
border: 20px solid white;
margin: 20px;
}
#surveyForm input#surveyId {
width: 315px;
}
#surveyForm input, #surveyForm label {
display: inline-block;
margin: 10px 0;
}
#surveyForm select {
width: 400px;
}
.pyramid {
width: 40%;
height: auto;
@ -80,6 +99,9 @@
font-weight: bold;
text-anchor: middle;
}
</style>
</head>
<body>
@ -90,7 +112,7 @@
<p>You first need to enter the Survey ID, and press submit in order to get the correct groupings available to select from. The master template survey is SV_cwKjMqAqGxImjMG if you want a survey to just try out.</p>
<p>SV_bD838sNKZEmi6Tc is also worth experimenting with</p>
<form id="surveyForm">
<label for="surveyId">Survey iD</label>
<label for="surveyId">Survey Id:</label>
<input type="text" id="surveyId" name="surveyId" />
<br>
@ -138,10 +160,13 @@
<p>To bring the EO Framework to life, we have created a simple health check - the eoQ™ test - to help you assess the strength of your current EO practice and signpost areas for possible improvement. It should take up to 20-30 minutes to complete the questionnaire.</p>
<div id="pyramids">
<svg class="pyramid" style="display: inline-block" xmlns="http://www.w3.org/2000/svg" id="svg_pyramid" width="1000" height="1000"></svg>
<svg class="pyramid" style="display: inline-block" xmlns="http://www.w3.org/2000/svg" id="svg_pyramid_RAG" width="1000" height="1000"></svg>
<svg class="pyramid no-axis no-text big-number" style="display: inline-block" xmlns="http://www.w3.org/2000/svg" id="svg_pyramid_RAG_test" width="1000" height="1000"></svg>
<svg class="pyramid no-axis big-number" style="display: inline-block" xmlns="http://www.w3.org/2000/svg" id="svg_pyramid_RAG_test2" width="1000" height="1000"></svg>
</div>
<hr>