bulltrackers-module 1.0.733 → 1.0.734
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.
- package/functions/computation-system-v2/README.md +152 -0
- package/functions/computation-system-v2/computations/PopularInvestorProfileMetrics.js +720 -0
- package/functions/computation-system-v2/computations/PopularInvestorRiskAssessment.js +176 -0
- package/functions/computation-system-v2/computations/PopularInvestorRiskMetrics.js +294 -0
- package/functions/computation-system-v2/computations/TestComputation.js +46 -0
- package/functions/computation-system-v2/computations/UserPortfolioSummary.js +172 -0
- package/functions/computation-system-v2/config/bulltrackers.config.js +317 -0
- package/functions/computation-system-v2/framework/core/Computation.js +73 -0
- package/functions/computation-system-v2/framework/core/Manifest.js +223 -0
- package/functions/computation-system-v2/framework/core/RuleInjector.js +53 -0
- package/functions/computation-system-v2/framework/core/Rules.js +231 -0
- package/functions/computation-system-v2/framework/core/RunAnalyzer.js +163 -0
- package/functions/computation-system-v2/framework/cost/CostTracker.js +154 -0
- package/functions/computation-system-v2/framework/data/DataFetcher.js +399 -0
- package/functions/computation-system-v2/framework/data/QueryBuilder.js +232 -0
- package/functions/computation-system-v2/framework/data/SchemaRegistry.js +287 -0
- package/functions/computation-system-v2/framework/execution/Orchestrator.js +498 -0
- package/functions/computation-system-v2/framework/execution/TaskRunner.js +35 -0
- package/functions/computation-system-v2/framework/execution/middleware/CostTrackerMiddleware.js +32 -0
- package/functions/computation-system-v2/framework/execution/middleware/LineageMiddleware.js +32 -0
- package/functions/computation-system-v2/framework/execution/middleware/Middleware.js +14 -0
- package/functions/computation-system-v2/framework/execution/middleware/ProfilerMiddleware.js +47 -0
- package/functions/computation-system-v2/framework/index.js +45 -0
- package/functions/computation-system-v2/framework/lineage/LineageTracker.js +147 -0
- package/functions/computation-system-v2/framework/monitoring/Profiler.js +80 -0
- package/functions/computation-system-v2/framework/resilience/Checkpointer.js +66 -0
- package/functions/computation-system-v2/framework/scheduling/ScheduleValidator.js +327 -0
- package/functions/computation-system-v2/framework/storage/StateRepository.js +286 -0
- package/functions/computation-system-v2/framework/storage/StorageManager.js +469 -0
- package/functions/computation-system-v2/framework/storage/index.js +9 -0
- package/functions/computation-system-v2/framework/testing/ComputationTester.js +86 -0
- package/functions/computation-system-v2/framework/utils/Graph.js +205 -0
- package/functions/computation-system-v2/handlers/dispatcher.js +109 -0
- package/functions/computation-system-v2/handlers/index.js +23 -0
- package/functions/computation-system-v2/handlers/onDemand.js +289 -0
- package/functions/computation-system-v2/handlers/scheduler.js +327 -0
- package/functions/computation-system-v2/index.js +163 -0
- package/functions/computation-system-v2/rules/index.js +49 -0
- package/functions/computation-system-v2/rules/instruments.js +465 -0
- package/functions/computation-system-v2/rules/metrics.js +304 -0
- package/functions/computation-system-v2/rules/portfolio.js +534 -0
- package/functions/computation-system-v2/rules/rankings.js +655 -0
- package/functions/computation-system-v2/rules/social.js +562 -0
- package/functions/computation-system-v2/rules/trades.js +545 -0
- package/functions/computation-system-v2/scripts/migrate-sectors.js +73 -0
- package/functions/computation-system-v2/test/test-dispatcher.js +317 -0
- package/functions/computation-system-v2/test/test-framework.js +500 -0
- package/functions/computation-system-v2/test/test-real-execution.js +166 -0
- package/functions/computation-system-v2/test/test-real-integration.js +194 -0
- package/functions/computation-system-v2/test/test-refactor-e2e.js +131 -0
- package/functions/computation-system-v2/test/test-results.json +31 -0
- package/functions/computation-system-v2/test/test-risk-metrics-computation.js +329 -0
- package/functions/computation-system-v2/test/test-scheduler.js +204 -0
- package/functions/computation-system-v2/test/test-storage.js +449 -0
- package/functions/orchestrator/index.js +18 -26
- package/package.json +3 -2
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Computation System v2
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
A generic, BigQuery-driven computation framework that can be applied to any dataset.
|
|
6
|
+
|
|
7
|
+
**Key Principles:**
|
|
8
|
+
- **Zero hardcoded schemas** - Schemas are discovered dynamically from BigQuery metadata
|
|
9
|
+
- **Pre-query validation** - Queries are validated against cached schemas before execution
|
|
10
|
+
- **Simple computation interface** - Just declare what tables you need
|
|
11
|
+
- **Pass-based execution** - Topological sort determines execution order (Kahn's algorithm)
|
|
12
|
+
- **Hash-based versioning** - Automatic detection of code/dependency changes
|
|
13
|
+
|
|
14
|
+
## Directory Structure
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
computation-system-v2/
|
|
18
|
+
├── framework/ # GENERIC - Works with any BigQuery data
|
|
19
|
+
│ ├── core/
|
|
20
|
+
│ │ ├── Computation.js # Base class for all computations
|
|
21
|
+
│ │ ├── Executor.js # Orchestrates computation execution
|
|
22
|
+
│ │ └── Manifest.js # Builds & validates computation graph
|
|
23
|
+
│ ├── data/
|
|
24
|
+
│ │ ├── SchemaRegistry.js # Dynamic schema discovery + caching
|
|
25
|
+
│ │ ├── QueryBuilder.js # Builds validated SQL queries
|
|
26
|
+
│ │ └── DataFetcher.js # Executes queries, returns data
|
|
27
|
+
│ ├── persistence/
|
|
28
|
+
│ │ └── ResultWriter.js # Writes computation results
|
|
29
|
+
│ └── utils/
|
|
30
|
+
│ ├── hash.js # Code hashing utilities
|
|
31
|
+
│ └── logger.js # Logging utilities
|
|
32
|
+
│
|
|
33
|
+
├── config/
|
|
34
|
+
│ └── bulltrackers.config.js # BullTrackers-specific configuration
|
|
35
|
+
│
|
|
36
|
+
├── computations/ # BullTrackers computations (v2 format)
|
|
37
|
+
│ └── (migrated computations go here)
|
|
38
|
+
│
|
|
39
|
+
└── index.js # Main entry point
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
### 1. Define a Computation
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
const { Computation } = require('./framework/core/Computation');
|
|
48
|
+
|
|
49
|
+
class MyComputation extends Computation {
|
|
50
|
+
static getConfig() {
|
|
51
|
+
return {
|
|
52
|
+
name: 'MyComputation',
|
|
53
|
+
requires: {
|
|
54
|
+
'my_table': {
|
|
55
|
+
lookback: 0, // 0 = today only, N = last N days
|
|
56
|
+
mandatory: true // If true, computation won't run without this data
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
dependencies: [], // Other computations this depends on
|
|
60
|
+
type: 'global' // 'global' or 'per-entity'
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async process(context) {
|
|
65
|
+
const data = context.data['my_table'];
|
|
66
|
+
// Your logic here
|
|
67
|
+
return { result: 'computed value' };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 2. Register in Config
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
// config/bulltrackers.config.js
|
|
76
|
+
module.exports = {
|
|
77
|
+
bigquery: {
|
|
78
|
+
projectId: 'your-project',
|
|
79
|
+
dataset: 'your_dataset'
|
|
80
|
+
},
|
|
81
|
+
tables: {
|
|
82
|
+
'my_table': {
|
|
83
|
+
dateField: 'date',
|
|
84
|
+
entityField: 'user_id'
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
computations: [
|
|
88
|
+
require('./computations/MyComputation')
|
|
89
|
+
]
|
|
90
|
+
};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 3. Run
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
const { execute } = require('./computation-system-v2');
|
|
97
|
+
await execute({ date: '2026-01-24', config: require('./config/bulltrackers.config') });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Key Concepts
|
|
101
|
+
|
|
102
|
+
### Schema Registry
|
|
103
|
+
|
|
104
|
+
The `SchemaRegistry` fetches table schemas from BigQuery's `INFORMATION_SCHEMA` and caches them:
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
const schema = await schemaRegistry.getSchema('my_table');
|
|
108
|
+
// Returns: [{ name: 'id', type: 'INT64' }, { name: 'date', type: 'DATE' }, ...]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Before any query is executed, it's validated against the cached schema to prevent runtime errors.
|
|
112
|
+
|
|
113
|
+
### Query Validation
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
// This will throw BEFORE hitting BigQuery if 'nonexistent_column' doesn't exist
|
|
117
|
+
const query = queryBuilder.build({
|
|
118
|
+
table: 'my_table',
|
|
119
|
+
select: ['id', 'nonexistent_column'], // Error: column doesn't exist
|
|
120
|
+
where: { date: '2026-01-24' }
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Pass System
|
|
125
|
+
|
|
126
|
+
Computations are automatically organized into "passes" based on dependencies:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
Pass 1: Computations with no dependencies (can run in parallel)
|
|
130
|
+
Pass 2: Computations depending only on Pass 1 results
|
|
131
|
+
Pass 3: Computations depending on Pass 1 or 2 results
|
|
132
|
+
...
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Hash-Based Versioning
|
|
136
|
+
|
|
137
|
+
Each computation gets a unique hash based on:
|
|
138
|
+
- Its own code
|
|
139
|
+
- The code of any shared utilities it uses
|
|
140
|
+
- The hashes of its dependencies
|
|
141
|
+
|
|
142
|
+
When a hash changes, the computation re-runs. When hashes match, results are reused.
|
|
143
|
+
|
|
144
|
+
## Comparison with v1
|
|
145
|
+
|
|
146
|
+
| Aspect | v1 | v2 |
|
|
147
|
+
|--------|----|----|
|
|
148
|
+
| Schema definition | Hardcoded in `bigquery_utils.js` | Dynamic from `INFORMATION_SCHEMA` |
|
|
149
|
+
| Query building | Per-table functions | Single generic builder with validation |
|
|
150
|
+
| Data loading | Complex routing through multiple layers | Direct fetch with simple interface |
|
|
151
|
+
| Computation declaration | Multiple overlapping fields | Single `requires` object |
|
|
152
|
+
| Domain coupling | Deeply embedded | Configuration-only |
|