jzyg123 commited on
Commit
f2b0f1f
·
verified ·
1 Parent(s): 65f9559

Update src/script.py

Browse files
Files changed (1) hide show
  1. src/script.py +9 -6
src/script.py CHANGED
@@ -392,6 +392,9 @@ class DingTalkFormQueryClient:
392
  except Exception:
393
  current['score_trend'] = "计算错误"
394
 
 
 
 
395
  return processed_records
396
 
397
  def timestamp_to_date(self, timestamp):
@@ -445,7 +448,7 @@ class DingTalkFormQueryClient:
445
  def compute_rank_trend(self, records):
446
  """计算相比上次考试的组合排名变化。返回字符串如 '↓3名' 或 '↑2名' 或 '无变化'。"""
447
  try:
448
- # records 按时间序排列(正序),的在最
449
  if not records or len(records) < 2:
450
  return "无变化"
451
  # 提取最近两次的组合排名字段并尝试解析为整数
@@ -457,8 +460,8 @@ class DingTalkFormQueryClient:
457
  s = re.sub(r"[^0-9]", "", str(v))
458
  return int(s) if s.isdigit() else None
459
 
460
- latest = parse_rank(records[-1]) # 最新的在最后
461
- prev = parse_rank(records[-2]) # 上一次的在倒数第二个
462
  if latest is None or prev is None:
463
  return "无数据"
464
  diff = prev - latest
@@ -639,9 +642,9 @@ def query():
639
  if student_name == '周洋光' and result.get('success') and result.get('data'):
640
  print("✅ 检测到周洋光,准备发送通知...")
641
  trend = client.compute_rank_trend(result.get('data'))
642
- # 取最新考试名称(列表已按序排列,取最后一个)
643
- latest_exam = result.get('data')[-1].get('考试名称', '') if result.get('data') else ''
644
- title = f"本次考试排名: {result.get('data')[-1].get('大类排名','最新排名')}名"
645
  message = f"相比上次考试趋势: {trend}"
646
  signature = latest_exam
647
  send_resp = client.send_dot_notification(title, message, signature)
 
392
  except Exception:
393
  current['score_trend'] = "计算错误"
394
 
395
+ # 反转列表,使最新的考试排在前面
396
+ processed_records.reverse()
397
+
398
  return processed_records
399
 
400
  def timestamp_to_date(self, timestamp):
 
448
  def compute_rank_trend(self, records):
449
  """计算相比上次考试的组合排名变化。返回字符串如 '↓3名' 或 '↑2名' 或 '无变化'。"""
450
  try:
451
+ # records 按时间序排列(最的在最前面)
452
  if not records or len(records) < 2:
453
  return "无变化"
454
  # 提取最近两次的组合排名字段并尝试解析为整数
 
460
  s = re.sub(r"[^0-9]", "", str(v))
461
  return int(s) if s.isdigit() else None
462
 
463
+ latest = parse_rank(records[0]) # 最新的在第一个
464
+ prev = parse_rank(records[1]) # 上一次的在第二个
465
  if latest is None or prev is None:
466
  return "无数据"
467
  diff = prev - latest
 
642
  if student_name == '周洋光' and result.get('success') and result.get('data'):
643
  print("✅ 检测到周洋光,准备发送通知...")
644
  trend = client.compute_rank_trend(result.get('data'))
645
+ # 取最新考试名称(列表已按序排列,取一个)
646
+ latest_exam = result.get('data')[0].get('考试名称', '') if result.get('data') else ''
647
+ title = f"本次考试排名: {result.get('data')[0].get('大类排名','最新排名')}名"
648
  message = f"相比上次考试趋势: {trend}"
649
  signature = latest_exam
650
  send_resp = client.send_dot_notification(title, message, signature)