/**
* Results Display - Show evaluation results to user
*/
/**
* Interpret Gardner grade
*/
export function interpretGrade(grade) {
if (grade === 'poor grade embryo' || !grade || grade.length < 3) {
return '
This embryo has been classified as poor grade.
';
}
const stage = grade[0];
const icm = grade[1];
const te = grade[2];
const stageDesc = {
'3': 'Early Blastocyst (cavity < 50% of embryo)',
'4': 'Expanded Blastocyst (cavity >= 50% of embryo)',
'5': 'Hatching/Hatched Blastocyst'
};
const icmDesc = {
'A': 'Excellent - Tightly packed, many cells',
'B': 'Good - Loosely grouped, several cells',
'C': 'Fair - Very few cells'
};
const teDesc = {
'A': 'Excellent - Many cells, cohesive epithelium',
'B': 'Good - Few cells, loose epithelium',
'C': 'Fair - Very few large cells'
};
return `
- Stage ${stage}: ${stageDesc[stage] || 'Unknown stage'}
- ICM Quality ${icm}: ${icmDesc[icm] || 'Unknown quality'}
- TE Quality ${te}: ${teDesc[te] || 'Unknown quality'}
`;
}
/**
* Display top predictions
*/
export function displayPredictions(predictions, container) {
if (!predictions || Object.keys(predictions).length === 0) {
container.innerHTML = '';
return;
}
const sortedPredictions = Object.entries(predictions)
.sort((a, b) => b[1] - a[1])
.slice(0, 5);
container.innerHTML = sortedPredictions.map(([label, confidence]) => `
${label}
${(confidence * 100).toFixed(1)}%
`).join('');
}
/**
* Get image quality tip HTML
*/
function getImageQualityTip() {
return `
Image Quality Tip
If this result seems incorrect, please ensure:
- The image is clear and well-focused
Try uploading a clearer image for more accurate results.
`;
}
/**
* Display single embryo results
*/
export function displaySingleEmbryoResults(result) {
const resultsDiv = document.getElementById('singleResults');
const predictionsDiv = document.getElementById('singlePredictions');
if (!resultsDiv || !predictionsDiv) return;
if (result.quality === 'poor') {
resultsDiv.innerHTML = `
Quality: Poor Grade Embryo
Assessment
This embryo has been classified as poor quality and is not suitable for transfer.
Recommendation: This embryo does not meet the minimum quality standards for viable transfer.
${getImageQualityTip()}
`;
predictionsDiv.innerHTML = '';
} else {
resultsDiv.innerHTML = `
Predicted Grade: ${result.grade}
Grade Interpretation
${interpretGrade(result.grade)}
`;
displayPredictions(result.predictions, predictionsDiv);
}
}
/**
* Display cropped embryo results
*/
export function displayCroppedEmbryoResults(result) {
const resultsDiv = document.getElementById('croppedResults');
const predictionsDiv = document.getElementById('croppedPredictions');
if (!resultsDiv || !predictionsDiv) return;
if (result.quality === 'poor') {
resultsDiv.innerHTML = `
Quality: Poor Grade Embryo
This embryo is not suitable for transfer.
Tip: If this seems incorrect, try uploading a clearer, well-focused image of the embryo for more accurate assessment.
`;
predictionsDiv.innerHTML = '';
} else {
resultsDiv.innerHTML = `
Predicted Grade: ${result.grade}
${interpretGrade(result.grade)}
`;
displayPredictions(result.predictions, predictionsDiv);
}
}
/**
* Display quick evaluation results
*/
export function displayQuickResults(result) {
const resultsDiv = document.getElementById('quickResults');
const predictionsDiv = document.getElementById('quickPredictions');
if (!resultsDiv || !predictionsDiv) return;
if (result.quality === 'poor') {
resultsDiv.innerHTML = `
Quality: Poor Grade Embryo
This embryo has been classified as poor quality and is not suitable for transfer.
${getImageQualityTip()}
`;
predictionsDiv.innerHTML = '';
} else {
resultsDiv.innerHTML = `
Predicted Grade: ${result.grade}
${interpretGrade(result.grade)}
`;
displayPredictions(result.predictions, predictionsDiv);
}
}
/**
* Display classification status
*/
export function displayClassificationStatus(result) {
const statusDiv = document.getElementById('classificationStatus');
if (!statusDiv) return;
const isEmbryo = result.label === 'yes';
if (isEmbryo) {
statusDiv.innerHTML = `
Embryo Detected
Image successfully classified as embryo.
Confidence: ${(result.confidence * 100).toFixed(1)}%
Click 'Next: Detect Embryos' to continue.
`;
} else {
statusDiv.innerHTML = `
Not an Embryo
The image does not appear to contain an embryo.
Confidence: ${(result.confidence * 100).toFixed(1)}%
Please upload a valid embryo image to proceed.
`;
}
}
/**
* Display final results in Step 5
*/
export function displayFinalResults(result) {
const resultsDiv = document.getElementById('finalResults');
const predictionsDiv = document.getElementById('finalPredictions');
if (!resultsDiv || !predictionsDiv) return;
if (result.quality === 'poor') {
resultsDiv.innerHTML = `
Quality: Poor Grade Embryo
Assessment
This embryo has been classified as poor quality and is not suitable for transfer.
Recommendation: This embryo does not meet the minimum quality standards for viable transfer.
${getImageQualityTip()}
`;
predictionsDiv.innerHTML = '';
} else {
resultsDiv.innerHTML = `
Predicted Grade: ${result.grade}
Grade Interpretation
${interpretGrade(result.grade)}
Analysis Complete
The embryo has been successfully evaluated using AI-powered analysis.
`;
displayPredictions(result.predictions, predictionsDiv);
}
}