Codexcoder commited on
Commit
1b4e60d
·
verified ·
1 Parent(s): 2b619a1

kyrexis: add kyrexis/progression_scaling.py

Browse files
Files changed (1) hide show
  1. kyrexis/progression_scaling.py +180 -0
kyrexis/progression_scaling.py ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # kyrexis/progression_scaling.py
2
+ """
3
+ Kyrexis 20-Year Progression Scaling (x4)
4
+
5
+ 33.5% CAGR · 368x Growth · 96.1% Maximum · 5.4469 Lineage Coefficient
6
+
7
+ The x4 scaling factor multiplies any projected metric — this is a
8
+ product-level planning multiplier from the module spec, not a claim
9
+ about real market growth.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from dataclasses import dataclass
15
+ from typing import Any, Dict, List, Optional # noqa: F401
16
+
17
+
18
+ @dataclass
19
+ class ProgressionYear:
20
+ """Progression data for a single year."""
21
+
22
+ year: int
23
+ growth_factor: float
24
+ lineage_coefficient: float
25
+ awakening: float
26
+ confidence: float
27
+
28
+
29
+ @dataclass
30
+ class ProgressionScale:
31
+ """20-year progression scaling parameters."""
32
+
33
+ total_years: int = 20
34
+ annual_growth_rate: float = 0.335 # 33.5% CAGR
35
+ total_growth_factor: float = 368.4
36
+ max_coefficient: float = 5.6667
37
+ current_coefficient: float = 5.4469
38
+ max_achievement: float = 0.961 # 96.1%
39
+
40
+
41
+ class ProgressionScalingEngine:
42
+ """
43
+ Kyrexis 20-Year Progression Scaling Engine.
44
+
45
+ Fixes the spec draft: the engine previously referenced
46
+ ``self.annual_growth_rate`` etc. before defining them — the
47
+ parameters now live on the engine (mirroring ProgressionScale).
48
+ """
49
+
50
+ def __init__(self, scale_factor: int = 4):
51
+ self.scale_factor = scale_factor
52
+ self.current_year = 0
53
+ self.progression_data: Dict[str, Any] = {}
54
+
55
+ # Parameters (from ProgressionScale / spec anchors)
56
+ self.total_years = 20
57
+ self.annual_growth_rate = 0.335
58
+ self.total_growth_factor = 368.4
59
+ self.max_coefficient = 5.6667
60
+ self.current_coefficient = 5.4469
61
+ self.max_achievement = 0.961
62
+
63
+ self.years: List[ProgressionYear] = []
64
+ self._init_progression()
65
+
66
+ def _init_progression(self) -> None:
67
+ """Initialize the 20-year progression table."""
68
+ print("📈 Initializing 20-Year Progression Scaling")
69
+ print(f" Annual Growth Rate: {self.annual_growth_rate * 100:.1f}%")
70
+ print(f" Total Growth Factor: {self.total_growth_factor:.1f}x")
71
+ print(f" Max Coefficient: {self.max_coefficient:.4f}")
72
+ print(f" Current Coefficient: {self.current_coefficient:.4f}")
73
+ print(f" Max Achievement: {self.max_achievement * 100:.1f}%")
74
+
75
+ self.years = []
76
+ for year in range(1, self.total_years + 1):
77
+ growth = (1 + self.annual_growth_rate) ** year
78
+ coefficient = self.max_coefficient * (1 - 0.85 ** year)
79
+ awakening = min(1.0, 0.4 + 0.025 * year + 0.01 * year ** 0.5)
80
+ confidence = max(0.0, 0.95 - (year * 0.005))
81
+ self.years.append(
82
+ ProgressionYear(
83
+ year=year,
84
+ growth_factor=round(growth, 4),
85
+ lineage_coefficient=round(coefficient, 4),
86
+ awakening=round(awakening, 4),
87
+ confidence=round(confidence, 4),
88
+ )
89
+ )
90
+ print(f"✅ {len(self.years)} progression years initialized")
91
+
92
+ def apply_scaling(self, value: float) -> float:
93
+ """Apply the x4 scaling multiplier."""
94
+ return value * self.scale_factor
95
+
96
+ def get_progression_at_year(self, year: int) -> Dict[str, Any]:
97
+ """Progression data at a specific year (with x4 scaling)."""
98
+ if year < 1 or year > self.total_years:
99
+ return {"error": f"Year must be between 1 and {self.total_years}"}
100
+ prog = self.years[year - 1]
101
+ return {
102
+ "year": year,
103
+ "growth_factor": prog.growth_factor,
104
+ "growth_factor_scaled": round(self.apply_scaling(prog.growth_factor), 4),
105
+ "lineage_coefficient": prog.lineage_coefficient,
106
+ "lineage_coefficient_scaled": round(self.apply_scaling(prog.lineage_coefficient), 4),
107
+ "awakening": prog.awakening,
108
+ "awakening_scaled": round(self.apply_scaling(prog.awakening), 4),
109
+ "confidence": prog.confidence,
110
+ "scaling_factor": self.scale_factor,
111
+ }
112
+
113
+ def get_full_progression(self) -> List[Dict[str, Any]]:
114
+ """Full 20-year progression table."""
115
+ return [self.get_progression_at_year(year) for year in range(1, self.total_years + 1)]
116
+
117
+ def get_summary(self) -> Dict[str, Any]:
118
+ """Progression summary."""
119
+ last_year = self.years[-1]
120
+ return {
121
+ "total_years": self.total_years,
122
+ "annual_growth_rate": self.annual_growth_rate,
123
+ "annual_growth_rate_percent": self.annual_growth_rate * 100,
124
+ "total_growth_factor": self.total_growth_factor,
125
+ "total_growth_factor_scaled": round(self.apply_scaling(self.total_growth_factor), 1),
126
+ "max_coefficient": self.max_coefficient,
127
+ "max_coefficient_scaled": round(self.apply_scaling(self.max_coefficient), 4),
128
+ "current_coefficient": self.current_coefficient,
129
+ "current_coefficient_scaled": round(self.apply_scaling(self.current_coefficient), 4),
130
+ "max_achievement": self.max_achievement,
131
+ "max_achievement_percent": self.max_achievement * 100,
132
+ "final_growth": last_year.growth_factor,
133
+ "final_growth_scaled": round(self.apply_scaling(last_year.growth_factor), 1),
134
+ "final_coefficient": last_year.lineage_coefficient,
135
+ "final_coefficient_scaled": round(self.apply_scaling(last_year.lineage_coefficient), 4),
136
+ "final_awakening": last_year.awakening,
137
+ "final_awakening_scaled": round(self.apply_scaling(last_year.awakening), 4),
138
+ "scaling_factor": self.scale_factor,
139
+ }
140
+
141
+ def calculate_20_year_projection(self, current_value: float) -> Dict[str, Any]:
142
+ """Project a value across 20 years with x4 scaling."""
143
+ projection = []
144
+ for year in range(1, self.total_years + 1):
145
+ growth = (1 + self.annual_growth_rate) ** year
146
+ value = current_value * growth
147
+ projection.append({
148
+ "year": year,
149
+ "growth_factor": round(growth, 4),
150
+ "value": round(value, 4),
151
+ "value_scaled": round(value * self.scale_factor, 4),
152
+ })
153
+ return {
154
+ "current_value": current_value,
155
+ "projection": projection,
156
+ "final_value": projection[-1]["value"],
157
+ "final_value_scaled": projection[-1]["value_scaled"],
158
+ "total_growth": round(projection[-1]["value"] / current_value, 2),
159
+ "total_growth_scaled": round(projection[-1]["value_scaled"] / current_value, 2),
160
+ "scaling_factor": self.scale_factor,
161
+ }
162
+
163
+ def get_progression_status(self) -> Dict[str, Any]:
164
+ """Progression system status."""
165
+ return {
166
+ "active": True,
167
+ "total_years": self.total_years,
168
+ "scale_factor": self.scale_factor,
169
+ "years_data": [p.__dict__ for p in self.years],
170
+ "summary": self.get_summary(),
171
+ }
172
+
173
+ def advance_year(self, years: int = 1) -> Dict[str, Any]:
174
+ """Advance the current-year cursor."""
175
+ self.current_year = min(self.current_year + years, self.total_years)
176
+ return self.get_progression_at_year(self.current_year)
177
+
178
+
179
+ # Singleton
180
+ progression = ProgressionScalingEngine()