latest
This commit is contained in:
parent
7b89d5f934
commit
8c01e3ab0b
65
index.php
65
index.php
@ -301,7 +301,8 @@
|
|||||||
analyze_complaints: "Analysis of customer complaints shows that 65% of delivery time issues are concentrated in the West region, primarily with one shipping carrier. I recommend diversifying our shipping partners in that region.",
|
analyze_complaints: "Analysis of customer complaints shows that 65% of delivery time issues are concentrated in the West region, primarily with one shipping carrier. I recommend diversifying our shipping partners in that region.",
|
||||||
generate_seller_dashboard: "Weekly Seller Performance Dashboard: \n**Top Performers:** SellerA (99% positive feedback), SellerB (fastest shipping), SellerC (most new products). \n**Needs Attention:** SellerX (rating dropped to 85%), SellerY (2 open disputes).",
|
generate_seller_dashboard: "Weekly Seller Performance Dashboard: \n**Top Performers:** SellerA (99% positive feedback), SellerB (fastest shipping), SellerC (most new products). \n**Needs Attention:** SellerX (rating dropped to 85%), SellerY (2 open disputes).",
|
||||||
summarize_refunds: "Monthly Refund Summary: A total of 152 refunds were processed this month. Top reasons: 1. Item arrived damaged (45%), 2. Item not as described (30%), 3. Accidental order (15%). There is a 20% increase in 'damaged item' refunds for electronics.",
|
summarize_refunds: "Monthly Refund Summary: A total of 152 refunds were processed this month. Top reasons: 1. Item arrived damaged (45%), 2. Item not as described (30%), 3. Accidental order (15%). There is a 20% increase in 'damaged item' refunds for electronics.",
|
||||||
generate_sales_chart: 'Here is the sales report for the last 6 months:<br><canvas id="salesChart" width="400" height="200"></canvas>'
|
generate_sales_chart: 'Here is the sales report for the last 6 months:<br><canvas id="salesChart" width="400" height="200"></canvas>',
|
||||||
|
generate_pie_chart: 'Here is a pie chart based on your request:<br><canvas id="pieChart" width="400" height="200"></canvas>'
|
||||||
};
|
};
|
||||||
|
|
||||||
const taskMap = {};
|
const taskMap = {};
|
||||||
@ -326,29 +327,49 @@
|
|||||||
sidebarQuickActions.addEventListener('click', handleQuickActionClick);
|
sidebarQuickActions.addEventListener('click', handleQuickActionClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderChart() {
|
function renderChart(type = 'bar', canvasId = 'salesChart', data = {}) {
|
||||||
// Use a MutationObserver to wait for the canvas to be added to the DOM
|
|
||||||
const observer = new MutationObserver((mutationsList, observer) => {
|
const observer = new MutationObserver((mutationsList, observer) => {
|
||||||
for(const mutation of mutationsList) {
|
for(const mutation of mutationsList) {
|
||||||
if (mutation.type === 'childList') {
|
if (mutation.type === 'childList') {
|
||||||
const chartCanvas = document.getElementById('salesChart');
|
const chartCanvas = document.getElementById(canvasId);
|
||||||
if (chartCanvas) {
|
if (chartCanvas) {
|
||||||
const ctx = chartCanvas.getContext('2d');
|
const ctx = chartCanvas.getContext('2d');
|
||||||
new Chart(ctx, {
|
let chartConfig;
|
||||||
|
if (type === 'pie') {
|
||||||
|
chartConfig = {
|
||||||
|
type: 'pie',
|
||||||
|
data: {
|
||||||
|
labels: data.labels || ['Red', 'Blue', 'Yellow'],
|
||||||
|
datasets: [{
|
||||||
|
label: 'My First Dataset',
|
||||||
|
data: data.values || [300, 50, 100],
|
||||||
|
backgroundColor: [
|
||||||
|
'rgb(255, 99, 132)',
|
||||||
|
'rgb(54, 162, 235)',
|
||||||
|
'rgb(255, 205, 86)'
|
||||||
|
],
|
||||||
|
hoverOffset: 4
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else { // default to bar
|
||||||
|
chartConfig = {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: {
|
data: {
|
||||||
labels: ['January', 'February', 'March', 'April', 'May', 'June'],
|
labels: data.labels || ['January', 'February', 'March', 'April', 'May', 'June'],
|
||||||
datasets: [{
|
datasets: [{
|
||||||
label: 'Sales',
|
label: 'Sales',
|
||||||
data: [12, 19, 3, 5, 2, 3],
|
data: data.values || [12, 19, 3, 5, 2, 3],
|
||||||
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
||||||
borderColor: 'rgba(75, 192, 192, 1)',
|
borderColor: 'rgba(75, 192, 192, 1)',
|
||||||
borderWidth: 1
|
borderWidth: 1
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
options: { scales: { y: { beginAtZero: true } } }
|
options: { scales: { y: { beginAtZero: true } } }
|
||||||
});
|
};
|
||||||
observer.disconnect(); // Stop observing once the chart is rendered
|
}
|
||||||
|
new Chart(ctx, chartConfig);
|
||||||
|
observer.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -373,19 +394,37 @@
|
|||||||
|
|
||||||
function processMessage(text) {
|
function processMessage(text) {
|
||||||
const trimmedText = text.trim();
|
const trimmedText = text.trim();
|
||||||
|
const lowerCaseText = trimmedText.toLowerCase();
|
||||||
if (!trimmedText) return;
|
if (!trimmedText) return;
|
||||||
|
|
||||||
activateSidebar();
|
activateSidebar();
|
||||||
addMessage(trimmedText, 'user');
|
addMessage(trimmedText, 'user');
|
||||||
userInput.value = '';
|
userInput.value = '';
|
||||||
|
|
||||||
const task = taskMap[trimmedText] || Object.keys(taskMap).find(key => key.includes(trimmedText));
|
let task = taskMap[trimmedText] || Object.keys(taskMap).find(key => key.includes(trimmedText));
|
||||||
|
let response = assistantResponses[task];
|
||||||
|
let chartType = null;
|
||||||
|
let chartData = {};
|
||||||
|
|
||||||
|
if (!task) {
|
||||||
|
if (lowerCaseText.includes('pie chart')) {
|
||||||
|
chartType = 'pie';
|
||||||
|
task = 'generate_pie_chart';
|
||||||
|
response = assistantResponses[task];
|
||||||
|
} else if (lowerCaseText.includes('chart') || lowerCaseText.includes('graph') || lowerCaseText.includes('report')) {
|
||||||
|
chartType = 'bar';
|
||||||
|
task = 'generate_sales_chart';
|
||||||
|
response = assistantResponses[task];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const response = assistantResponses[task] || "I'm a demo assistant. My capabilities are limited to the quick actions for now. Please select one of the options or upload a file.";
|
response = response || "I'm a demo assistant. My capabilities are limited to the quick actions for now. Please select one of the options or upload a file.";
|
||||||
|
|
||||||
if (task === 'generate_sales_chart') {
|
if (task === 'generate_sales_chart' || chartType === 'bar') {
|
||||||
renderChart();
|
renderChart('bar', 'salesChart', chartData);
|
||||||
|
} else if (task === 'generate_pie_chart' || chartType === 'pie') {
|
||||||
|
renderChart('pie', 'pieChart', chartData);
|
||||||
}
|
}
|
||||||
|
|
||||||
addMessage(response, 'assistant');
|
addMessage(response, 'assistant');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user