Indices: ${pattern.indices.join(', ')}
${pattern.description}
`;
patternListUl.appendChild(listItem);
});
}
}
// Function to reset the tool
window.resetTool = function() {
dataSeriesInput.value = '';
trendWindowInput.value = '5';
anomalyThresholdInput.value = '2.0';
clearError();
resultsSection.style.display = 'none';
patternChartSvg.innerHTML = ''; // Clear chart
patternListUl.innerHTML = '
No significant patterns detected based on current parameters.';
};
// PDF Download Functionality
window.downloadPdf = function() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(22);
doc.text("Deep Learning Pattern Recognition Report", 105, 20, null, null, "center");
doc.setFontSize(12);
doc.text(`Report Date: ${new Date().toLocaleDateString()}`, 14, 35);
doc.text(`Trend Analysis Window: ${trendWindowInput.value} periods`, 14, 42);
doc.text(`Anomaly Threshold: ${anomalyThresholdInput.value} Std Devs`, 14, 49);
let yOffset = 60;
// Input Data Section
doc.setFontSize(16);
doc.text("Input Data Series", 14, yOffset);
yOffset += 10;
doc.setFontSize(10);
doc.text(`Data: ${dataSeriesInput.value.replace(/,/g, ', ')}`, 14, yOffset, { maxWidth: 180 });
yOffset += doc.getTextDimensions(`Data: ${dataSeriesInput.value}`, { maxWidth: 180 }).h + 20;
// Chart Placeholder
doc.setFontSize(16);
doc.text("Data Series with Detected Patterns (Visualized On-Screen)", 14, yOffset);
yOffset += 10;
doc.setFontSize(10);
doc.text("The interactive chart on the tool visually highlights the detected patterns.", 14, yOffset);
doc.text("Please refer to the online tool for the full visual representation.", 14, yOffset + 5);
yOffset += 20;
// AI-Generated Pattern Analysis
doc.setFontSize(16);
doc.text("AI-Generated Pattern Analysis", 14, yOffset);
yOffset += 10;
const patterns = [];
const patternItems = patternListUl.querySelectorAll('.pattern-item');
if (patternItems.length === 0 || patternListUl.querySelector('.no-patterns-detected')) {
patterns.push([{ content: "No significant patterns detected based on current parameters.", styles: { fontStyle: 'italic', textColor: [102, 102, 102] } }]);
} else {
patternItems.forEach(item => {
const type = item.querySelector('.type').textContent;
const strength = item.querySelector('strong').textContent;
const indices = item.querySelector('p:nth-child(2)').textContent.replace('Indices: ', '');
const description = item.querySelector('p:nth-child(3)').textContent;
patterns.push([{ content: `${type} (Strength: ${strength})`, styles: { fontStyle: 'bold', fillColor: [240, 248, 255], textColor: [0, 123, 255] } }]);
patterns.push([`Indices: ${indices}`]);
patterns.push([description]);
patterns.push(['']); // Empty row for spacing
});
}
doc.autoTable({
startY: yOffset,
body: patterns,
theme: 'plain',
styles: {
font: 'helvetica',
fontSize: 10,
cellPadding: 3,
valign: 'top',
lineColor: [230, 230, 230],
lineWidth: 0.1
},
didParseCell: function(data) {
if (data.cell.raw && data.cell.raw.content && data.cell.raw.content.includes("No significant patterns")) {
data.cell.styles.halign = 'center';
}
}
});
doc.save(`Pattern_Recognition_Report.pdf`);
};
// Initial example data and analysis on load
dataSeriesInput.value = '10, 12, 11, 15, 14, 18, 17, 20, 22, 21, 15, 8, 5, 12, 10, 15, 20, 25, 22, 28, 30, 29, 27, 24, 20, 18, 15, 10, 8, 5';
trendWindowInput.value = '7';
anomalyThresholdInput.value = '2.5';
recognizePatterns(); // Run analysis on page load with example data
});