Auto commit: 2025-11-18T11:05:11.990Z

This commit is contained in:
Flatlogic Bot 2025-11-18 11:05:11 +00:00
parent 6a8221f33b
commit 3317cb7a89
2 changed files with 79 additions and 26 deletions

View File

@ -44,8 +44,35 @@ if ($_SESSION['question_index'] < count($questions)) {
foreach ($_SESSION['answers'] as $index => $answer) {
$formatted_answers[] = "Q: " . $questions[$index] . "\nA: " . $answer;
}
$prompt = "You are a burnout analysis expert. A user has completed a burnout survey. The user answered on a scale of 1-5 where 1 is 'Never' and 5 is 'Always'. Analyze the following survey answers and provide a detailed analysis.\n\nReturn the response as a JSON object. The JSON object must have the following keys: \"scores\", \"analysis\", \"recommendations\", and \"nextSteps\".\n\n- The 'scores' key should contain an object with 'Exhaustion', 'Cynicism', and 'Inefficacy' as keys, each with a numeric score from 0 to 5.\n- The 'analysis' key should contain an object with 'overallSummary', 'exhaustionSummary', 'cynicismSummary', and 'inefficacySummary' as keys, each containing a string with the corresponding analysis.\n- The 'recommendations' key should contain an array of objects, where each object has a 'title' and a 'description'.\n- The 'nextSteps' key should contain an array of strings.\n\nAnswers:";
$prompt .= implode("\n\n", $formatted_answers);
$prompt = <<<EOT
You are a burnout analysis expert. A user has answered a survey on a 1-5 scale (1='Never', 5='Always').
Analyze their answers and return ONLY a raw JSON object with the following structure:
{
"scores": {
"Exhaustion": <number>,
"Cynicism": <number>,
"Inefficacy": <number>
},
"analysis": {
"overallSummary": "<string>",
"exhaustionSummary": "<string>",
"cynicismSummary": "<string>",
"inefficacySummary": "<string>"
},
"recommendations": [
{
"title": "<string>",
"description": "<string>"
}
],
"nextSteps": [
"<string>"
]
}
User's Answers:
EOT;
$prompt .= "\n" . implode("\n", $formatted_answers);
$ai_response = LocalAIApi::createResponse([
'input' => [

View File

@ -10,6 +10,19 @@ if (!isset($_SESSION['results'])) {
}
$results = $_SESSION['results'];
// Attempt to decode if the results are a JSON string
if (is_string($results)) {
$decoded_results = json_decode($results, true);
if (json_last_error() === JSON_ERROR_NONE) {
$results = $decoded_results;
} else {
// Handle the case where the string is not valid JSON
$results = []; // Reset to a safe value
}
}
$scores = $results['scores'] ?? [];
$analysis = $results['analysis'] ?? [];
$recommendations = $results['recommendations'] ?? [];
@ -37,6 +50,14 @@ unset($_SESSION['results']);
<h1>Your Burnout Analysis</h1>
</div>
<div class="card-body">
<?php if (empty($scores) || empty($analysis) || empty($recommendations) || empty($nextSteps)): ?>
<div class="alert alert-danger" role="alert">
<h4 class="alert-heading">Analysis Failed</h4>
<p>We're sorry, but there was an error generating your burnout analysis. The data we received was incomplete or corrupted.</p>
<hr>
<p class="mb-0">Please try the survey again. If the problem persists, please contact support.</p>
</div>
<?php else: ?>
<?php if (!empty($analysis['overallSummary'])):
?>
<div class="alert alert-light" role="alert">
@ -120,7 +141,7 @@ unset($_SESSION['results']);
<p>No specific next steps available at this time.</p>
<?php
endif; ?>
<?php endif; ?>
</div>
<div class="card-footer text-center">
<a href="index.php" class="btn btn-primary">Take the Survey Again</a>
@ -130,30 +151,35 @@ unset($_SESSION['results']);
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
const scores = <?php echo json_encode($scores); ?>;
const ctx = document.getElementById('burnoutChart').getContext('2d');
const burnoutChart = new Chart(ctx, {
type: 'radar',
data: {
labels: Object.keys(scores),
datasets: [{
label: 'Burnout Dimensions',
data: Object.values(scores),
backgroundColor: 'rgba(0, 123, 255, 0.2)',
borderColor: 'rgba(0, 123, 255, 1)',
borderWidth: 1
}]
},
options: {
scales: {
r: {
angleLines: {
display: false
},
suggestedMin: 0,
suggestedMax: 5
document.addEventListener('DOMContentLoaded', function () {
const scores = <?php echo json_encode($scores); ?>;
const canvas = document.getElementById('burnoutChart');
if (canvas) {
const ctx = canvas.getContext('2d');
const burnoutChart = new Chart(ctx, {
type: 'radar',
data: {
labels: Object.keys(scores),
datasets: [{
label: 'Burnout Dimensions',
data: Object.values(scores),
backgroundColor: 'rgba(0, 123, 255, 0.2)',
borderColor: 'rgba(0, 123, 255, 1)',
borderWidth: 1
}]
},
options: {
scales: {
r: {
angleLines: {
display: false
},
suggestedMin: 0,
suggestedMax: 5
}
}
}
}
});
}
});
</script>