bulltrackers-module 1.0.91 → 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,67 +1,95 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Computation system sub-pipes and utils.
|
|
3
3
|
* REFACTORED: Now stateless and receive dependencies where needed.
|
|
4
|
+
* DYNAMIC: Categorization logic is now an exported function.
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
const { FieldValue, FieldPath } = require('@google-cloud/firestore');
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
// ---
|
|
11
|
-
const HISTORICAL_CALC_NAMES = new Set([
|
|
12
|
-
'paper-vs-diamond-hands', 'smart-money-flow', 'profitability-migration',
|
|
13
|
-
'user-profitability-tracker', 'sector-rotation', 'crowd-conviction-score',
|
|
14
|
-
'risk-appetite-change', 'drawdown-response', 'gain-response',
|
|
15
|
-
'tsl-effectiveness', 'position-count-pnl', 'diversification-pnl',
|
|
16
|
-
|
|
17
|
-
'deposit-withdrawal-percentage',
|
|
18
|
-
'new-allocation-percentage',
|
|
19
|
-
'reallocation-increase-percentage',
|
|
20
|
-
'asset-crowd-flow'
|
|
21
|
-
]);
|
|
8
|
+
// --- REMOVED ---
|
|
9
|
+
// const { utils } = require('aiden-shared-calculations-unified');
|
|
10
|
+
// const { withRetry } = utils;
|
|
11
|
+
// --- END REMOVED ---
|
|
22
12
|
|
|
23
|
-
// --- Set for meta calculation names (Generated Dynamically) ---
|
|
24
|
-
const META_CALC_NAMES = new Set(); // This will be populated dynamically
|
|
25
13
|
|
|
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();
|
|
26
23
|
|
|
27
|
-
const historicalCalculations = {};
|
|
28
|
-
const dailyCalculations = {};
|
|
29
|
-
const metaCalculations = {};
|
|
24
|
+
const historicalCalculations = {};
|
|
25
|
+
const dailyCalculations = {};
|
|
26
|
+
const metaCalculations = {};
|
|
30
27
|
|
|
31
|
-
for (const category in calculations) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// --- UPDATED LOGIC ---
|
|
35
|
-
// 1. Check if it's a 'meta' calculation by its category
|
|
28
|
+
for (const category in calculations) {
|
|
29
|
+
// 1. Check for 'meta' category first (by top-level directory name)
|
|
36
30
|
if (category === 'meta') {
|
|
37
31
|
if (!metaCalculations[category]) metaCalculations[category] = {};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
32
|
+
for (const calcName in calculations[category]) {
|
|
33
|
+
const CalculationClass = calculations[category][calcName];
|
|
34
|
+
metaCalculations[category][calcName] = CalculationClass;
|
|
35
|
+
META_CALC_NAMES.add(calcName);
|
|
36
|
+
}
|
|
37
|
+
continue; // Done with this category
|
|
38
|
+
}
|
|
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
|
+
}
|
|
50
66
|
}
|
|
51
67
|
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
historicalCalculations,
|
|
71
|
+
dailyCalculations,
|
|
72
|
+
metaCalculations,
|
|
73
|
+
HISTORICAL_CALC_NAMES,
|
|
74
|
+
META_CALC_NAMES
|
|
75
|
+
};
|
|
52
76
|
}
|
|
53
|
-
// --- End Categorization ---
|
|
77
|
+
// --- End Dynamic Categorization ---
|
|
54
78
|
|
|
55
79
|
|
|
56
80
|
/**
|
|
57
81
|
* Sub-pipe: pipe.computationSystem.computationUtils.commitBatchInChunks
|
|
58
82
|
* @param {object} config - The computation system configuration object.
|
|
59
|
-
* @param {object} dependencies - Contains db, logger.
|
|
83
|
+
* @param {object} dependencies - Contains db, logger, calculationUtils.
|
|
60
84
|
* @param {Array<object>} writes - Array of { ref: DocumentReference, data: object }.
|
|
61
85
|
* @param {string} operationName - Name for logging.
|
|
62
86
|
*/
|
|
63
87
|
async function commitBatchInChunks(config, dependencies, writes, operationName) {
|
|
64
|
-
|
|
88
|
+
// --- MODIFIED: Get withRetry from dependencies ---
|
|
89
|
+
const { db, logger, calculationUtils } = dependencies;
|
|
90
|
+
const { withRetry } = calculationUtils;
|
|
91
|
+
// --- END MODIFIED ---
|
|
92
|
+
|
|
65
93
|
const batchSizeLimit = config.batchSizeLimit || 450;
|
|
66
94
|
|
|
67
95
|
if (writes.length === 0) {
|
|
@@ -128,7 +156,10 @@ async function processJobsInParallel(jobs, taskFunction, passName, config) {
|
|
|
128
156
|
* Internal helper: Finds the earliest date document in a collection.
|
|
129
157
|
*/
|
|
130
158
|
async function getFirstDateFromCollection(config, dependencies, collectionName) {
|
|
131
|
-
|
|
159
|
+
// --- MODIFIED: Get withRetry from dependencies ---
|
|
160
|
+
const { db, logger, calculationUtils } = dependencies;
|
|
161
|
+
const { withRetry } = calculationUtils;
|
|
162
|
+
// --- END MODIFIED ---
|
|
132
163
|
let earliestDate = null;
|
|
133
164
|
try {
|
|
134
165
|
const blockDocRefs = await withRetry(
|
|
@@ -169,7 +200,7 @@ async function getFirstDateFromCollection(config, dependencies, collectionName)
|
|
|
169
200
|
/**
|
|
170
201
|
* Sub-pipe: pipe.computationSystem.computationUtils.getFirstDateFromSourceData
|
|
171
202
|
* @param {object} config - The computation system configuration object.
|
|
172
|
-
* @param {object} dependencies - Contains db, logger.
|
|
203
|
+
* @param {object} dependencies - Contains db, logger, calculationUtils.
|
|
173
204
|
* @returns {Promise<Date>} The earliest date found or a default fallback date.
|
|
174
205
|
*/
|
|
175
206
|
async function getFirstDateFromSourceData(config, dependencies) {
|
|
@@ -199,9 +230,9 @@ async function getFirstDateFromSourceData(config, dependencies) {
|
|
|
199
230
|
|
|
200
231
|
module.exports = {
|
|
201
232
|
FieldValue, FieldPath,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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,
|
|
206
237
|
getExpectedDateStrings, processJobsInParallel, getFirstDateFromSourceData,
|
|
207
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",
|