<?php
// Test script to verify the Bangla calculation fix

// Function to get grade point
function getGradePoint($grade) {
    switch ($grade) {
        case 'A+': return 5.00;
        case 'A': return 4.00;
        case 'A-': return 3.50;
        case 'B': return 3.00;
        case 'C': return 2.00;
        case 'D': return 1.00;
        default: return 0.00;
    }
}

// Test the user's example: CQ: 60, 67 (avg: 63), MCQ: 21, 20 (avg: 20)
$cq_marks_array = [60, 67];
$mcq_marks_array = [21, 20];

// Calculate averages
$cq_average = array_sum($cq_marks_array) / count($cq_marks_array); // 63.5 ≈ 63
$mcq_average = array_sum($mcq_marks_array) / count($mcq_marks_array); // 20.5 ≈ 20

echo "CQ Marks: " . implode(", ", $cq_marks_array) . " (Average: $cq_average)\n";
echo "MCQ Marks: " . implode(", ", $mcq_marks_array) . " (Average: $mcq_average)\n";

// Check passing criteria (Jessore Board rules)
if ($cq_average > 22 && $mcq_average > 9) {
    echo "Passed criteria: CQ > 22 AND MCQ > 9\n";
    
    // Calculate total obtained
    $total_obtained = $cq_average + $mcq_average; // 63.5 + 20.5 = 84
    echo "Total obtained marks: $total_obtained\n";
    
    // For combined Bangla, typically 2 papers of 100 marks each = 200 total
    $total_full_marks = 200;
    echo "Total full marks: $total_full_marks\n";
    
    // Calculate percentage
    $percentage = ($total_obtained / $total_full_marks) * 100;
    echo "Percentage: $percentage%\n";
    
    // Determine grade based on percentage
    if ($percentage >= 80) $grade = 'A+';
    elseif ($percentage >= 70) $grade = 'A';
    elseif ($percentage >= 60) $grade = 'A-';
    elseif ($percentage >= 50) $grade = 'B';
    elseif ($percentage >= 40) $grade = 'C';
    elseif ($percentage >= 33) $grade = 'D';
    else $grade = 'F';
    
    $grade_point = getGradePoint($grade);
    
    echo "Calculated Grade: $grade\n";
    echo "Calculated GPA: $grade_point\n";
    
    echo "\nExpected for user's example:\n";
    echo "- If grade is B (3.00), then percentage should be 50-59%\n";
    echo "- For 84 obtained, full marks would need to be ~140-168\n";
    echo "- This suggests there might be a different full marks calculation\n";
} else {
    echo "Failed criteria: CQ <= 22 OR MCQ <= 9\n";
    $grade = 'F';
    $grade_point = getGradePoint($grade);
    echo "Grade: $grade\n";
    echo "GPA: $grade_point\n";
}
?>