bulltrackers-module 1.0.88 → 1.0.90

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.
@@ -78,7 +78,6 @@ async function runComputationOrchestrator(config, dependencies) {
78
78
  const existingDateIds = new Set(insightDocs.docs.map(d => d.id).filter(id => /^\d{4}-\d{2}-\d{2}$/.test(id)));
79
79
 
80
80
  // --- PASS 1 ---
81
- // (Existing Pass 1 code ... no changes here)
82
81
  const missingDates = allExpectedDates.filter(dateStr => !existingDateIds.has(dateStr));
83
82
  const pass1Jobs = missingDates.map(date => ({
84
83
  date,
@@ -100,7 +99,6 @@ async function runComputationOrchestrator(config, dependencies) {
100
99
 
101
100
 
102
101
  // --- PASS 2 ---
103
- // (Existing Pass 2 code ... no changes here)
104
102
  const pass2Jobs = [];
105
103
  const updatedInsightDocs = await withRetry(() => dependencies.db.collection(config.resultsCollection).get(), "ListAllInsightDocs-Pass2");
106
104
  updatedInsightDocs.forEach(doc => {
@@ -199,7 +197,6 @@ async function runComputationOrchestrator(config, dependencies) {
199
197
  * Internal sub-pipe: Initializes calculator instances.
200
198
  */
201
199
  function initializeCalculators(calculationsToRun, sourcePackage, logger) {
202
- // ... (existing code unchanged) ...
203
200
  const state = {};
204
201
  for (const { category, calcName } of calculationsToRun) {
205
202
  const CalculationClass = sourcePackage[category]?.[calcName];
@@ -230,7 +227,6 @@ async function streamAndProcess(
230
227
  todaySocialPostInsights = null,
231
228
  yesterdaySocialPostInsights = null
232
229
  ) {
233
- // ... (existing code unchanged) ...
234
230
  const { db, logger } = dependencies;
235
231
  logger.log('INFO', `[${passName}] Streaming ${todayRefs.length} 'today' part docs for ${dateStr}...`);
236
232
 
@@ -341,10 +337,8 @@ async function streamAndProcess(
341
337
 
342
338
  /**
343
339
  * Internal sub-pipe: Runs computations for a single date.
344
- * (Existing code ... no changes here)
345
340
  */
346
341
  async function runUnifiedComputation(dateToProcess, calculationsToRun, passName, sourcePackage, config, dependencies) {
347
- // ... (existing code unchanged) ...
348
342
  const { db, logger } = dependencies;
349
343
  const dateStr = dateToProcess.toISOString().slice(0, 10);
350
344
  logger.log('INFO', `[${passName}] Starting run for ${dateStr} with ${calculationsToRun.length} calcs.`);
@@ -364,7 +358,7 @@ async function runUnifiedComputation(dateToProcess, calculationsToRun, passName,
364
358
  let yesterdayInsightsData = null;
365
359
  let yesterdaySocialPostInsightsData = null;
366
360
 
367
- const requiresYesterdayPortfolio = calculationsToRun.some(c => sourcePackage[c.category]?.[c.calcName]?.prototype?.process.length >= 3);
361
+ const requiresYesterdayPortfolio = calculationsToRun.some(c => HISTORICAL_CALC_NAMES.has(c.calcName)); // Use historical cals to determine need FIX from const requiresYesterdayPortfolio = calculationsToRun.some(c => sourcePackage[c.category]?.[c.calcName]?.prototype?.process.length >= 3);
368
362
  const requiresYesterdayInsights = calculationsToRun.some(c => c.category === 'insights');
369
363
  const requiresYesterdaySocialPosts = calculationsToRun.some(c => c.category === 'socialPosts');
370
364
 
@@ -13,7 +13,6 @@ const { FieldPath } = require('@google-cloud/firestore'); // <<< --- ADD FieldPa
13
13
  * @returns {Promise<Firestore.DocumentReference[]>} An array of DocumentReferences.
14
14
  */
15
15
  async function getPortfolioPartRefs(config, dependencies, dateString) {
16
- // ... (existing code unchanged) ...
17
16
  const { db, logger } = dependencies;
18
17
  logger.log('INFO', `Getting portfolio part references for date: ${dateString}`);
19
18
  const allPartRefs = [];
@@ -53,7 +52,6 @@ async function getPortfolioPartRefs(config, dependencies, dateString) {
53
52
  * @returns {Promise<object>} A single map of { [userId]: portfolioData }.
54
53
  */
55
54
  async function loadDataByRefs(config, dependencies, refs) {
56
- // ... (existing code unchanged) ...
57
55
  const { db, logger } = dependencies;
58
56
  if (!refs || refs.length === 0) { return {}; }
59
57
  const mergedPortfolios = {};
@@ -88,7 +86,6 @@ async function loadDataByRefs(config, dependencies, refs) {
88
86
  * @returns {Promise<object>} A single map of { [userId]: portfolioData }.
89
87
  */
90
88
  async function loadFullDayMap(config, dependencies, partRefs) {
91
- // ... (existing code unchanged) ...
92
89
  const { logger } = dependencies;
93
90
  if (partRefs.length === 0) return {};
94
91
  logger.log('TRACE', `Loading full day map from ${partRefs.length} references...`);
@@ -100,7 +97,6 @@ async function loadFullDayMap(config, dependencies, partRefs) {
100
97
  }
101
98
 
102
99
  /**
103
- * --- (EXISTING) ---
104
100
  * Sub-pipe: pipe.computationSystem.dataLoader.loadDailyInsights
105
101
  * Fetches the daily instrument insights document for a specific date.
106
102
  * @param {object} config - The computation system configuration object.
@@ -173,5 +169,5 @@ module.exports = {
173
169
  loadDataByRefs,
174
170
  loadFullDayMap,
175
171
  loadDailyInsights,
176
- loadDailySocialPostInsights, // Export the new function
172
+ loadDailySocialPostInsights,
177
173
  };
@@ -20,24 +20,30 @@ const HISTORICAL_CALC_NAMES = new Set([
20
20
  'asset-crowd-flow'
21
21
  ]);
22
22
 
23
- // --- NEW: Add a set for meta calculation names ---
24
- const META_CALC_NAMES = new Set([
25
- 'cash-flow-deployment'
26
- ]);
27
- // --- END NEW ---
23
+ // --- Set for meta calculation names (Generated Dynamically) ---
24
+ const META_CALC_NAMES = new Set(); // This will be populated dynamically
25
+
28
26
 
29
27
  const historicalCalculations = {};
30
28
  const dailyCalculations = {};
31
- const metaCalculations = {}; // <-- NEW: Add object for meta calcs
29
+ const metaCalculations = {};
32
30
 
33
31
  for (const category in calculations) {
34
32
  for (const calcName in calculations[category]) {
35
- if (HISTORICAL_CALC_NAMES.has(calcName)) {
36
- if (!historicalCalculations[category]) historicalCalculations[category] = {};
37
- historicalCalculations[category][calcName] = calculations[category][calcName];
38
- } else if (META_CALC_NAMES.has(calcName)) { // <-- NEW: Add else-if block
33
+
34
+ // --- UPDATED LOGIC ---
35
+ // 1. Check if it's a 'meta' calculation by its category
36
+ if (category === 'meta') {
39
37
  if (!metaCalculations[category]) metaCalculations[category] = {};
40
38
  metaCalculations[category][calcName] = calculations[category][calcName];
39
+ META_CALC_NAMES.add(calcName); // Add to the set for export
40
+
41
+ // 2. Check if it's a historical calculation
42
+ } else if (HISTORICAL_CALC_NAMES.has(calcName)) {
43
+ if (!historicalCalculations[category]) historicalCalculations[category] = {};
44
+ historicalCalculations[category][calcName] = calculations[category][calcName];
45
+
46
+ // 3. Otherwise, it's a standard daily calculation
41
47
  } else {
42
48
  if (!dailyCalculations[category]) dailyCalculations[category] = {};
43
49
  dailyCalculations[category][calcName] = calculations[category][calcName];
@@ -55,7 +61,6 @@ for (const category in calculations) {
55
61
  * @param {string} operationName - Name for logging.
56
62
  */
57
63
  async function commitBatchInChunks(config, dependencies, writes, operationName) {
58
- // ... (existing code unchanged) ...
59
64
  const { db, logger } = dependencies;
60
65
  const batchSizeLimit = config.batchSizeLimit || 450;
61
66
 
@@ -83,7 +88,6 @@ async function commitBatchInChunks(config, dependencies, writes, operationName)
83
88
  * (Stateless)
84
89
  */
85
90
  function getExpectedDateStrings(startDate, endDate) {
86
- // ... (existing code unchanged) ...
87
91
  const dateStrings = [];
88
92
  if (startDate <= endDate) {
89
93
  const startUTC = new Date(Date.UTC(startDate.getUTCFullYear(), startDate.getUTCMonth(), startDate.getUTCDate()));
@@ -101,7 +105,6 @@ function getExpectedDateStrings(startDate, endDate) {
101
105
  * (Stateless, as taskFunction will receive dependencies)
102
106
  */
103
107
  async function processJobsInParallel(jobs, taskFunction, passName, config) {
104
- // ... (existing code unchanged) ...
105
108
  // This function itself doesn't need dependencies,
106
109
  // but the 'taskFunction' it calls *will* receive them from its caller.
107
110
  const { logger } = require("sharedsetup")(__filename); // Use local logger for this static util
@@ -125,7 +128,6 @@ async function processJobsInParallel(jobs, taskFunction, passName, config) {
125
128
  * Internal helper: Finds the earliest date document in a collection.
126
129
  */
127
130
  async function getFirstDateFromCollection(config, dependencies, collectionName) {
128
- // ... (existing code unchanged) ...
129
131
  const { db, logger } = dependencies;
130
132
  let earliestDate = null;
131
133
  try {
@@ -171,7 +173,6 @@ async function getFirstDateFromCollection(config, dependencies, collectionName)
171
173
  * @returns {Promise<Date>} The earliest date found or a default fallback date.
172
174
  */
173
175
  async function getFirstDateFromSourceData(config, dependencies) {
174
- // ... (existing code unchanged) ...
175
176
  const { logger } = dependencies;
176
177
  logger.log('INFO', 'Querying for the earliest date from source portfolio data...');
177
178
 
@@ -198,11 +199,9 @@ async function getFirstDateFromSourceData(config, dependencies) {
198
199
 
199
200
  module.exports = {
200
201
  FieldValue, FieldPath,
201
- // --- MODIFIED: Export meta calculations ---
202
202
  historicalCalculations, dailyCalculations, metaCalculations,
203
203
  unifiedUtils: utils,
204
204
  HISTORICAL_CALC_NAMES, META_CALC_NAMES,
205
- // --- END MODIFIED ---
206
205
  withRetry, commitBatchInChunks,
207
206
  getExpectedDateStrings, processJobsInParallel, getFirstDateFromSourceData,
208
207
  };
package/index.js CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  // --- Core Utilities (Classes and Stateless Helpers) ---
8
- // ... (no changes here) ...
8
+
9
9
  const core = {
10
10
  IntelligentHeaderManager: require('./functions/core/utils/intelligent_header_manager').IntelligentHeaderManager,
11
11
  IntelligentProxyManager: require('./functions/core/utils/intelligent_proxy_manager').IntelligentProxyManager,
@@ -15,7 +15,7 @@ const core = {
15
15
  };
16
16
 
17
17
  // --- Pipe 1: Orchestrator ---
18
- // ... (no changes here) ...
18
+
19
19
  const orchestrator = {
20
20
  // Main Pipes (Entry points for Cloud Functions)
21
21
  runDiscoveryOrchestrator: require('./functions/orchestrator/index').runDiscoveryOrchestrator,
@@ -32,7 +32,7 @@ const orchestrator = {
32
32
  };
33
33
 
34
34
  // --- Pipe 2: Dispatcher ---
35
- // ... (no changes here) ...
35
+
36
36
  const dispatcher = {
37
37
  // Main Pipe
38
38
  handleRequest: require('./functions/dispatcher/index').handleRequest,
@@ -42,7 +42,7 @@ const dispatcher = {
42
42
  };
43
43
 
44
44
  // --- Pipe 3: Task Engine ---
45
- // ... (no changes here) ...
45
+
46
46
  const taskEngine = {
47
47
  // Main Pipe
48
48
  handleRequest: require('./functions/task-engine/handler_creator').handleRequest,
@@ -54,7 +54,6 @@ const taskEngine = {
54
54
  };
55
55
 
56
56
  // --- Pipe 4: Computation System ---
57
- // ... (no changes here) ...
58
57
  const computationSystem = {
59
58
  // Main Pipe
60
59
  runOrchestration: require('./functions/computation-system/helpers/orchestration_helpers').runComputationOrchestrator,
@@ -65,7 +64,7 @@ const computationSystem = {
65
64
  };
66
65
 
67
66
  // --- Pipe 5: API ---
68
- // ... (no changes here) ...
67
+
69
68
  const api = {
70
69
  // Main Pipe
71
70
  createApiApp: require('./functions/generic-api/index').createApiApp,
@@ -75,27 +74,21 @@ const api = {
75
74
  };
76
75
 
77
76
  // --- Pipe 6: Maintenance ---
78
- // Standalone cleanup and utility functions
77
+ // Standalone cleanup and utility functions TODO -- Some of these are not really maintenance pipes, socials could do with its own pipe..?
79
78
  const maintenance = {
80
79
  runSpeculatorCleanup: require('./functions/speculator-cleanup-orchestrator/helpers/cleanup_helpers').runCleanup,
81
80
  handleInvalidSpeculator: require('./functions/invalid-speculator-handler/helpers/handler_helpers').handleInvalidSpeculator,
82
81
  runFetchInsights: require('./functions/fetch-insights/helpers/handler_helpers').fetchAndStoreInsights,
83
82
  runFetchPrices: require('./functions/etoro-price-fetcher/helpers/handler_helpers').fetchAndStorePrices,
84
-
85
- // --- UPDATED ---
86
83
  runUserActivitySamplerOrchestrator: require('./functions/user-activity-sampler/helpers/sampler_helpers').runUserActivitySamplerOrchestrator,
87
84
  handleSampleBlockTask: require('./functions/user-activity-sampler/helpers/sampler_helpers').handleSampleBlockTask,
88
- // --- END UPDATE ---
89
-
90
- // --- NEW SOCIAL SENTIMENT FUNCTIONS ---
91
85
  runSocialOrchestrator: require('./functions/social-orchestrator/helpers/orchestrator_helpers').runSocialOrchestrator,
92
86
  handleSocialTask: require('./functions/social-task-handler/helpers/handler_helpers').handleSocialTask,
93
87
  runBackfillAssetPrices: require('./functions/price-backfill/helpers/handler_helpers').runBackfillAssetPrices,
94
- // --- END NEW ---
95
88
  };
96
89
 
97
90
  // --- Pipe 7: Proxy ---
98
- // ... (no changes here) ...
91
+
99
92
  const proxy = {
100
93
  handlePost: require('./functions/appscript-api/index').handlePost,
101
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.88",
3
+ "version": "1.0.90",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -32,7 +32,7 @@
32
32
  "@google-cloud/firestore": "^7.11.3",
33
33
  "sharedsetup": "latest",
34
34
  "require-all": "^3.0.0",
35
- "aiden-shared-calculations-unified": "1.0.13",
35
+ "aiden-shared-calculations-unified": "1.0.15",
36
36
  "@google-cloud/pubsub": "latest",
37
37
  "express": "^4.19.2",
38
38
  "cors": "^2.8.5",