diff --git a/drawbar.js b/drawbar.js index db6ee2d..a38610b 100644 --- a/drawbar.js +++ b/drawbar.js @@ -1,7 +1,8 @@ -function drawBar(id) { +function drawBar(id,data) { +//console.log(id); const svg = d3.select(`${id}`); const backgroundwidth = +svg.attr("width"); const backgroundradius = 10; @@ -23,8 +24,9 @@ svg.append("rect") // .attr("stroke-width", 2); - -const data = { +//const data = { +/* +data = { "-3": 0, "-2": 1, "-1": 3, @@ -33,6 +35,9 @@ const data = { "2": 0, "3": 10 }; +*/ +//console.log(data); + const dataArray = Object.entries(data).map(([key, count]) => ({ key: +key, @@ -72,10 +77,6 @@ svg.append("g") .selectAll("text") .style("visibility", "hidden"); // This hides the labels - - - - // Y Axis //svg.append("g") // .attr("transform", `translate(${margin.left},0)`) @@ -110,15 +111,14 @@ svg.selectAll(".label") const format = d3.format(".2f"); const totalCount = d3.sum(dataArray, d => d.count); const weightedSum = d3.sum(dataArray, d => d.key * d.count); -const average = totalCount > 0 ? format(weightedSum / totalCount) : 0; +average = totalCount > 0 ? weightedSum / totalCount : 0; const xLinear = d3.scaleLinear() .domain([-3, 3]) .range([margin.left + x.bandwidth() / 2, width - margin.right - x.bandwidth() / 2]); - -// const avgX = xLinear(average); -const avgX = xLinear(2.7); // Temporary for testing +const avgX = xLinear(average); +//const avgX = xLinear(-0.50); // Temporary for testing svg.append("line") .attr("x1", avgX) @@ -127,7 +127,7 @@ svg.append("line") .attr("y2", y(d3.max(dataArray, d => d.count)) - 20) .attr("stroke", "#e40074") // From brand guidelines .attr("stroke-width", 4) - .attr("stroke-dasharray", "6,2"); + .attr("stroke-dasharray", "10,4"); /* svg.append("text") @@ -140,6 +140,7 @@ svg.append("text") */ // Title beneath the graph +/* svg.append("text") .attr("x", width / 2) .attr("y", height - 10) // Just below the x-axis @@ -147,13 +148,14 @@ svg.append("text") .attr("font-size", "14px") .attr("fill", "black") .text("Demo bar graph"); +*/ -// Add infor to right of bar chart +// Add info to right of bar chart // Oblong settings -const boxx = 620; +const boxx = 610; const boxy = 60; -const boxwidth = 150; +const boxwidth = 170; const boxheight = 80; const cornerRadius = 10; @@ -185,9 +187,40 @@ svg.append("text") .attr("text-anchor", "middle") .attr("dominant-baseline", "middle") .attr("font-size", "20px") - .attr("font-weight", "900") // 400 is normal, 700 is bold, 900 is extra-bold + .attr("font-weight", "400") // 400 is normal, 700 is bold, 900 is extra-bold .attr("font-family", "sans-serif") - .text("Average : 1.69"); + .text("Average: ") + .append(function() { + return document.createElementNS("http://www.w3.org/2000/svg", "tspan"); + }) + .text(average.toFixed(1)) + .attr("class", "average") + .attr("fill", "#e40074") + .attr("font-weight", "900"); + + +// .text("Average : "+average.toFixed(2)); + +// Get the score gap: + +let maxKey = null; +let minKey = null; + +for (const [key, value] of Object.entries(data)) { + if (value > 0) { + const numKey = Number(key); + //console.log(numkey); + if (maxKey === null || numKey > maxKey) { + maxKey = numKey; + } + if (minKey === null || numKey < minKey) { + minKey = numKey; + } + } +} + + +scoregap = maxKey - minKey+1; // Add text to the bottom half svg.append("text") @@ -196,8 +229,58 @@ svg.append("text") .attr("text-anchor", "middle") .attr("dominant-baseline", "middle") .attr("font-size", "20px") - .attr("font-weight", "900") // 400 is normal, 700 is bold, 900 is extra-bold + .attr("font-weight", "400") // 400 is normal, 700 is bold, 900 is extra-bold .attr("font-family", "sans-serif") - .text("Score Gap : 6"); + .text("Score gap: ") + .append(function() { + return document.createElementNS("http://www.w3.org/2000/svg", "tspan"); + }) + .text(scoregap) + .attr("font-weight", "900"); -} \ No newline at end of file + + + +// .text("Score Gap : "+scoregap); + + +return average; //Needed for the next layer up in the analysis + +} + + + +function doBarData(id,qid) { + return fetch('get_qid_counts.php', { + method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: new URLSearchParams({ qid }) + }) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not OK'); + } + return response.json(); + }) + .then(data => { + if (data.error) { + throw new Error(data.error); + } +// console.log(data); +// console.log(data[0][Object.keys(data[0])[0]]); +/* */ + bardata = { + "-3": data[0][Object.keys(data[0])[0]], + "-2": data[1][Object.keys(data[1])[0]], + "-1": data[2][Object.keys(data[2])[0]], + "0": data[3][Object.keys(data[3])[0]], + "1": data[4][Object.keys(data[4])[0]], + "2": data[5][Object.keys(data[5])[0]], + "3": data[6][Object.keys(data[6])[0]], + }; + + //console.log(bardata); + drawBar(id,bardata); + // return data; // Should be an array like [{ value: -3, count: 2 }, ..., { value: 3, count: 5 }] + }); +} diff --git a/drawtriangle.js b/drawtriangle.js index 4b91246..e0c4873 100644 --- a/drawtriangle.js +++ b/drawtriangle.js @@ -155,7 +155,7 @@ svg.append("text") .attr("fill", "black") // 🎨 customize color .attr("font-size", bigfont) .attr("font-weight", "bold") - .attr("font-family", "Courier New, monospace") + .attr("font-family", 'sans-serif, Consolas, "Lucida Console", Menlo, "DejaVu Sans Mono", monospace') .text(`${mean}`); // Add axis labels diff --git a/drawtriangleinverted.js b/drawtriangleinverted.js index cb14993..a69b4bd 100644 --- a/drawtriangleinverted.js +++ b/drawtriangleinverted.js @@ -133,7 +133,7 @@ const midY = (bottomLeft[1] + bottomRight[1]) / 2; if (!svg.classed("no-text")){ svg.append("text") .attr("x", midX) - .attr("y", midY + 30) // Adjust for correct height (moved to bottom) + .attr("y", midY + 25) // Adjust for correct height (moved to bottom) .attr("text-anchor", "middle") .attr("fill", textcolour) // My Colour .attr("font-size", "22px") @@ -142,20 +142,20 @@ svg.append("text") } // And now a central number -let bigy = midY-45; +let bigy = midY + 70; let bigfont = "36px"; if (svg.classed("big-number")){ - bigy = midY-85; + bigy = midY + 120; bigfont = "70px"; } svg.append("text") .attr("x", midX) - .attr("y", midY + 70) + .attr("y", bigy) .attr("text-anchor", "middle") .attr("fill", "black") // 🎨 customize color .attr("font-size", bigfont) .attr("font-weight", "bold") - .attr("font-family", "Courier New, monospace") + .attr("font-family", 'sans-serif, Consolas, "Lucida Console", Menlo, "DejaVu Sans Mono", monospace') .text(`${mean}`); } diff --git a/getData.php b/getData.php index e0545e9..68b0cf2 100644 --- a/getData.php +++ b/getData.php @@ -7,7 +7,7 @@ $dataCentre = $config['data_centre']; $surveyId = $_POST['survey_id'] ?? null; if (!$surveyId) { - $surveyId="SV_bD838sNKZEmi6Tc"; // *****FIXME***** JUST FOR DEVELOPMENT + $surveyId="SV_cwKjMqAqGxImjMG"; // *****FIXME***** JUST FOR DEVELOPMENT //die("No survey ID provided."); } @@ -93,6 +93,10 @@ curl_close($ch); // Decode the response $data = json_decode($response, true); +//For testing only +echo $response; + + //Save surveyId //insertSurveyIfNotExists($identifier, $description); // The identifier is actually the surveyId, and the description isn't included at this point. $surveyIndex = getOrCreateSurvey($surveyId, ""); diff --git a/getQuestions.php b/getQuestions.php index 6e9a60b..8990d6a 100644 --- a/getQuestions.php +++ b/getQuestions.php @@ -7,7 +7,8 @@ $dataCenter = $config['data_centre']; // Get the survey ID from POST $surveyId = $_POST['survey_id'] ?? null; if (!$surveyId) { - $surveyId="SV_cAstEvm4ZrPaqGi"; + //$surveyId="SV_cAstEvm4ZrPaqGi"; + $surveyId="SV_cwKjMqAqGxImjMG"; #die("No survey ID provided."); } diff --git a/getSurveys.php b/getSurveys.php index f73899b..e88f94f 100644 --- a/getSurveys.php +++ b/getSurveys.php @@ -40,6 +40,19 @@ $surveys = $result['result']['elements'] ?? [];
This tool has been created by Peter Edmond working for Telos Partners as part of the OPL Data Analysis Project. Whilst it *SHOULD* behave as expected, it has been know for lightning to strike, computers to explode, and pigs to fly (allegedly, if thrown out of an aircraft?). There may be other interesting side effects? If this software does something unexpected, then it should be addressed to Telos Partners AFTER READING AND UNDERSTANDING how to report bugs effectively. +
+In order to be able to access the survey data, you must use this form to export the data from Qualtrics. This is done via an API key. Normally the survey will be immediately visible by name in the drop down, however under certain circumstances this might not work, such as if it has the same name as another survey, or the survey has not been shared with the account that is associated with the API. +
+ +The ability to check whether a surveyId is accessible for exporting can be checked directly via the surveyId. The form allowing direct entry of the surveyID lso carries out a full export of the data associated with the requested surveyId (provided that surveyId data can be accessed). The template survey is surveyId SV_cwKjMqAqGxImjMG if you wish to test a value. The surveyId is of the form SV_************** and can be found by looking at the survey web page path when looking at the survey in the Qualtrics interface. +
+ +NOTE - Once you have pressed submit, your browser will appear to freeze. This is because there is LOADS of work going on in the background to authenticate, identify all the answers that have been provided to this survey, and download them. Once the available answer sets have been downloaded, you will get a messy page showing the surveyId, the total number of COMPLETED AND SUBMITTED response sets (responseId). Once the page with the Response IDs has appeared, then the data has been fully exported, and is available for analysis.
+ +The export process OVER-WRITES any previous results for a particular survey. This means that that if data is deleted in the Qualtrics interface, then that data set will be lost. Additionally, by importing the data, and additional completed surveys will be added to the data set and be available for analysis. Carrying out the import process effectively aims to sychronise the data for analysis with that from the Qualtrics survey software.
+ +No surveys found or an error occurred.