bulltrackers-module 1.0.732 → 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.
Files changed (106) hide show
  1. package/functions/computation-system-v2/README.md +152 -0
  2. package/functions/computation-system-v2/computations/PopularInvestorProfileMetrics.js +720 -0
  3. package/functions/computation-system-v2/computations/PopularInvestorRiskAssessment.js +176 -0
  4. package/functions/computation-system-v2/computations/PopularInvestorRiskMetrics.js +294 -0
  5. package/functions/computation-system-v2/computations/TestComputation.js +46 -0
  6. package/functions/computation-system-v2/computations/UserPortfolioSummary.js +172 -0
  7. package/functions/computation-system-v2/config/bulltrackers.config.js +317 -0
  8. package/functions/computation-system-v2/framework/core/Computation.js +73 -0
  9. package/functions/computation-system-v2/framework/core/Manifest.js +223 -0
  10. package/functions/computation-system-v2/framework/core/RuleInjector.js +53 -0
  11. package/functions/computation-system-v2/framework/core/Rules.js +231 -0
  12. package/functions/computation-system-v2/framework/core/RunAnalyzer.js +163 -0
  13. package/functions/computation-system-v2/framework/cost/CostTracker.js +154 -0
  14. package/functions/computation-system-v2/framework/data/DataFetcher.js +399 -0
  15. package/functions/computation-system-v2/framework/data/QueryBuilder.js +232 -0
  16. package/functions/computation-system-v2/framework/data/SchemaRegistry.js +287 -0
  17. package/functions/computation-system-v2/framework/execution/Orchestrator.js +498 -0
  18. package/functions/computation-system-v2/framework/execution/TaskRunner.js +35 -0
  19. package/functions/computation-system-v2/framework/execution/middleware/CostTrackerMiddleware.js +32 -0
  20. package/functions/computation-system-v2/framework/execution/middleware/LineageMiddleware.js +32 -0
  21. package/functions/computation-system-v2/framework/execution/middleware/Middleware.js +14 -0
  22. package/functions/computation-system-v2/framework/execution/middleware/ProfilerMiddleware.js +47 -0
  23. package/functions/computation-system-v2/framework/index.js +45 -0
  24. package/functions/computation-system-v2/framework/lineage/LineageTracker.js +147 -0
  25. package/functions/computation-system-v2/framework/monitoring/Profiler.js +80 -0
  26. package/functions/computation-system-v2/framework/resilience/Checkpointer.js +66 -0
  27. package/functions/computation-system-v2/framework/scheduling/ScheduleValidator.js +327 -0
  28. package/functions/computation-system-v2/framework/storage/StateRepository.js +286 -0
  29. package/functions/computation-system-v2/framework/storage/StorageManager.js +469 -0
  30. package/functions/computation-system-v2/framework/storage/index.js +9 -0
  31. package/functions/computation-system-v2/framework/testing/ComputationTester.js +86 -0
  32. package/functions/computation-system-v2/framework/utils/Graph.js +205 -0
  33. package/functions/computation-system-v2/handlers/dispatcher.js +109 -0
  34. package/functions/computation-system-v2/handlers/index.js +23 -0
  35. package/functions/computation-system-v2/handlers/onDemand.js +289 -0
  36. package/functions/computation-system-v2/handlers/scheduler.js +327 -0
  37. package/functions/computation-system-v2/index.js +163 -0
  38. package/functions/computation-system-v2/rules/index.js +49 -0
  39. package/functions/computation-system-v2/rules/instruments.js +465 -0
  40. package/functions/computation-system-v2/rules/metrics.js +304 -0
  41. package/functions/computation-system-v2/rules/portfolio.js +534 -0
  42. package/functions/computation-system-v2/rules/rankings.js +655 -0
  43. package/functions/computation-system-v2/rules/social.js +562 -0
  44. package/functions/computation-system-v2/rules/trades.js +545 -0
  45. package/functions/computation-system-v2/scripts/migrate-sectors.js +73 -0
  46. package/functions/computation-system-v2/test/test-dispatcher.js +317 -0
  47. package/functions/computation-system-v2/test/test-framework.js +500 -0
  48. package/functions/computation-system-v2/test/test-real-execution.js +166 -0
  49. package/functions/computation-system-v2/test/test-real-integration.js +194 -0
  50. package/functions/computation-system-v2/test/test-refactor-e2e.js +131 -0
  51. package/functions/computation-system-v2/test/test-results.json +31 -0
  52. package/functions/computation-system-v2/test/test-risk-metrics-computation.js +329 -0
  53. package/functions/computation-system-v2/test/test-scheduler.js +204 -0
  54. package/functions/computation-system-v2/test/test-storage.js +449 -0
  55. package/functions/orchestrator/index.js +24 -30
  56. package/index.js +8 -29
  57. package/package.json +3 -2
  58. package/functions/computation-system/WorkflowOrchestrator.js +0 -213
  59. package/functions/computation-system/config/monitoring_config.js +0 -31
  60. package/functions/computation-system/config/validation_overrides.js +0 -10
  61. package/functions/computation-system/context/ContextFactory.js +0 -143
  62. package/functions/computation-system/context/ManifestBuilder.js +0 -379
  63. package/functions/computation-system/data/AvailabilityChecker.js +0 -236
  64. package/functions/computation-system/data/CachedDataLoader.js +0 -325
  65. package/functions/computation-system/data/DependencyFetcher.js +0 -455
  66. package/functions/computation-system/executors/MetaExecutor.js +0 -279
  67. package/functions/computation-system/executors/PriceBatchExecutor.js +0 -108
  68. package/functions/computation-system/executors/StandardExecutor.js +0 -465
  69. package/functions/computation-system/helpers/computation_dispatcher.js +0 -750
  70. package/functions/computation-system/helpers/computation_worker.js +0 -375
  71. package/functions/computation-system/helpers/monitor.js +0 -64
  72. package/functions/computation-system/helpers/on_demand_helpers.js +0 -154
  73. package/functions/computation-system/layers/extractors.js +0 -1097
  74. package/functions/computation-system/layers/index.js +0 -40
  75. package/functions/computation-system/layers/mathematics.js +0 -522
  76. package/functions/computation-system/layers/profiling.js +0 -537
  77. package/functions/computation-system/layers/validators.js +0 -170
  78. package/functions/computation-system/legacy/AvailabilityCheckerOld.js +0 -388
  79. package/functions/computation-system/legacy/CachedDataLoaderOld.js +0 -357
  80. package/functions/computation-system/legacy/DependencyFetcherOld.js +0 -478
  81. package/functions/computation-system/legacy/MetaExecutorold.js +0 -364
  82. package/functions/computation-system/legacy/StandardExecutorold.js +0 -476
  83. package/functions/computation-system/legacy/computation_dispatcherold.js +0 -944
  84. package/functions/computation-system/logger/logger.js +0 -297
  85. package/functions/computation-system/persistence/ContractValidator.js +0 -81
  86. package/functions/computation-system/persistence/FirestoreUtils.js +0 -56
  87. package/functions/computation-system/persistence/ResultCommitter.js +0 -283
  88. package/functions/computation-system/persistence/ResultsValidator.js +0 -130
  89. package/functions/computation-system/persistence/RunRecorder.js +0 -142
  90. package/functions/computation-system/persistence/StatusRepository.js +0 -52
  91. package/functions/computation-system/reporter_epoch.js +0 -6
  92. package/functions/computation-system/scripts/UpdateContracts.js +0 -128
  93. package/functions/computation-system/services/SnapshotService.js +0 -148
  94. package/functions/computation-system/simulation/Fabricator.js +0 -285
  95. package/functions/computation-system/simulation/SeededRandom.js +0 -41
  96. package/functions/computation-system/simulation/SimRunner.js +0 -51
  97. package/functions/computation-system/system_epoch.js +0 -2
  98. package/functions/computation-system/tools/BuildReporter.js +0 -531
  99. package/functions/computation-system/tools/ContractDiscoverer.js +0 -144
  100. package/functions/computation-system/tools/DeploymentValidator.js +0 -536
  101. package/functions/computation-system/tools/FinalSweepReporter.js +0 -322
  102. package/functions/computation-system/topology/HashManager.js +0 -55
  103. package/functions/computation-system/topology/ManifestLoader.js +0 -47
  104. package/functions/computation-system/utils/data_loader.js +0 -675
  105. package/functions/computation-system/utils/schema_capture.js +0 -121
  106. package/functions/computation-system/utils/utils.js +0 -188
@@ -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 |