testowa

/project-root |– /static | |– /css | | |– style.css | |– /js | | |– script.js |– /templates | |– index.html | |– survey.html | |– results.html |– app.py |– requirements.txt Ankieta

Witamy w ankiecie

Ankieta

Kategoria 1

Wyniki

Wyniki

body { font-family: Arial, sans-serif; } h1, h2 { color: #333; } form { margin: 20px; } input[type=”number”] { width: 50px; } button, input[type=”submit”] { margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; } button:hover, input[type=”submit”]:hover { background-color: #0056b3; } document.getElementById(’surveyForm’).addEventListener(’submit’, function(event) { event.preventDefault(); const formData = new FormData(event.target); const data = {}; formData.forEach((value, key) => { data[key] = parseInt(value); }); fetch(’/results’, { method: 'POST’, headers: { 'Content-Type’: 'application/json’ }, body: JSON.stringify(data) }) .then(response => response.json()) .then(results => { drawChart(results); }); }); function drawChart(data) { const width = 450, height = 450, margin = 40; const radius = Math.min(width, height) / 2 – margin; const svg = d3.select(„#chart”) .append(„svg”) .attr(„width”, width) .attr(„height”, height) .append(„g”) .attr(„transform”, `translate(${width / 2}, ${height / 2})`); const color = d3.scaleOrdinal() .domain(data) .range(d3.schemeSet2); const pie = d3.pie() .value(d => d.value); const data_ready = pie(d3.entries(data)); svg .selectAll(’whatever’) .data(data_ready) .join(’path’) .attr(’d’, d3.arc() .innerRadius(0) .outerRadius(radius) ) .attr(’fill’, d => color(d.data.key)) .attr(„stroke”, „black”) .style(„stroke-width”, „2px”) .style(„opacity”, 0.7); } function downloadPDF() { const element = document.getElementById(’chart’); html2canvas(element).then(canvas => { const imgData = canvas.toDataURL(’image/png’); const pdf = new jsPDF(); pdf.addImage(imgData, 'PNG’, 10, 10); pdf.save(„wyniki.pdf”); }); } from flask import Flask, render_template, request, jsonify import json app = Flask(__name__) @app.route(’/’) def index(): return render_template(’index.html’) @app.route(’/survey’) def survey(): return render_template(’survey.html’) @app.route(’/results’, methods=[’POST’]) def results(): data = request.get_json() # Przetwarzanie danych ankiety, np. obliczanie średnich wyników results = { 'category1′: 5, 'category2′: -3, 'category3′: 7, 'category4′: 2, 'category5′: 0, 'category6′: -1 } return jsonify(results) if __name__ == '__main__’: app.run(debug=True)