Fairness Calculator

Fairness Calculator

This tool helps evaluate the fairness of a distribution or comparison based on different perspectives. Enter the values and select the fairness criteria to analyze.

Please enter at least two valid numbers.

'; resultsDiv.style.display = 'block'; downloadBtn.style.display = 'none'; return; } const sum = values.reduce((a, b) => a + b, 0); const average = values.length > 0 ? sum / values.length : 0; const min = values.length > 0 ? Math.min(...values) : 0; const max = values.length > 0 ? Math.max(...values) : 0; let fairnessReport = ''; fairnessReport += `
Number of Values: ${values.length}
`; fairnessReport += `
Sum of Values: ${sum.toFixed(2)}
`; fairnessReport += `
Average Value: ${average.toFixed(2)}
`; fairnessReport += `
Minimum Value: ${min.toFixed(2)}
`; fairnessReport += `
Maximum Value: ${max.toFixed(2)}
`; if (!isNaN(comparisonValue)) { let aboveCount = 0; let belowCount = 0; let equalCount = 0; values.forEach(v => { if (v > comparisonValue) aboveCount++; else if (v < comparisonValue) belowCount++; else equalCount++; }); fairnessReport += `
Comparison Value: ${comparisonValue.toFixed(2)}
`; fairnessReport += `
Values Above Comparison: ${aboveCount}
`; fairnessReport += `
Values Below Comparison: ${belowCount}
`; fairnessReport += `
Values Equal to Comparison: ${equalCount}
`; } // Simple measure of dispersion (range) const range = max - min; fairnessReport += `
Range (Max - Min): ${range.toFixed(2)}
`; fairnessMetricsDiv.innerHTML = fairnessReport; resultsDiv.style.display = 'block'; downloadBtn.style.display = 'block'; } function downloadPDF() { const resultsDiv = document.getElementById('results'); const pdf = new jspdf.jsPDF(); const margin = 10; let y = margin; const lineHeight = 5; // Adjust for better spacing const pageWidth = pdf.internal.pageSize.getWidth(); // Background color pdf.setFillColor(244, 244, 244); // Light Gray in RGB pdf.rect(0, 0, pageWidth, pdf.internal.pageSize.getHeight(), 'F'); // Title pdf.setTextColor(76, 175, 80); // Primary Green in RGB pdf.setFontSize(20); const title = 'Fairness Analysis Results'; const titleWidth = pdf.getTextWidth(title); pdf.text(title, pageWidth / 2, y + 10, { align: 'center' }); y += 20; // Results text pdf.setTextColor(51, 51, 51); // Dark Gray in RGB pdf.setFontSize(12); const textLines = resultsDiv.innerText.split('\n'); textLines.forEach(line => { const splitLines = pdf.splitTextToSize(line, pageWidth - 2 * margin); splitLines.forEach(splitLine => { if (y + lineHeight > pdf.internal.pageSize.getHeight() - margin) { pdf.addPage(); y = margin; } pdf.text(margin, y, splitLine); y += lineHeight; }); }); pdf.save('fairness_analysis.pdf'); }
Scroll to Top