bulltrackers-module 1.0.183 → 1.0.184

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * FIXED: computation_controller.js
3
- * V3.3: Adds Price Loading for Meta Context & Fixes Context Injection
3
+ * V3.4: Adds Price Loading & Context Injection.
4
4
  */
5
5
 
6
6
  const { DataExtractor,
@@ -55,34 +55,25 @@ class DataLoader {
55
55
 
56
56
  try {
57
57
  const snapshot = await db.collection(collection).get();
58
- if (snapshot.empty) return { history: [] };
58
+ if (snapshot.empty) return { history: {} };
59
59
 
60
- // Flatten shards into a single array for the context
61
- // Structure expected by calculation: Array of { instrumentId, prices: {...} }
62
- const allPrices = [];
60
+ const historyMap = {};
63
61
 
64
62
  snapshot.forEach(doc => {
65
63
  const shardData = doc.data();
66
- // Iterate keys in shard (instrumentIds)
67
- for (const [instId, data] of Object.entries(shardData)) {
68
- if (data && data.prices) {
69
- allPrices.push({
70
- instrumentId: instId,
71
- ...data
72
- });
73
- }
74
- }
64
+ // Merge shard keys (instrumentIds) into main map
65
+ if (shardData) Object.assign(historyMap, shardData);
75
66
  });
76
67
 
77
- logger.log('INFO', `[DataLoader] Loaded prices for ${allPrices.length} instruments.`);
68
+ logger.log('INFO', `[DataLoader] Loaded prices for ${Object.keys(historyMap).length} instruments.`);
78
69
 
79
- // Cache as an object with 'history' array to match context expectations
80
- this.cache.prices = { history: allPrices };
70
+ // Cache as an object with 'history' map to match priceExtractor expectations
71
+ this.cache.prices = { history: historyMap };
81
72
  return this.cache.prices;
82
73
 
83
74
  } catch (e) {
84
75
  logger.log('ERROR', `[DataLoader] Failed to load prices: ${e.message}`);
85
- return { history: [] };
76
+ return { history: {} };
86
77
  }
87
78
  }
88
79
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * FILENAME: bulltrackers-module/functions/computation-system/helpers/orchestration_helpers.js
3
- * FIXED: Only marks computations as TRUE if they actually store results.
3
+ * FIXED: Explicit Logging + Honest Status Updates
4
4
  */
5
5
 
6
6
  const { ComputationController } = require('../controllers/computation_controller');
@@ -28,8 +28,6 @@ function checkRootDependencies(calcManifest, rootDataStatus) {
28
28
  else if (dep === 'insights' && !rootDataStatus.hasInsights) missing.push('insights');
29
29
  else if (dep === 'social' && !rootDataStatus.hasSocial) missing.push('social');
30
30
  else if (dep === 'history' && !rootDataStatus.hasHistory) missing.push('history');
31
- // Note: 'price' is typically not a blocking root check in this specific function logic unless added,
32
- // but usually prices are treated as auxiliary. If you want to block on prices, add it here.
33
31
  }
34
32
  return { canRun: missing.length === 0, missing };
35
33
  }
@@ -52,7 +50,6 @@ async function checkRootDataAvailability(dateStr, config, dependencies, earliest
52
50
 
53
51
  await Promise.all(tasks);
54
52
 
55
- // We allow running if ANY data is present. Specific calcs filter themselves using checkRootDependencies.
56
53
  if (!(hasPortfolio || hasInsights || hasSocial || hasHistory)) return null;
57
54
 
58
55
  return {
@@ -205,6 +202,9 @@ async function runStandardComputationPass(date, calcs, passName, config, deps, r
205
202
  const inst = new c.class();
206
203
  inst.manifest = c;
207
204
  state[normalizeName(c.name)] = inst;
205
+
206
+ // LOG: Explicitly say what calculation is being processed (Initialized)
207
+ logger.log('INFO', `${c.name} calculation running for ${dStr}`);
208
208
  }
209
209
  catch(e) {
210
210
  logger.log('WARN', `Failed to init ${c.name}`);
@@ -223,6 +223,9 @@ async function runMetaComputationPass(date, calcs, passName, config, deps, fetch
223
223
 
224
224
  for (const mCalc of calcs) {
225
225
  try {
226
+ // LOG: Explicitly say what calculation is being processed
227
+ deps.logger.log('INFO', `${mCalc.name} calculation running for ${dStr}`);
228
+
226
229
  const inst = new mCalc.class();
227
230
  inst.manifest = mCalc;
228
231
  await controller.executor.executeOncePerDay(inst, mCalc, dStr, fetchedDeps, previousFetchedDeps);
@@ -234,8 +237,8 @@ async function runMetaComputationPass(date, calcs, passName, config, deps, fetch
234
237
  }
235
238
 
236
239
  /**
237
- * --- FIXED: commitResults ---
238
- * Only marks 'successUpdates' if data is actually written.
240
+ * --- UPDATED: commitResults ---
241
+ * Includes Explicit Result Logging and Honest Status Reporting.
239
242
  */
240
243
  async function commitResults(stateObj, dStr, passName, config, deps, skipStatusWrite = false) {
241
244
  const writes = [], schemas = [], sharded = {};
@@ -245,10 +248,15 @@ async function commitResults(stateObj, dStr, passName, config, deps, skipStatusW
245
248
  const calc = stateObj[name];
246
249
  try {
247
250
  const result = await calc.getResult();
248
- if (!result) continue;
251
+
252
+ // If null/undefined, log as Failed/Unknown immediately
253
+ if (!result) {
254
+ deps.logger.log('INFO', `${name} calculation for ${dStr} ran, result : Failed (Empty Result)`);
255
+ continue;
256
+ }
249
257
 
250
258
  const standardRes = {};
251
- let hasData = false; // Track if this calc produced data
259
+ let hasData = false;
252
260
 
253
261
  for (const key in result) {
254
262
  if (key.startsWith('sharded_')) {
@@ -284,15 +292,19 @@ async function commitResults(stateObj, dStr, passName, config, deps, skipStatusW
284
292
  });
285
293
  }
286
294
 
287
- // FIX: Only mark as successful if we actually had data to write.
295
+ // --- EXPLICIT LOGGING & STATUS UPDATE ---
288
296
  if (hasData) {
289
297
  successUpdates[name] = true;
298
+ deps.logger.log('INFO', `${name} calculation for ${dStr} ran, result : Succeeded`);
290
299
  } else {
291
- // Optional: Log that it produced no data
292
- // deps.logger.log('INFO', `Calc ${name} produced no data. Skipping status update.`);
300
+ // It ran without error, but produced no content (e.g. no data met criteria)
301
+ deps.logger.log('INFO', `${name} calculation for ${dStr} ran, result : Unknown (No Data Written)`);
293
302
  }
294
303
 
295
- } catch (e) { deps.logger.log('ERROR', `Commit failed ${name}: ${e.message}`); }
304
+ } catch (e) {
305
+ deps.logger.log('ERROR', `Commit failed ${name}: ${e.message}`);
306
+ deps.logger.log('INFO', `${name} calculation for ${dStr} ran, result : Failed (Exception)`);
307
+ }
296
308
  }
297
309
 
298
310
  if (schemas.length) batchStoreSchemas(deps, config, schemas).catch(()=>{});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.183",
3
+ "version": "1.0.184",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [