bulltrackers-module 1.0.92 → 1.0.93
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.
|
@@ -17,22 +17,35 @@ const {
|
|
|
17
17
|
|
|
18
18
|
// --- MODIFIED: Import new meta calculation objects ---
|
|
19
19
|
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
withRetry,
|
|
20
|
+
categorizeCalculations, // <-- IMPORT THE NEW FUNCTION
|
|
21
|
+
// REMOVED: withRetry
|
|
23
22
|
getExpectedDateStrings, processJobsInParallel, getFirstDateFromSourceData,
|
|
24
|
-
commitBatchInChunks
|
|
23
|
+
commitBatchInChunks
|
|
24
|
+
// REMOVED: unifiedUtils
|
|
25
25
|
} = require('../utils/utils.js');
|
|
26
26
|
// --- END MODIFIED ---
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Main pipe: pipe.computationSystem.runOrchestration
|
|
30
30
|
* @param {object} config - The computation system configuration object.
|
|
31
|
-
* @param {object} dependencies - Contains db, logger.
|
|
31
|
+
* @param {object} dependencies - Contains db, logger, calculationUtils.
|
|
32
|
+
* @param {object} calculations - The injected calculations object from 'aiden-shared-calculations-unified'.
|
|
32
33
|
* @returns {Promise<Object>} Summary of all passes.
|
|
33
34
|
*/
|
|
34
|
-
async function runComputationOrchestrator(config, dependencies) {
|
|
35
|
-
const { logger, db } = dependencies; // Added db
|
|
35
|
+
async function runComputationOrchestrator(config, dependencies, calculations) { // <-- ADDED 'calculations'
|
|
36
|
+
const { logger, db, calculationUtils } = dependencies; // Added db and calculationUtils
|
|
37
|
+
const { withRetry } = calculationUtils; // <-- Get withRetry from injected utils
|
|
38
|
+
|
|
39
|
+
// --- NEW: Categorize the injected calculations ---
|
|
40
|
+
const {
|
|
41
|
+
historicalCalculations,
|
|
42
|
+
dailyCalculations,
|
|
43
|
+
metaCalculations,
|
|
44
|
+
HISTORICAL_CALC_NAMES,
|
|
45
|
+
META_CALC_NAMES
|
|
46
|
+
} = categorizeCalculations(calculations);
|
|
47
|
+
// --- END NEW ---
|
|
48
|
+
|
|
36
49
|
// --- MODIFIED: Add pass3_results to summary ---
|
|
37
50
|
const summary = { pass1_results: [], pass2_results: [], pass3_results: [] };
|
|
38
51
|
// --- END MODIFIED ---
|
|
@@ -46,9 +59,12 @@ async function runComputationOrchestrator(config, dependencies) {
|
|
|
46
59
|
const masterDailyList = Object.entries(dailyCalculations).flatMap(([cat, calcs]) =>
|
|
47
60
|
Object.keys(calcs).map(name => ({ category: cat, calcName: name }))
|
|
48
61
|
);
|
|
49
|
-
|
|
62
|
+
|
|
63
|
+
// --- MODIFIED: Use the injected 'calculations' object ---
|
|
64
|
+
const insightsCalculations = calculations.insights || {};
|
|
50
65
|
const masterInsightsList = Object.keys(insightsCalculations).map(name => ({ category: 'insights', calcName: name }));
|
|
51
|
-
const socialPostCalculations =
|
|
66
|
+
const socialPostCalculations = calculations.socialPosts || {};
|
|
67
|
+
// --- END MODIFIED ---
|
|
52
68
|
const masterSocialPostList = Object.keys(socialPostCalculations).map(name => ({ category: 'socialPosts', calcName: name }));
|
|
53
69
|
|
|
54
70
|
// --- NEW: Create master list for meta calcs ---
|
|
@@ -227,7 +243,7 @@ async function streamAndProcess(
|
|
|
227
243
|
todaySocialPostInsights = null,
|
|
228
244
|
yesterdaySocialPostInsights = null
|
|
229
245
|
) {
|
|
230
|
-
const { db, logger } = dependencies;
|
|
246
|
+
const { db, logger, calculationUtils } = dependencies; // <-- Get calculationUtils
|
|
231
247
|
logger.log('INFO', `[${passName}] Streaming ${todayRefs.length} 'today' part docs for ${dateStr}...`);
|
|
232
248
|
|
|
233
249
|
// Calculate yesterday's date string
|
|
@@ -235,7 +251,10 @@ async function streamAndProcess(
|
|
|
235
251
|
yesterdayDate.setUTCDate(yesterdayDate.getUTCDate() - 1);
|
|
236
252
|
const yesterdayStr = yesterdayDate.toISOString().slice(0, 10);
|
|
237
253
|
|
|
238
|
-
|
|
254
|
+
// --- MODIFIED: Get mapping functions from injected utils ---
|
|
255
|
+
const { instrumentToTicker, instrumentToSector } = await calculationUtils.loadInstrumentMappings();
|
|
256
|
+
// --- END MODIFIED ---
|
|
257
|
+
|
|
239
258
|
// Add date strings to the context
|
|
240
259
|
const context = {
|
|
241
260
|
instrumentMappings: instrumentToTicker,
|
|
@@ -1,62 +1,78 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Computation system sub-pipes and utils.
|
|
3
3
|
* REFACTORED: Now stateless and receive dependencies where needed.
|
|
4
|
-
* DYNAMIC:
|
|
4
|
+
* DYNAMIC: Categorization logic is now an exported function.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const { FieldValue, FieldPath } = require('@google-cloud/firestore');
|
|
8
|
-
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
// ---
|
|
12
|
-
|
|
13
|
-
// These sets will be populated dynamically by inspecting the file structure
|
|
14
|
-
const HISTORICAL_CALC_NAMES = new Set();
|
|
15
|
-
const META_CALC_NAMES = new Set();
|
|
16
|
-
|
|
17
|
-
const historicalCalculations = {};
|
|
18
|
-
const dailyCalculations = {};
|
|
19
|
-
const metaCalculations = {};
|
|
20
|
-
|
|
21
|
-
for (const category in calculations) {
|
|
22
|
-
// 1. Check for 'meta' category first (by top-level directory name)
|
|
23
|
-
if (category === 'meta') {
|
|
24
|
-
if (!metaCalculations[category]) metaCalculations[category] = {};
|
|
25
|
-
for (const calcName in calculations[category]) {
|
|
26
|
-
const CalculationClass = calculations[category][calcName];
|
|
27
|
-
metaCalculations[category][calcName] = CalculationClass;
|
|
28
|
-
META_CALC_NAMES.add(calcName);
|
|
29
|
-
}
|
|
30
|
-
continue; // Done with this category
|
|
31
|
-
}
|
|
8
|
+
// --- REMOVED ---
|
|
9
|
+
// const { utils } = require('aiden-shared-calculations-unified');
|
|
10
|
+
// const { withRetry } = utils;
|
|
11
|
+
// --- END REMOVED ---
|
|
12
|
+
|
|
32
13
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
14
|
+
/**
|
|
15
|
+
* NEW FUNCTION: This logic is now wrapped and exported.
|
|
16
|
+
* It receives the 'calculations' object from the entry point.
|
|
17
|
+
* @param {object} calculations - The full calculations object from the 'aiden-shared-calculations-unified' package.
|
|
18
|
+
* @returns {object} An object containing categorized calculations and name sets.
|
|
19
|
+
*/
|
|
20
|
+
function categorizeCalculations(calculations) {
|
|
21
|
+
const HISTORICAL_CALC_NAMES = new Set();
|
|
22
|
+
const META_CALC_NAMES = new Set();
|
|
23
|
+
|
|
24
|
+
const historicalCalculations = {};
|
|
25
|
+
const dailyCalculations = {};
|
|
26
|
+
const metaCalculations = {};
|
|
27
|
+
|
|
28
|
+
for (const category in calculations) {
|
|
29
|
+
// 1. Check for 'meta' category first (by top-level directory name)
|
|
30
|
+
if (category === 'meta') {
|
|
31
|
+
if (!metaCalculations[category]) metaCalculations[category] = {};
|
|
32
|
+
for (const calcName in calculations[category]) {
|
|
33
|
+
const CalculationClass = calculations[category][calcName];
|
|
34
|
+
metaCalculations[category][calcName] = CalculationClass;
|
|
35
|
+
META_CALC_NAMES.add(calcName);
|
|
48
36
|
}
|
|
37
|
+
continue; // Done with this category
|
|
49
38
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!
|
|
57
|
-
|
|
39
|
+
|
|
40
|
+
// 2. Process other categories (e.g., 'pnl', 'capital_flow')
|
|
41
|
+
for (const subKey in calculations[category]) {
|
|
42
|
+
const item = calculations[category][subKey];
|
|
43
|
+
|
|
44
|
+
// Check if the key is 'historical' and it contains an object of calculations
|
|
45
|
+
if (subKey === 'historical' && typeof item === 'object' && item !== null && !Array.isArray(item)) {
|
|
46
|
+
// This is the historical subdirectory, e.g., calculations.capital_flow.historical
|
|
47
|
+
|
|
48
|
+
if (!historicalCalculations[category]) historicalCalculations[category] = {};
|
|
49
|
+
|
|
50
|
+
for (const calcName in item) {
|
|
51
|
+
const CalculationClass = item[calcName];
|
|
52
|
+
// Add it to the historical list, using the parent 'category'
|
|
53
|
+
historicalCalculations[category][calcName] = CalculationClass;
|
|
54
|
+
HISTORICAL_CALC_NAMES.add(calcName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Check if the item is a function (a standard daily calc at the root of the category)
|
|
58
|
+
else if (typeof item === 'function') {
|
|
59
|
+
// This is a standard daily calc, e.g., calculations.pnl.average-daily-pnl
|
|
60
|
+
const calcName = subKey;
|
|
61
|
+
const CalculationClass = item;
|
|
62
|
+
|
|
63
|
+
if (!dailyCalculations[category]) dailyCalculations[category] = {};
|
|
64
|
+
dailyCalculations[category][calcName] = CalculationClass;
|
|
65
|
+
}
|
|
58
66
|
}
|
|
59
67
|
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
historicalCalculations,
|
|
71
|
+
dailyCalculations,
|
|
72
|
+
metaCalculations,
|
|
73
|
+
HISTORICAL_CALC_NAMES,
|
|
74
|
+
META_CALC_NAMES
|
|
75
|
+
};
|
|
60
76
|
}
|
|
61
77
|
// --- End Dynamic Categorization ---
|
|
62
78
|
|
|
@@ -64,12 +80,16 @@ for (const category in calculations) {
|
|
|
64
80
|
/**
|
|
65
81
|
* Sub-pipe: pipe.computationSystem.computationUtils.commitBatchInChunks
|
|
66
82
|
* @param {object} config - The computation system configuration object.
|
|
67
|
-
* @param {object} dependencies - Contains db, logger.
|
|
83
|
+
* @param {object} dependencies - Contains db, logger, calculationUtils.
|
|
68
84
|
* @param {Array<object>} writes - Array of { ref: DocumentReference, data: object }.
|
|
69
85
|
* @param {string} operationName - Name for logging.
|
|
70
86
|
*/
|
|
71
87
|
async function commitBatchInChunks(config, dependencies, writes, operationName) {
|
|
72
|
-
|
|
88
|
+
// --- MODIFIED: Get withRetry from dependencies ---
|
|
89
|
+
const { db, logger, calculationUtils } = dependencies;
|
|
90
|
+
const { withRetry } = calculationUtils;
|
|
91
|
+
// --- END MODIFIED ---
|
|
92
|
+
|
|
73
93
|
const batchSizeLimit = config.batchSizeLimit || 450;
|
|
74
94
|
|
|
75
95
|
if (writes.length === 0) {
|
|
@@ -136,7 +156,10 @@ async function processJobsInParallel(jobs, taskFunction, passName, config) {
|
|
|
136
156
|
* Internal helper: Finds the earliest date document in a collection.
|
|
137
157
|
*/
|
|
138
158
|
async function getFirstDateFromCollection(config, dependencies, collectionName) {
|
|
139
|
-
|
|
159
|
+
// --- MODIFIED: Get withRetry from dependencies ---
|
|
160
|
+
const { db, logger, calculationUtils } = dependencies;
|
|
161
|
+
const { withRetry } = calculationUtils;
|
|
162
|
+
// --- END MODIFIED ---
|
|
140
163
|
let earliestDate = null;
|
|
141
164
|
try {
|
|
142
165
|
const blockDocRefs = await withRetry(
|
|
@@ -177,7 +200,7 @@ async function getFirstDateFromCollection(config, dependencies, collectionName)
|
|
|
177
200
|
/**
|
|
178
201
|
* Sub-pipe: pipe.computationSystem.computationUtils.getFirstDateFromSourceData
|
|
179
202
|
* @param {object} config - The computation system configuration object.
|
|
180
|
-
* @param {object} dependencies - Contains db, logger.
|
|
203
|
+
* @param {object} dependencies - Contains db, logger, calculationUtils.
|
|
181
204
|
* @returns {Promise<Date>} The earliest date found or a default fallback date.
|
|
182
205
|
*/
|
|
183
206
|
async function getFirstDateFromSourceData(config, dependencies) {
|
|
@@ -207,9 +230,9 @@ async function getFirstDateFromSourceData(config, dependencies) {
|
|
|
207
230
|
|
|
208
231
|
module.exports = {
|
|
209
232
|
FieldValue, FieldPath,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
233
|
+
// unifiedUtils: utils, // This is no longer defined here
|
|
234
|
+
categorizeCalculations, // EXPORT THE NEW FUNCTION
|
|
235
|
+
// withRetry, // This is no longer defined here
|
|
236
|
+
commitBatchInChunks,
|
|
214
237
|
getExpectedDateStrings, processJobsInParallel, getFirstDateFromSourceData,
|
|
215
238
|
};
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const { FieldValue } = require('@google-cloud/firestore');
|
|
8
|
-
//
|
|
9
|
-
const { loadInstrumentMappings } = require('aiden-shared-calculations-unified').utils;
|
|
8
|
+
// --- REMOVED ---
|
|
9
|
+
// const { loadInstrumentMappings } = require('aiden-shared-calculations-unified').utils;
|
|
10
|
+
// --- END REMOVED ---
|
|
10
11
|
const pLimit = require('p-limit');
|
|
11
12
|
|
|
12
13
|
// How many tickers to fetch in parallel
|
|
@@ -19,16 +20,21 @@ const SHARD_SIZE = 40;
|
|
|
19
20
|
/**
|
|
20
21
|
* Main pipe: pipe.maintenance.runBackfillAssetPrices
|
|
21
22
|
* @param {object} config - Configuration object.
|
|
22
|
-
* @param {object} dependencies - Contains db, logger, headerManager, proxyManager.
|
|
23
|
+
* @param {object} dependencies - Contains db, logger, headerManager, proxyManager, calculationUtils.
|
|
23
24
|
*/
|
|
25
|
+
// --- MODIFIED: Removed calculationUtils, as it's in dependencies ---
|
|
24
26
|
exports.runBackfillAssetPrices = async (config, dependencies) => {
|
|
25
|
-
const { db, logger, headerManager, proxyManager } = dependencies;
|
|
27
|
+
const { db, logger, headerManager, proxyManager, calculationUtils } = dependencies;
|
|
28
|
+
const { loadInstrumentMappings } = calculationUtils; // <-- Get function from dependencies
|
|
29
|
+
// --- END MODIFIED ---
|
|
26
30
|
|
|
27
31
|
logger.log('INFO', '[PriceBackfill] Starting historical price backfill...');
|
|
28
32
|
|
|
29
33
|
let mappings;
|
|
30
34
|
try {
|
|
35
|
+
// --- MODIFIED: Use the injected utils ---
|
|
31
36
|
mappings = await loadInstrumentMappings();
|
|
37
|
+
// --- END MODIFIED ---
|
|
32
38
|
if (!mappings || !mappings.instrumentToTicker) {
|
|
33
39
|
throw new Error("Failed to load instrument mappings.");
|
|
34
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bulltrackers-module",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.93",
|
|
4
4
|
"description": "Helper Functions for Bulltrackers.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -32,7 +32,6 @@
|
|
|
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.16",
|
|
36
35
|
"@google-cloud/pubsub": "latest",
|
|
37
36
|
"express": "^4.19.2",
|
|
38
37
|
"cors": "^2.8.5",
|