Riy777 commited on
Commit
ed354c8
·
verified ·
1 Parent(s): dc313fd

Update ml_engine/patterns.py

Browse files
Files changed (1) hide show
  1. ml_engine/patterns.py +25 -4
ml_engine/patterns.py CHANGED
@@ -1,5 +1,5 @@
1
  # ml_engine/patterns.py
2
- # (V12.0 - Unified Pattern Engine - XGBoost & Pipeline Merged)
3
 
4
  import os
5
  import gc
@@ -25,7 +25,7 @@ except ImportError:
25
  logger.warning("⚠️ مكتبة 'hurst' غير موجودة. سيتم استخدام القيمة الافتراضية.")
26
 
27
  # ==============================================================================
28
- # 🛠️ INTERNAL HELPER FUNCTIONS (Previously in xgboost_pattern_v2)
29
  # ==============================================================================
30
 
31
  def _zv(x):
@@ -169,10 +169,26 @@ class ChartPatternAnalyzer:
169
  """
170
  self.models_dir = models_dir
171
  self.models = {}
 
 
 
172
  self.timeframe_weights = {'15m': 0.40, '1h': 0.30, '5m': 0.20, '4h': 0.10, '1d': 0.00}
 
 
 
173
  self.supported_timeframes = list(self.timeframe_weights.keys())
174
  self.initialized = False
175
 
 
 
 
 
 
 
 
 
 
 
176
  async def initialize(self):
177
  """تحميل نماذج XGBoost"""
178
  if self.initialized: return True
@@ -183,6 +199,7 @@ class ChartPatternAnalyzer:
183
  return False
184
 
185
  loaded_count = 0
 
186
  for tf in self.supported_timeframes:
187
  model_path = os.path.join(self.models_dir, f"xgb_{tf}.json")
188
  if os.path.exists(model_path):
@@ -223,6 +240,7 @@ class ChartPatternAnalyzer:
223
  prob_up = model.predict(dtest)[0]
224
  details[tf] = float(prob_up)
225
 
 
226
  weight = self.timeframe_weights.get(tf, 0.0)
227
  if weight > 0:
228
  weighted_score_sum += prob_up * weight
@@ -236,9 +254,12 @@ class ChartPatternAnalyzer:
236
  if total_weight_used > 0:
237
  final_score = weighted_score_sum / total_weight_used
238
 
 
239
  pattern_text = "Neutral"
240
- if final_score >= 0.60: pattern_text = "Bullish Signal"
241
- elif final_score <= 0.40: pattern_text = "Bearish Signal"
 
 
242
 
243
  return {
244
  'pattern_detected': pattern_text,
 
1
  # ml_engine/patterns.py
2
+ # (V30.0 - GEM-Architect: Config-Injectable Edition)
3
 
4
  import os
5
  import gc
 
25
  logger.warning("⚠️ مكتبة 'hurst' غير موجودة. سيتم استخدام القيمة الافتراضية.")
26
 
27
  # ==============================================================================
28
+ # 🛠️ INTERNAL HELPER FUNCTIONS (Essential for Feature Engineering)
29
  # ==============================================================================
30
 
31
  def _zv(x):
 
169
  """
170
  self.models_dir = models_dir
171
  self.models = {}
172
+
173
+ # ✅ القيم الافتراضية (Placeholder)
174
+ # سيتم الكتابة عليها بواسطة Processor عند التشغيل
175
  self.timeframe_weights = {'15m': 0.40, '1h': 0.30, '5m': 0.20, '4h': 0.10, '1d': 0.00}
176
+ self.thresh_bullish = 0.60
177
+ self.thresh_bearish = 0.40
178
+
179
  self.supported_timeframes = list(self.timeframe_weights.keys())
180
  self.initialized = False
181
 
182
+ def configure_thresholds(self, weights: dict, bull_thresh: float, bear_thresh: float):
183
+ """
184
+ دالة استقبال الإعدادات من المعالج المركزي (Processor Injection).
185
+ """
186
+ self.timeframe_weights = weights
187
+ self.thresh_bullish = bull_thresh
188
+ self.thresh_bearish = bear_thresh
189
+ self.supported_timeframes = list(weights.keys())
190
+ logger.info(f"🔧 [PatternEngine] Config Injected: Bull > {self.thresh_bullish}, Weights set.")
191
+
192
  async def initialize(self):
193
  """تحميل نماذج XGBoost"""
194
  if self.initialized: return True
 
199
  return False
200
 
201
  loaded_count = 0
202
+ # تحميل النماذج بناءً على الأطر الزمنية المدعومة (التي تم تكوينها)
203
  for tf in self.supported_timeframes:
204
  model_path = os.path.join(self.models_dir, f"xgb_{tf}.json")
205
  if os.path.exists(model_path):
 
240
  prob_up = model.predict(dtest)[0]
241
  details[tf] = float(prob_up)
242
 
243
+ # ✅ استخدام الوزن الديناميكي
244
  weight = self.timeframe_weights.get(tf, 0.0)
245
  if weight > 0:
246
  weighted_score_sum += prob_up * weight
 
254
  if total_weight_used > 0:
255
  final_score = weighted_score_sum / total_weight_used
256
 
257
+ # ✅ استخدام العتبات الديناميكية للتصنيف
258
  pattern_text = "Neutral"
259
+ if final_score >= self.thresh_bullish:
260
+ pattern_text = "Bullish Signal"
261
+ elif final_score <= self.thresh_bearish:
262
+ pattern_text = "Bearish Signal"
263
 
264
  return {
265
  'pattern_detected': pattern_text,