aiden-shared-calculations-unified 1.0.69 → 1.0.71
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.
|
@@ -79,6 +79,8 @@ class InLossAssetCrowdFlow {
|
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* Helper to get the cohort data from the dependency.
|
|
82
|
+
* --- MODIFIED ---
|
|
83
|
+
* Reads `data.users_in_loss` as a string array, not an object array.
|
|
82
84
|
*/
|
|
83
85
|
_getInLossCohorts(fetchedDependencies) {
|
|
84
86
|
if (this.inLossCohorts) {
|
|
@@ -94,7 +96,8 @@ class InLossAssetCrowdFlow {
|
|
|
94
96
|
// Map<ticker, Set<userId>>
|
|
95
97
|
this.inLossCohorts = new Map();
|
|
96
98
|
for (const [ticker, data] of Object.entries(pnlStatusData)) {
|
|
97
|
-
|
|
99
|
+
// `data.users_in_loss` is now a string[], so no .map() is needed.
|
|
100
|
+
const userSet = new Set(data.users_in_loss || []); // <-- MODIFIED
|
|
98
101
|
this.inLossCohorts.set(ticker, userSet);
|
|
99
102
|
}
|
|
100
103
|
return this.inLossCohorts;
|
|
@@ -79,6 +79,8 @@ class InProfitAssetCrowdFlow {
|
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* Helper to get the cohort data from the dependency.
|
|
82
|
+
* --- MODIFIED ---
|
|
83
|
+
* Reads `data.users_in_profit` as a string array, not an object array.
|
|
82
84
|
*/
|
|
83
85
|
_getInProfitCohorts(fetchedDependencies) {
|
|
84
86
|
if (this.inProfitCohorts) {
|
|
@@ -94,7 +96,8 @@ class InProfitAssetCrowdFlow {
|
|
|
94
96
|
// Map<ticker, Set<userId>>
|
|
95
97
|
this.inProfitCohorts = new Map();
|
|
96
98
|
for (const [ticker, data] of Object.entries(pnlStatusData)) {
|
|
97
|
-
|
|
99
|
+
// `data.users_in_profit` is now a string[], so no .map() is needed.
|
|
100
|
+
const userSet = new Set(data.users_in_profit || []); // <-- MODIFIED
|
|
98
101
|
this.inProfitCohorts.set(ticker, userSet);
|
|
99
102
|
}
|
|
100
103
|
return this.inProfitCohorts;
|
|
@@ -5,21 +5,32 @@
|
|
|
5
5
|
* sample are in profit versus in loss?"
|
|
6
6
|
*
|
|
7
7
|
* This provides a crowd-wide P&L status for each instrument.
|
|
8
|
+
*
|
|
9
|
+
* --- FIX ---
|
|
10
|
+
* This version is modified to only store user *IDs* in the arrays,
|
|
11
|
+
* not the full user P&L objects, to prevent exceeding the
|
|
12
|
+
* 1 MiB Firestore document size limit.
|
|
8
13
|
*/
|
|
9
14
|
const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
|
|
10
15
|
|
|
11
16
|
class AssetPnlStatus {
|
|
12
17
|
constructor() {
|
|
13
|
-
// We will store { [instrumentId]: { in_profit:
|
|
18
|
+
// We will store { [instrumentId]: { in_profit: Map(), in_loss: Map() } }
|
|
19
|
+
// The maps will store <userId, pnl> but only the keys (userIds) will be saved.
|
|
14
20
|
this.assets = new Map();
|
|
15
21
|
this.mappings = null;
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
/**
|
|
19
25
|
* Defines the output schema for this calculation.
|
|
26
|
+
* --- MODIFIED ---
|
|
27
|
+
* The `users_in_profit` and `users_in_loss` schemas are changed
|
|
28
|
+
* from `items: userSchema` to `items: { "type": "string" }`.
|
|
20
29
|
* @returns {object} JSON Schema object
|
|
21
30
|
*/
|
|
22
31
|
static getSchema() {
|
|
32
|
+
/*
|
|
33
|
+
// The userSchema is no longer needed in the output
|
|
23
34
|
const userSchema = {
|
|
24
35
|
"type": "object",
|
|
25
36
|
"properties": {
|
|
@@ -28,6 +39,7 @@ class AssetPnlStatus {
|
|
|
28
39
|
},
|
|
29
40
|
"required": ["userId", "pnl"]
|
|
30
41
|
};
|
|
42
|
+
*/
|
|
31
43
|
|
|
32
44
|
const tickerSchema = {
|
|
33
45
|
"type": "object",
|
|
@@ -47,13 +59,13 @@ class AssetPnlStatus {
|
|
|
47
59
|
},
|
|
48
60
|
"users_in_profit": {
|
|
49
61
|
"type": "array",
|
|
50
|
-
"description": "List of
|
|
51
|
-
"items":
|
|
62
|
+
"description": "List of user IDs in profit.",
|
|
63
|
+
"items": { "type": "string" } // <-- MODIFIED
|
|
52
64
|
},
|
|
53
65
|
"users_in_loss": {
|
|
54
66
|
"type": "array",
|
|
55
|
-
"description": "List of
|
|
56
|
-
"items":
|
|
67
|
+
"description": "List of user IDs in loss.",
|
|
68
|
+
"items": { "type": "string" } // <-- MODIFIED
|
|
57
69
|
}
|
|
58
70
|
},
|
|
59
71
|
"required": ["in_profit_count", "in_loss_count", "profit_ratio", "users_in_profit", "users_in_loss"]
|
|
@@ -100,6 +112,11 @@ class AssetPnlStatus {
|
|
|
100
112
|
}
|
|
101
113
|
}
|
|
102
114
|
|
|
115
|
+
/**
|
|
116
|
+
* --- MODIFIED ---
|
|
117
|
+
* This now saves an array of strings (user IDs) instead of
|
|
118
|
+
* an array of {userId, pnl} objects to save space.
|
|
119
|
+
*/
|
|
103
120
|
async getResult() {
|
|
104
121
|
if (!this.mappings) {
|
|
105
122
|
this.mappings = await loadInstrumentMappings();
|
|
@@ -118,9 +135,9 @@ class AssetPnlStatus {
|
|
|
118
135
|
in_profit_count: profitCount,
|
|
119
136
|
in_loss_count: lossCount,
|
|
120
137
|
profit_ratio: (profitCount / total) * 100,
|
|
121
|
-
// Convert Maps to arrays of
|
|
122
|
-
users_in_profit: Array.from(data.in_profit
|
|
123
|
-
users_in_loss: Array.from(data.in_loss
|
|
138
|
+
// Convert Maps to arrays of *keys* (user IDs)
|
|
139
|
+
users_in_profit: Array.from(data.in_profit.keys()), // <-- MODIFIED
|
|
140
|
+
users_in_loss: Array.from(data.in_loss.keys()) // <-- MODIFIED
|
|
124
141
|
};
|
|
125
142
|
}
|
|
126
143
|
}
|