feat: implement consistent 20-color mapping for visible products across dashboard charts
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m30s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m30s
This commit is contained in:
@@ -61,6 +61,25 @@ const verifyToken = (req, res, next) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sseClients = new Set();
|
||||||
|
|
||||||
|
// SSE Endpoint for real-time updates
|
||||||
|
app.get('/api/stream', (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'text/event-stream');
|
||||||
|
res.setHeader('Cache-Control', 'no-cache');
|
||||||
|
res.setHeader('Connection', 'keep-alive');
|
||||||
|
res.flushHeaders();
|
||||||
|
|
||||||
|
// Send initial connection event
|
||||||
|
res.write('data: {"connected": true}\n\n');
|
||||||
|
|
||||||
|
sseClients.add(res);
|
||||||
|
|
||||||
|
req.on('close', () => {
|
||||||
|
sseClients.delete(res);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Login Endpoint
|
// Login Endpoint
|
||||||
app.post('/api/login', (req, res) => {
|
app.post('/api/login', (req, res) => {
|
||||||
const { email, password } = req.body;
|
const { email, password } = req.body;
|
||||||
|
|||||||
33
fake-data.cjs
Normal file
33
fake-data.cjs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const products = [];
|
||||||
|
|
||||||
|
// Group 1: High Quantity, Low Price (Top 10 in Bar Chart, won't show in Pie Chart)
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
products.push({
|
||||||
|
Nome_Cliente: "Fake Client A" + i,
|
||||||
|
Data_Pedido: "06-05-2026",
|
||||||
|
Valor_Pedido: 100,
|
||||||
|
ID_Produto: "QA" + i,
|
||||||
|
Descricao_Produto: "Produto Muito Vendido " + i,
|
||||||
|
Quantidade: 1000 + i, // High sales
|
||||||
|
Valor_Unitario: 0.10 // Low revenue
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group 2: Low Quantity, High Price (Top 10 in Pie Chart, won't show in Bar Chart)
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
products.push({
|
||||||
|
Nome_Cliente: "Fake Client B" + i,
|
||||||
|
Data_Pedido: "06-05-2026",
|
||||||
|
Valor_Pedido: 10000,
|
||||||
|
ID_Produto: "QB" + i,
|
||||||
|
Descricao_Produto: "Produto Muito Caro " + i,
|
||||||
|
Quantidade: 1, // Low sales
|
||||||
|
Valor_Unitario: 10000 + i // High revenue
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch('http://localhost:3004/api/data', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json', 'x-api-key': 'nexstar_secret_key_123' },
|
||||||
|
body: JSON.stringify(products)
|
||||||
|
}).then(res => console.log("Status:", res.status)).catch(console.error);
|
||||||
42
fake-data.js
Normal file
42
fake-data.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Clear previous data for a clean slate
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
const pool = new Pool({ connectionString: 'postgres://graphuser:graphpassword@localhost:5432/graphdb' });
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
await pool.query('TRUNCATE TABLE orders RESTART IDENTITY;');
|
||||||
|
|
||||||
|
// Group 1: High Quantity, Low Price (Top 10 in Bar Chart, won't show in Pie Chart)
|
||||||
|
const group1 = Array.from({length: 10}, (_, i) => ({
|
||||||
|
Nome_Cliente: "Fake Client A" + i,
|
||||||
|
Data_Pedido: "06-05-2026",
|
||||||
|
Valor_Pedido: 100,
|
||||||
|
ID_Produto: "QA" + i,
|
||||||
|
Descricao_Produto: "Produto Muito Vendido " + i,
|
||||||
|
Quantidade: 1000 + i, // High sales
|
||||||
|
Valor_Unitario: 0.10 // Low revenue
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Group 2: Low Quantity, High Price (Top 10 in Pie Chart, won't show in Bar Chart)
|
||||||
|
const group2 = Array.from({length: 10}, (_, i) => ({
|
||||||
|
Nome_Cliente: "Fake Client B" + i,
|
||||||
|
Data_Pedido: "06-05-2026",
|
||||||
|
Valor_Pedido: 10000,
|
||||||
|
ID_Produto: "QB" + i,
|
||||||
|
Descricao_Produto: "Produto Muito Caro " + i,
|
||||||
|
Quantidade: 1, // Low sales
|
||||||
|
Valor_Unitario: 10000 + i // High revenue
|
||||||
|
}));
|
||||||
|
|
||||||
|
const products = [...group1, ...group2];
|
||||||
|
|
||||||
|
const res = await fetch('http://localhost:3004/api/data', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json', 'x-api-key': 'nexstar_secret_key_123' },
|
||||||
|
body: JSON.stringify(products)
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(res.status);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
Reference in New Issue
Block a user