Riy777 commited on
Commit
e2fdba0
ยท
1 Parent(s): 60b8fa4

Update r2.py

Browse files
Files changed (1) hide show
  1. r2.py +43 -1
r2.py CHANGED
@@ -63,6 +63,48 @@ class R2Service:
63
  except Exception as e:
64
  print(f"โŒ Failed to release lock: {e}")
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  async def save_llm_prompts_async(self, symbol, prompt_type, prompt_content, analysis_data=None):
67
  """ุญูุธ ุงู„ู€ Prompts ุงู„ู…ุฑุณู„ุฉ ุฅู„ู‰ ุงู„ู†ู…ูˆุฐุฌ ุงู„ุถุฎู…"""
68
  try:
@@ -292,4 +334,4 @@ class R2Service:
292
  print(f"โŒ Failed to get monitored trades: {e}")
293
  return []
294
 
295
- print("โœ… Enhanced R2 Service Loaded - Comprehensive Logging System")
 
63
  except Exception as e:
64
  print(f"โŒ Failed to release lock: {e}")
65
 
66
+ async def save_candidates_async(self, candidates):
67
+ """ุญูุธ ุจูŠุงู†ุงุช ุงู„ู…ุฑุดุญูŠู† ุงู„ุนุดุฑุฉ ููŠ ู…ู„ู ู…ู†ูุตู„ ููŠ R2"""
68
+ try:
69
+ key = "Candidates.json"
70
+ data = {
71
+ "timestamp": datetime.now().isoformat(),
72
+ "total_candidates": len(candidates),
73
+ "candidates": candidates
74
+ }
75
+ data_json = json.dumps(data, indent=2, ensure_ascii=False).encode('utf-8')
76
+ self.s3_client.put_object(
77
+ Bucket=BUCKET_NAME, Key=key, Body=data_json, ContentType="application/json"
78
+ )
79
+ print(f"โœ… ุชู… ุญูุธ {len(candidates)} ู…ุฑุดุญ ููŠ ู…ู„ู Candidates ููŠ R2")
80
+
81
+ # ุนุฑุถ ู…ุนู„ูˆู…ุงุช ุงู„ู…ุฑุดุญูŠู† ุงู„ู…ุญููˆุธูŠู†
82
+ print("๐Ÿ“Š ุงู„ู…ุฑุดุญูˆู† ุงู„ู…ุญููˆุธูˆู†:")
83
+ for i, candidate in enumerate(candidates):
84
+ symbol = candidate.get('symbol', 'Unknown')
85
+ score = candidate.get('enhanced_final_score', 0)
86
+ strategy = candidate.get('target_strategy', 'GENERIC')
87
+ print(f" {i+1}. {symbol}: {score:.3f} - {strategy}")
88
+
89
+ except Exception as e:
90
+ print(f"โŒ ูุดู„ ุญูุธ ุงู„ู…ุฑุดุญูŠู† ููŠ R2: {e}")
91
+
92
+ async def load_candidates_async(self):
93
+ """ุชุญู…ูŠู„ ุจูŠุงู†ุงุช ุงู„ู…ุฑุดุญูŠู† ู…ู† R2"""
94
+ try:
95
+ key = "Candidates.json"
96
+ response = self.s3_client.get_object(Bucket=BUCKET_NAME, Key=key)
97
+ data = json.loads(response['Body'].read())
98
+ candidates = data.get('candidates', [])
99
+ print(f"โœ… ุชู… ุชุญู…ูŠู„ {len(candidates)} ู…ุฑุดุญ ู…ู† R2")
100
+ return candidates
101
+ except ClientError as e:
102
+ if e.response['Error']['Code'] == 'NoSuchKey':
103
+ print("โš ๏ธ ู„ุง ูŠูˆุฌุฏ ู…ู„ู ู…ุฑุดุญูŠู† ุณุงุจู‚")
104
+ return []
105
+ else:
106
+ raise
107
+
108
  async def save_llm_prompts_async(self, symbol, prompt_type, prompt_content, analysis_data=None):
109
  """ุญูุธ ุงู„ู€ Prompts ุงู„ู…ุฑุณู„ุฉ ุฅู„ู‰ ุงู„ู†ู…ูˆุฐุฌ ุงู„ุถุฎู…"""
110
  try:
 
334
  print(f"โŒ Failed to get monitored trades: {e}")
335
  return []
336
 
337
+ print("โœ… Enhanced R2 Service Loaded - Comprehensive Logging System with Candidates Support")