Procházet zdrojové kódy

feat: 优化每日邮件报告和新增每周备份

- 邮件标题增加'Regime'标识
- 详细数据从60天扩展到365天
- 日期格式改为yy-mm-dd (如26-03-06)
- 新增OpenClaw每周自动备份脚本
- 设置每周日凌晨2:00自动备份
- 取消catfly-daily-backup定时任务

修改文件:
- daily_email_sender.py: 优化邮件内容和格式
- openclaw_weekly_backup.sh: 新增备份脚本
openclaw před 3 měsíci
rodič
revize
8145f72692

+ 13 - 13
market-regime-identifier/daily_email_sender.py

@@ -59,9 +59,9 @@ df_aligned['prob_ranging'] = probs[:, 0]
 df_aligned['prob_trend'] = probs[:, 1]
 df_aligned['prob_reversal'] = probs[:, 2]
 
-# 获取最近60
-last_60 = df_aligned.tail(60).copy()
-last_60['change'] = last_60['close'].pct_change() * 100
+# 获取最近365
+last_365 = df_aligned.tail(365).copy()
+last_365['change'] = last_365['close'].pct_change() * 100
 
 # 获取最新数据
 today = df_aligned.iloc[-1]
@@ -72,9 +72,9 @@ colors = ['#2196F3', '#4CAF50', '#FF5722']
 state_name = state_names[int(today['state'])]
 state_color = colors[int(today['state'])]
 
-# 生成60天详细数据表格
+# 生成365天详细数据表格
 html_rows = ""
-for idx, row in last_60.iterrows():
+for idx, row in last_365.iterrows():
     s = int(row['state'])
     change = row['change'] if not pd.isna(row['change']) else 0
     change_str = f"{change:+.2f}%" if change != 0 else "-"
@@ -85,7 +85,7 @@ for idx, row in last_60.iterrows():
     
     html_rows += f"""
         <tr {highlight}>
-            <td>{idx.strftime('%m-%d')}</td>
+            <td>{idx.strftime('%y-%m-%d')}</td>
             <td>{row['close']:.2f}</td>
             <td style="color: {colors[s]}; font-weight: bold;">{state_names[s]}</td>
             <td>{row['prob_ranging']:.1%}</td>
@@ -100,7 +100,7 @@ daily_change = today['close'] - yesterday['close']
 daily_change_pct = daily_change / yesterday['close'] * 100
 
 # 计算区间涨跌
-range_change_pct = (today['close'] / last_60['close'].iloc[0] - 1) * 100
+range_change_pct = (today['close'] / last_365['close'].iloc[0] - 1) * 100
 
 # 邮件内容
 html = f"""
@@ -135,15 +135,15 @@ html = f"""
     </div>
     
     <div class="summary">
-        <h2>📊 最近60天统计 (2024-至今)</h2>
-        <p><strong>60天前价格:</strong> {last_60['close'].iloc[0]:.2f}</p>
+        <h2>📊 最近365天统计 (2024-至今)</h2>
+        <p><strong>365天前价格:</strong> {last_365['close'].iloc[0]:.2f}</p>
         <p><strong>区间涨跌:</strong> <span style="color: {'green' if range_change_pct >= 0 else 'red'};">{range_change_pct:+.2f}%</span></p>
-        <p><strong>最高价:</strong> {last_60['close'].max():.2f} ({last_60['close'].idxmax().strftime('%m-%d')}) / <strong>最低价:</strong> {last_60['close'].min():.2f} ({last_60['close'].idxmin().strftime('%m-%d')})</p>
+        <p><strong>最高价:</strong> {last_365['close'].max():.2f} ({last_365['close'].idxmax().strftime('%m-%d')}) / <strong>最低价:</strong> {last_365['close'].min():.2f} ({last_365['close'].idxmin().strftime('%m-%d')})</p>
         <br>
-        <p><strong>状态分布:</strong> 🟦 震荡 {(last_60['state']==0).sum()}天 / 🟩 趋势 {(last_60['state']==1).sum()}天 / 🟧 反转 {(last_60['state']==2).sum()}天</p>
+        <p><strong>状态分布:</strong> 🟦 震荡 {(last_365['state']==0).sum()}天 / 🟩 趋势 {(last_365['state']==1).sum()}天 / 🟧 反转 {(last_365['state']==2).sum()}天</p>
     </div>
     
-    <h2>📋 最近60天详细数据</h2>
+    <h2>📋 最近365天详细数据</h2>
     <p class="legend">
         <span>🟦 震荡</span>
         <span>🟩 趋势</span>
@@ -186,7 +186,7 @@ EMAIL_CONFIG = {
 }
 
 msg = MIMEMultipart('related')
-msg['Subject'] = Header(f"📊 CYB50每日市场状态报告 [{df_aligned.index[-1].strftime('%m-%d')}] 当前{state_name}", 'utf-8')
+msg['Subject'] = Header(f"📊 CYB50-Regime每日市场状态报告 [{df_aligned.index[-1].strftime('%m-%d')}] 当前{state_name}", 'utf-8')
 msg['From'] = "regime <regime@openclaw.local>"
 msg['To'] = EMAIL_CONFIG['receiver_email']
 msg.attach(MIMEText(html, 'html', 'utf-8'))

+ 38 - 0
openclaw_weekly_backup.sh

@@ -0,0 +1,38 @@
+#!/bin/bash
+# OpenClaw 每周自动备份脚本
+# 运行时间: 每周日凌晨 2:00
+
+BACKUP_DIR="/root/openclaw-backups"
+DATE=$(date +%Y%m%d-%H%M%S)
+BACKUP_FILE="$BACKUP_DIR/openclaw-weekly-$DATE.tar.gz"
+
+# 创建备份目录
+mkdir -p "$BACKUP_DIR"
+
+# 执行备份
+tar -czf "$BACKUP_FILE" \
+  -C /root/.openclaw \
+  --exclude='workspace/cat-fly/__pycache__' \
+  --exclude='workspace/market-regime-identifier/__pycache__' \
+  --exclude='*.pyc' \
+  --exclude='*.log' \
+  workspace/ \
+  openclaw.json \
+  openclaw.json.bak \
+  openclaw.json.bak.1 \
+  openclaw.json.bak.2 \
+  openclaw.json.bak.3 \
+  openclaw.json.bak.4 2>/dev/null
+
+# 检查备份是否成功
+if [ $? -eq 0 ]; then
+    echo "[$(date '+%Y-%m-%d %H:%M:%S')] ✓ OpenClaw 备份成功: $BACKUP_FILE"
+    echo "  文件大小: $(du -h $BACKUP_FILE | cut -f1)"
+    
+    # 只保留最近4个备份(约1个月)
+    ls -t $BACKUP_DIR/openclaw-weekly-*.tar.gz | tail -n +5 | xargs -r rm -f
+    echo "  已清理旧备份,保留最近4个"
+else
+    echo "[$(date '+%Y-%m-%d %H:%M:%S')] ✗ OpenClaw 备份失败"
+    exit 1
+fi