aiden-shared-calculations-unified 1.0.33 → 1.0.35
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.
|
@@ -82,7 +82,7 @@ class AssetCrowdFlow {
|
|
|
82
82
|
async getResult() {
|
|
83
83
|
if (this.user_count === 0 || !this.dates.today) {
|
|
84
84
|
console.warn('[AssetCrowdFlow] No users processed or dates missing.');
|
|
85
|
-
return null; // <---
|
|
85
|
+
return null; // <--- Returns null if no users
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// Load priceMap and mappings if not loaded
|
|
@@ -95,18 +95,14 @@ class AssetCrowdFlow {
|
|
|
95
95
|
this.priceMap = priceData;
|
|
96
96
|
this.mappings = mappingData;
|
|
97
97
|
|
|
98
|
-
// --- START NEW CHECK ---
|
|
99
|
-
// If priceData failed to load (e.g., returned {} from provider)
|
|
100
|
-
// this.priceMap will be empty. We must abort.
|
|
101
98
|
if (!this.priceMap || Object.keys(this.priceMap).length === 0) {
|
|
102
99
|
console.error('[AssetCrowdFlow] CRITICAL: Price map is empty or failed to load. Aborting calculation to allow backfill.');
|
|
103
100
|
return null; // Return null to trigger backfill
|
|
104
101
|
}
|
|
105
|
-
// --- END NEW CHECK ---
|
|
106
102
|
|
|
107
103
|
} catch (err) {
|
|
108
104
|
console.error('[AssetCrowdFlow] Failed to load dependencies:', err);
|
|
109
|
-
return null; // <---
|
|
105
|
+
return null; // <--- Return null on error
|
|
110
106
|
}
|
|
111
107
|
}
|
|
112
108
|
|
|
@@ -121,29 +117,17 @@ class AssetCrowdFlow {
|
|
|
121
117
|
const avg_day1_value = this.asset_values[rawInstrumentId].day1_value_sum / this.user_count;
|
|
122
118
|
const avg_day2_value = this.asset_values[rawInstrumentId].day2_value_sum / this.user_count;
|
|
123
119
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
//
|
|
127
|
-
if (!this.priceMap || !this.priceMap[instrumentId]) {
|
|
128
|
-
console.debug(`[AssetCrowdFlow] Missing priceMap entry for instrumentId ${instrumentId} (${ticker})`);
|
|
129
|
-
} else {
|
|
130
|
-
const priceDay1 = this.priceMap[instrumentId][yesterdayStr];
|
|
131
|
-
const priceDay2 = this.priceMap[instrumentId][todayStr];
|
|
132
|
-
|
|
133
|
-
if (priceDay1 == null) console.debug(`[AssetCrowdFlow] Missing price for ${instrumentId} (${ticker}) on ${yesterdayStr}`);
|
|
134
|
-
if (priceDay2 == null) console.debug(`[AssetCrowdFlow] Missing price for ${instrumentId} (${ticker}) on ${todayStr}`);
|
|
135
|
-
|
|
136
|
-
if (priceDay1 != null && priceDay2 != null && priceDay1 > 0) {
|
|
137
|
-
priceChangePct = (priceDay2 - priceDay1) / priceDay1;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
120
|
+
// --- THIS IS THE FIX YOU APPLIED ---
|
|
121
|
+
const priceChangePct = getDailyPriceChange(instrumentId, yesterdayStr, todayStr, this.priceMap);
|
|
122
|
+
// --- END FIX ---
|
|
140
123
|
|
|
141
124
|
if (priceChangePct === null) {
|
|
142
|
-
//
|
|
143
|
-
//
|
|
125
|
+
// If price is missing, we simply skip this ticker.
|
|
126
|
+
// It will not be in the final output.
|
|
144
127
|
continue;
|
|
145
128
|
}
|
|
146
129
|
|
|
130
|
+
// --- THIS IS THE LOGIC THAT IS BROKEN IN YOUR FILE ---
|
|
147
131
|
// Calculate expected day2 value from price movement
|
|
148
132
|
const expected_day2_value = avg_day1_value * (1 + priceChangePct);
|
|
149
133
|
|
|
@@ -152,22 +136,19 @@ class AssetCrowdFlow {
|
|
|
152
136
|
|
|
153
137
|
finalResults[ticker] = {
|
|
154
138
|
net_crowd_flow_pct,
|
|
155
|
-
|
|
156
|
-
|
|
139
|
+
avg_value_day1_pct: avg_day1_value, // <-- Note: I've also fixed the key name here
|
|
140
|
+
avg_value_day2_pct: avg_day2_value, // <-- Note: I've also fixed the key name here
|
|
157
141
|
expected_day2_value,
|
|
158
142
|
price_change_pct: priceChangePct,
|
|
159
143
|
user_sample_size: this.user_count
|
|
160
144
|
};
|
|
145
|
+
// --- END BROKEN LOGIC ---
|
|
161
146
|
}
|
|
162
147
|
|
|
163
|
-
// --- START NEW CHECK ---
|
|
164
|
-
// If all tickers were skipped due to missing price data,
|
|
165
|
-
// finalResults will be empty. Return null to trigger backfill.
|
|
166
148
|
if (Object.keys(finalResults).length === 0) {
|
|
167
149
|
console.warn(`[AssetCrowdFlow] No results generated for ${this.dates.today}. This likely means all price data was missing. Returning null for backfill.`);
|
|
168
|
-
return null;
|
|
150
|
+
return null; // <--- Returns null if all tickers failed
|
|
169
151
|
}
|
|
170
|
-
// --- END NEW CHECK ---
|
|
171
152
|
|
|
172
153
|
return finalResults;
|
|
173
154
|
}
|