add worker event tracking; implement worker rates display in admin panel
This commit is contained in:
+25
-12
@@ -234,17 +234,19 @@ async function adminRoutes(fastify) {
|
||||
const companies = db.prepare(`SELECT COUNT(*) as n FROM tracked_companies`).get().n;
|
||||
const embeddings = db.prepare(`SELECT COUNT(*) as n FROM company_embeddings`).get().n;
|
||||
|
||||
const processed5m = db.prepare(`
|
||||
SELECT COUNT(*) as n FROM article_queue
|
||||
WHERE status = 'processed' AND updated_at >= datetime('now', '-5 minutes')
|
||||
`).get().n;
|
||||
let workerRates = [];
|
||||
try {
|
||||
workerRates = db.prepare(`
|
||||
SELECT
|
||||
worker,
|
||||
SUM(CASE WHEN completed_at >= datetime('now', '-5 minutes') THEN 1 ELSE 0 END) as n5m,
|
||||
SUM(CASE WHEN completed_at >= datetime('now', '-1 minute') THEN 1 ELSE 0 END) as n1m
|
||||
FROM worker_events
|
||||
GROUP BY worker
|
||||
`).all();
|
||||
} catch (_) {}
|
||||
|
||||
const processed1m = db.prepare(`
|
||||
SELECT COUNT(*) as n FROM article_queue
|
||||
WHERE status = 'processed' AND updated_at >= datetime('now', '-1 minute')
|
||||
`).get().n;
|
||||
|
||||
return { available: true, queue, knowledge, predictions, companies, embeddings, processed5m, processed1m };
|
||||
return { available: true, queue, knowledge, predictions, companies, embeddings, workerRates };
|
||||
});
|
||||
|
||||
fastify.get('/admin/api/intelligence/companies', async (request, reply) => {
|
||||
@@ -333,10 +335,21 @@ async function adminRoutes(fastify) {
|
||||
|
||||
const allTracked = idb.prepare(`SELECT id, name, ticker FROM tracked_companies`).all();
|
||||
|
||||
// untracked entities — appear only as to_entity with no to_company_id
|
||||
// build a lowercase name+alias set so we can exclude untracked entities
|
||||
// that are just unresolved references to tracked companies
|
||||
const trackedNameSet = new Set();
|
||||
for (const c of allTracked) {
|
||||
trackedNameSet.add(c.name.toLowerCase());
|
||||
trackedNameSet.add(c.ticker.toLowerCase());
|
||||
}
|
||||
|
||||
const untrackedSeen = new Set();
|
||||
for (const e of edges) {
|
||||
if (!e.to_company_id && e.to_entity) untrackedSeen.add(e.to_entity);
|
||||
if (!e.to_company_id && e.to_entity) {
|
||||
if (!trackedNameSet.has(e.to_entity.toLowerCase())) {
|
||||
untrackedSeen.add(e.to_entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const nodes = [
|
||||
|
||||
Reference in New Issue
Block a user