bulltrackers-module 1.0.699 → 1.0.701
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -216,15 +216,22 @@ async function fetchDependencies(date, calcs, config, deps, manifestLookup = {},
|
|
|
216
216
|
|
|
217
217
|
/**
|
|
218
218
|
* Fetches result series (Historical data) for lookbacks.
|
|
219
|
+
* @param {string} endDateStr - The end date for the series
|
|
220
|
+
* @param {string[]} calcNames - Original (case-sensitive) computation names
|
|
221
|
+
* @param {Object} manifestLookup - Map of normalizedName -> category
|
|
222
|
+
* @param {Object} config - Configuration object
|
|
223
|
+
* @param {Object} deps - Dependencies (db, logger)
|
|
224
|
+
* @param {number} lookbackDays - Number of days to look back
|
|
219
225
|
*/
|
|
220
226
|
async function fetchResultSeries(endDateStr, calcNames, manifestLookup, config, deps, lookbackDays) {
|
|
221
227
|
const { db, logger } = deps;
|
|
222
228
|
const results = {}; // normalizedName -> { date -> data }
|
|
229
|
+
const { resultsCollection = 'computation_results', resultsSubcollection = 'results', computationsSubcollection = 'computations' } = config;
|
|
223
230
|
|
|
224
231
|
// Initialize results structure
|
|
225
232
|
calcNames.forEach(n => results[normalizeName(n)] = {});
|
|
226
233
|
|
|
227
|
-
// Generate Date List
|
|
234
|
+
// Generate Date List (going backwards from endDate)
|
|
228
235
|
const dates = [];
|
|
229
236
|
const d = new Date(endDateStr);
|
|
230
237
|
for (let i = 0; i < lookbackDays; i++) {
|
|
@@ -232,12 +239,22 @@ async function fetchResultSeries(endDateStr, calcNames, manifestLookup, config,
|
|
|
232
239
|
dates.push(d.toISOString().slice(0, 10));
|
|
233
240
|
}
|
|
234
241
|
|
|
242
|
+
// [DEBUG] Log the manifest lookup and resolved categories
|
|
243
|
+
logger.log('INFO', `[DependencyFetcher] 🔍 ManifestLookup has ${Object.keys(manifestLookup).length} entries`);
|
|
244
|
+
for (const rawName of calcNames) {
|
|
245
|
+
const norm = normalizeName(rawName);
|
|
246
|
+
const category = manifestLookup[norm] || 'analytics';
|
|
247
|
+
const samplePath = `${resultsCollection}/${dates[0]}/${resultsSubcollection}/${category}/${computationsSubcollection}/${rawName}`;
|
|
248
|
+
logger.log('INFO', `[DependencyFetcher] 📍 '${rawName}' -> category='${category}' -> Path: ${samplePath}`);
|
|
249
|
+
}
|
|
250
|
+
|
|
235
251
|
// Build Fetch Operations
|
|
236
252
|
const ops = [];
|
|
237
253
|
for (const dateStr of dates) {
|
|
238
254
|
for (const rawName of calcNames) {
|
|
239
255
|
const norm = normalizeName(rawName);
|
|
240
256
|
const category = manifestLookup[norm] || 'analytics';
|
|
257
|
+
|
|
241
258
|
ops.push(async () => {
|
|
242
259
|
const val = await fetchSingleResult(db, { ...config, logger }, dateStr, rawName, category);
|
|
243
260
|
if (val && !isDataEmpty(val)) {
|
|
@@ -253,6 +270,13 @@ async function fetchResultSeries(endDateStr, calcNames, manifestLookup, config,
|
|
|
253
270
|
for (let i = 0; i < ops.length; i += BATCH_SIZE) {
|
|
254
271
|
await Promise.all(ops.slice(i, i + BATCH_SIZE).map(fn => fn()));
|
|
255
272
|
}
|
|
273
|
+
|
|
274
|
+
// [DEBUG] Log results summary
|
|
275
|
+
for (const rawName of calcNames) {
|
|
276
|
+
const norm = normalizeName(rawName);
|
|
277
|
+
const foundDates = Object.keys(results[norm] || {});
|
|
278
|
+
logger.log('INFO', `[DependencyFetcher] ✅ '${rawName}' found data for ${foundDates.length}/${lookbackDays} days`);
|
|
279
|
+
}
|
|
256
280
|
|
|
257
281
|
return results;
|
|
258
282
|
}
|
|
@@ -9,6 +9,13 @@ const { commitResults } = require('../persistence/ResultCommitter');
|
|
|
9
9
|
const { fetchResultSeries } = require('../data/DependencyFetcher');
|
|
10
10
|
const { getManifest } = require('../topology/ManifestLoader');
|
|
11
11
|
|
|
12
|
+
// Helper to get calculations - prefer config.calculations, fallback to direct require
|
|
13
|
+
function getCalculations(config) {
|
|
14
|
+
if (config && config.calculations) return config.calculations;
|
|
15
|
+
try { return require('aiden-shared-calculations-unified').calculations; }
|
|
16
|
+
catch (e) { return {}; }
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
class MetaExecutor {
|
|
13
20
|
|
|
14
21
|
// =========================================================================
|
|
@@ -19,8 +26,8 @@ class MetaExecutor {
|
|
|
19
26
|
const dStr = date.toISOString().slice(0, 10);
|
|
20
27
|
const loader = new CachedDataLoader(config, deps);
|
|
21
28
|
|
|
22
|
-
// 1. Setup Manifest Lookup
|
|
23
|
-
const allManifests = getManifest(config.
|
|
29
|
+
// 1. Setup Manifest Lookup (use activeProductLines and calculations from config)
|
|
30
|
+
const allManifests = getManifest(config.activeProductLines || [], getCalculations(config), deps);
|
|
24
31
|
const manifestLookup = Object.fromEntries(allManifests.map(m => [normalizeName(m.name), m.category]));
|
|
25
32
|
|
|
26
33
|
// 2. Load Base Data (Always Required)
|
|
@@ -94,13 +101,17 @@ class MetaExecutor {
|
|
|
94
101
|
const { logger } = deps;
|
|
95
102
|
const calcs = [metadata]; // Treat single as list for helpers
|
|
96
103
|
|
|
104
|
+
// Build manifestLookup using calculations from config (set in index.js)
|
|
105
|
+
const allManifests = getManifest(config.activeProductLines || [], getCalculations(config), deps);
|
|
106
|
+
const manifestLookup = Object.fromEntries(allManifests.map(m => [normalizeName(m.name), m.category]));
|
|
107
|
+
|
|
97
108
|
// 1. Load Data using Shared Helpers
|
|
98
109
|
const [mappings, rankings, variableRoots, seriesData, piMasterList] = await Promise.all([
|
|
99
110
|
loader.loadMappings(),
|
|
100
111
|
loader.loadRankings(dateStr),
|
|
101
112
|
loadVariableRootData(loader, dateStr, calcs, logger),
|
|
102
|
-
loadSeriesData(loader, dateStr, calcs,
|
|
103
|
-
loader.loadPIMasterList()
|
|
113
|
+
loadSeriesData(loader, dateStr, calcs, manifestLookup, config, deps),
|
|
114
|
+
loader.loadPIMasterList()
|
|
104
115
|
]);
|
|
105
116
|
|
|
106
117
|
let rankingsYesterday = null;
|
|
@@ -213,7 +224,7 @@ async function loadSeriesData(loader, dateStr, calcs, manifestLookup, config, de
|
|
|
213
224
|
const rootRequests = {};
|
|
214
225
|
const depRequests = {}; // norm -> { days, originalName }
|
|
215
226
|
|
|
216
|
-
// 1. Aggregate Lookback Depths
|
|
227
|
+
// 1. Aggregate Lookback Depths from dependencySeries config
|
|
217
228
|
for (const c of calcs) {
|
|
218
229
|
if (c.rootDataSeries) {
|
|
219
230
|
Object.entries(c.rootDataSeries).forEach(([type, val]) => {
|
|
@@ -225,7 +236,6 @@ async function loadSeriesData(loader, dateStr, calcs, manifestLookup, config, de
|
|
|
225
236
|
Object.entries(c.dependencySeries).forEach(([name, val]) => {
|
|
226
237
|
const days = typeof val === 'object' ? val.lookback : val;
|
|
227
238
|
const norm = normalizeName(name);
|
|
228
|
-
// [FIX] Track BOTH normalized name (for dedup) AND original name (for Firestore lookup)
|
|
229
239
|
if (!depRequests[norm] || depRequests[norm].days < days) {
|
|
230
240
|
depRequests[norm] = { days, originalName: name };
|
|
231
241
|
}
|
|
@@ -252,12 +262,12 @@ async function loadSeriesData(loader, dateStr, calcs, manifestLookup, config, de
|
|
|
252
262
|
}
|
|
253
263
|
});
|
|
254
264
|
|
|
255
|
-
// 3. Fetch Dependency Series
|
|
256
|
-
// [FIX] Use ORIGINAL names for Firestore document lookup (case-sensitive)
|
|
265
|
+
// 3. Fetch Dependency Series (category comes from manifestLookup)
|
|
257
266
|
const depEntries = Object.values(depRequests);
|
|
258
267
|
if (depEntries.length > 0) {
|
|
259
268
|
const depOriginalNames = depEntries.map(e => e.originalName);
|
|
260
269
|
const maxDays = Math.max(...depEntries.map(e => e.days));
|
|
270
|
+
|
|
261
271
|
deps.logger.log('INFO', `[MetaExecutor] Loading up to ${maxDays}-day series for Dependencies: ${depOriginalNames.join(', ')}`);
|
|
262
272
|
seriesData.results = await fetchResultSeries(dateStr, depOriginalNames, manifestLookup, config, deps, maxDays);
|
|
263
273
|
}
|
|
@@ -13,6 +13,13 @@ const mathLayer = require('../layers/index');
|
|
|
13
13
|
const { performance } = require('perf_hooks');
|
|
14
14
|
const v8 = require('v8');
|
|
15
15
|
|
|
16
|
+
// Helper to get calculations - prefer config.calculations, fallback to direct require
|
|
17
|
+
function getCalculations(config) {
|
|
18
|
+
if (config && config.calculations) return config.calculations;
|
|
19
|
+
try { return require('aiden-shared-calculations-unified').calculations; }
|
|
20
|
+
catch (e) { return {}; }
|
|
21
|
+
}
|
|
22
|
+
|
|
16
23
|
class StandardExecutor {
|
|
17
24
|
|
|
18
25
|
// =========================================================================
|
|
@@ -383,17 +390,16 @@ async function loadGlobalRoots(loader, dateStr, calcs, deps) {
|
|
|
383
390
|
|
|
384
391
|
async function loadSeriesData(loader, dateStr, calcs, config, deps) {
|
|
385
392
|
const rootReqs = {};
|
|
386
|
-
const depReqs = {}; // norm -> { days, originalName }
|
|
393
|
+
const depReqs = {}; // norm -> { days, originalName, category }
|
|
387
394
|
|
|
388
395
|
calcs.forEach(c => {
|
|
389
396
|
if (c.manifest.rootDataSeries) {
|
|
390
397
|
Object.entries(c.manifest.rootDataSeries).forEach(([k, v]) => rootReqs[k] = Math.max(rootReqs[k]||0, v.lookback||v));
|
|
391
398
|
}
|
|
392
399
|
if (c.manifest.dependencySeries) {
|
|
393
|
-
// [FIX] Track BOTH normalized name (for dedup) AND original name (for Firestore lookup)
|
|
394
400
|
Object.entries(c.manifest.dependencySeries).forEach(([k, v]) => {
|
|
395
401
|
const norm = normalizeName(k);
|
|
396
|
-
const days = v.lookback
|
|
402
|
+
const days = typeof v === 'object' ? v.lookback : v;
|
|
397
403
|
if (!depReqs[norm] || depReqs[norm].days < days) {
|
|
398
404
|
depReqs[norm] = { days, originalName: k };
|
|
399
405
|
}
|
|
@@ -411,14 +417,15 @@ async function loadSeriesData(loader, dateStr, calcs, config, deps) {
|
|
|
411
417
|
if (rootMap[key]) series.root[key] = (await loader.loadSeries(rootMap[key], dateStr, days)).data;
|
|
412
418
|
}));
|
|
413
419
|
|
|
414
|
-
//
|
|
420
|
+
// Build lookup from ALL computations using config.calculations
|
|
415
421
|
const depEntries = Object.values(depReqs);
|
|
416
422
|
if (depEntries.length) {
|
|
417
423
|
const depOriginalNames = depEntries.map(e => e.originalName);
|
|
418
424
|
const maxDays = Math.max(...depEntries.map(e => e.days));
|
|
419
|
-
|
|
420
|
-
const allManifests = getManifest(config.
|
|
425
|
+
|
|
426
|
+
const allManifests = getManifest(config.activeProductLines || [], getCalculations(config), deps);
|
|
421
427
|
const lookup = Object.fromEntries(allManifests.map(m => [normalizeName(m.name), m.category]));
|
|
428
|
+
|
|
422
429
|
series.results = await fetchResultSeries(dateStr, depOriginalNames, lookup, config, deps, maxDays);
|
|
423
430
|
}
|
|
424
431
|
|