bulltrackers-module 1.0.672 → 1.0.674
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.
|
@@ -2049,14 +2049,13 @@ const fetchUserRecommendations = async (db, userId) => {
|
|
|
2049
2049
|
|
|
2050
2050
|
const fetchTrendingPopularInvestors = async (db) => {
|
|
2051
2051
|
// Path: /unified_insights/{DATE}/results/popular-investor/computations/TrendingPopularInvestors
|
|
2052
|
+
// Data exists in pointer document (small size, not compressed/sharded)
|
|
2053
|
+
// Look back up to 7 days if today's data doesn't exist
|
|
2052
2054
|
const today = new Date().toISOString().split('T')[0];
|
|
2053
|
-
|
|
2054
|
-
// Try today first, then look back up to 7 days
|
|
2055
2055
|
for (let i = 0; i < 7; i++) {
|
|
2056
2056
|
const checkDate = new Date(today);
|
|
2057
2057
|
checkDate.setDate(checkDate.getDate() - i);
|
|
2058
2058
|
const dateKey = checkDate.toISOString().split('T')[0];
|
|
2059
|
-
|
|
2060
2059
|
try {
|
|
2061
2060
|
const result = await getComputationResults(db, 'TrendingPopularInvestors', dateKey);
|
|
2062
2061
|
if (result && result.trending && Array.isArray(result.trending) && result.trending.length > 0) {
|
|
@@ -2069,19 +2068,17 @@ const fetchTrendingPopularInvestors = async (db) => {
|
|
|
2069
2068
|
}
|
|
2070
2069
|
}
|
|
2071
2070
|
}
|
|
2072
|
-
|
|
2073
2071
|
return [];
|
|
2074
2072
|
};
|
|
2075
2073
|
|
|
2076
2074
|
const fetchPopularInvestorCategories = async (db) => {
|
|
2075
|
+
// Data exists compressed in pointer document at /unified_insights/{DATE}/results/popular-investor/computations/PopularInvestorCategories
|
|
2076
|
+
// Look back up to 7 days if today's data doesn't exist
|
|
2077
2077
|
const today = new Date().toISOString().split('T')[0];
|
|
2078
|
-
|
|
2079
|
-
// Try today first, then look back up to 7 days
|
|
2080
2078
|
for (let i = 0; i < 7; i++) {
|
|
2081
2079
|
const checkDate = new Date(today);
|
|
2082
2080
|
checkDate.setDate(checkDate.getDate() - i);
|
|
2083
2081
|
const dateKey = checkDate.toISOString().split('T')[0];
|
|
2084
|
-
|
|
2085
2082
|
try {
|
|
2086
2083
|
const result = await getComputationResults(db, 'PopularInvestorCategories', dateKey);
|
|
2087
2084
|
if (result && result.categories && typeof result.categories === 'object' && Object.keys(result.categories).length > 0) {
|
|
@@ -2094,7 +2091,6 @@ const fetchPopularInvestorCategories = async (db) => {
|
|
|
2094
2091
|
}
|
|
2095
2092
|
}
|
|
2096
2093
|
}
|
|
2097
|
-
|
|
2098
2094
|
return {};
|
|
2099
2095
|
};
|
|
2100
2096
|
|
|
@@ -208,23 +208,56 @@ router.get('/computations', async (req, res) => {
|
|
|
208
208
|
// Fetch results for each computation
|
|
209
209
|
const results = {};
|
|
210
210
|
for (const compName of computationNames) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
211
|
+
let data = null;
|
|
212
|
+
let foundData = false;
|
|
213
|
+
|
|
214
|
+
// For RecommendedPopularInvestors in latest mode: Look back up to 7 days to find user's data
|
|
215
|
+
if (compName === 'RecommendedPopularInvestors' && mode === 'latest') {
|
|
216
|
+
const userCidStr = String(userId);
|
|
217
|
+
|
|
218
|
+
// Look back up to 7 days to find computation that contains this user's data
|
|
219
|
+
// Data structure: { [userId]: recommendations[] }
|
|
220
|
+
for (let i = 0; i < 7; i++) {
|
|
221
|
+
const checkDate = new Date(targetDate);
|
|
222
|
+
checkDate.setDate(checkDate.getDate() - i);
|
|
223
|
+
const dateKey = checkDate.toISOString().split('T')[0];
|
|
224
|
+
|
|
217
225
|
try {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
226
|
+
const checkData = await getComputationResults(db, compName, dateKey, userId);
|
|
227
|
+
if (checkData && typeof checkData === 'object' && checkData[userCidStr] && Array.isArray(checkData[userCidStr])) {
|
|
228
|
+
data = checkData;
|
|
229
|
+
foundData = true;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
223
232
|
} catch (e) {
|
|
233
|
+
// Continue to next date
|
|
234
|
+
if (i === 6) {
|
|
235
|
+
console.warn(`[Recommended] Failed to fetch after 7 day lookback: ${e.message}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
results[compName] = foundData ? data : null;
|
|
241
|
+
} else {
|
|
242
|
+
// For other computations: Try today, then look back if latest mode
|
|
243
|
+
try {
|
|
244
|
+
data = await getComputationResults(db, compName, targetDate, userId);
|
|
245
|
+
results[compName] = data;
|
|
246
|
+
} catch (error) {
|
|
247
|
+
// If latest mode and today fails, try yesterday
|
|
248
|
+
if (mode === 'latest') {
|
|
249
|
+
try {
|
|
250
|
+
const yesterday = new Date();
|
|
251
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
252
|
+
const yesterdayStr = yesterday.toISOString().split('T')[0];
|
|
253
|
+
data = await getComputationResults(db, compName, yesterdayStr, userId);
|
|
254
|
+
results[compName] = data;
|
|
255
|
+
} catch (e) {
|
|
256
|
+
results[compName] = null;
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
224
259
|
results[compName] = null;
|
|
225
260
|
}
|
|
226
|
-
} else {
|
|
227
|
-
results[compName] = null;
|
|
228
261
|
}
|
|
229
262
|
}
|
|
230
263
|
}
|