130 lines
5.2 KiB
Python
130 lines
5.2 KiB
Python
# -*- coding: utf-8 -*-
|
||||
|
|
"""线性代数各讲:难度分布 + 多问结构 + 文件体积 自检。
|
|||
|
|
|
|||
|
|
用法:
|
|||
|
|
python stat_difficulty.py # 扫描全部线代在学练习讲
|
|||
|
|
python stat_difficulty.py <讲目录> ... # 只看指定讲
|
|||
|
|
python stat_difficulty.py <单个.md> # 单文件明细
|
|||
|
|
|
|||
|
|
约定(2026-10-25 定):
|
|||
|
|
题目标题 = `### 题 N · X.Y:短标题(★☆☆|★★☆|★★★)`
|
|||
|
|
道题标签取各小问中的最高难度;(Ⅰ)应当永远是 ★☆☆ 的入口问。
|
|||
|
|
单个 .md 不超过 13000 字符,超了就要拆。
|
|||
|
|
"""
|
|||
|
|
import os
|
|||
|
|
import re
|
|||
|
|
import sys
|
|||
|
|
|
|||
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
|||
|
|
BASE = os.path.join(ROOT, '基于考研的学习', '数学一', '在学练习')
|
|||
|
|
LIMIT = 13000
|
|||
|
|
STAR = {'★☆☆': 1, '★★☆': 2, '★★★': 3}
|
|||
|
|
INV = {1: '★☆☆', 2: '★★☆', 3: '★★★'}
|
|||
|
|
|
|||
|
|
|
|||
|
|
def iter_point_files(target):
|
|||
|
|
"""返回 [(目录名, [点文件路径])]"""
|
|||
|
|
if os.path.isfile(target):
|
|||
|
|
yield (os.path.basename(os.path.dirname(target)), [target])
|
|||
|
|
return
|
|||
|
|
for name in sorted(os.listdir(target)):
|
|||
|
|
p = os.path.join(target, name)
|
|||
|
|
if os.path.isfile(p) and re.match(r'^\d\d[^\d].*\.md$', name) and '速查' not in name and '盘点' not in name:
|
|||
|
|
yield (os.path.basename(target.rstrip('/\\')), [p])
|
|||
|
|
break_ = False
|
|||
|
|
# 目录情形:收集所有 02..09 点文件
|
|||
|
|
if os.path.isdir(target):
|
|||
|
|
files = [os.path.join(target, f) for f in sorted(os.listdir(target))
|
|||
|
|
if re.match(r'^\d\d[^\d].*\.md$', f) and '速查' not in f and '盘点' not in f]
|
|||
|
|
yield (os.path.basename(target.rstrip('/\\')), files)
|
|||
|
|
|
|||
|
|
|
|||
|
|
def analyze(path):
|
|||
|
|
"""返回 (题数, {星级:数量}, [每题问数], 字符数, [非★☆☆起手的标题])"""
|
|||
|
|
t = open(path, encoding='utf-8').read()
|
|||
|
|
cnt = {1: 0, 2: 0, 3: 0}
|
|||
|
|
asks = []
|
|||
|
|
titles = []
|
|||
|
|
for blk in re.split(r'^### 题 ', t, flags=re.M)[1:]:
|
|||
|
|
head = blk.split('\n')[0]
|
|||
|
|
titles.append(head)
|
|||
|
|
# 只统计「题干」中的小问:题目标题之后、"怎么想/解"之前的部分。
|
|||
|
|
# 解析里往往会重复出现(Ⅰ)(Ⅱ)等标号,计入会严重高估。
|
|||
|
|
stem = re.split(r'\n\*\*怎么想\*\*|\n\*\*解\*\*|\n> 考法来源', blk)[0]
|
|||
|
|
body = blk.split('\n---\n')[0]
|
|||
|
|
# 题干在未出现"怎么想"时就是整段 body 的前半:退回到 body
|
|||
|
|
cut = min(len(stem), len(body))
|
|||
|
|
seg = stem[:cut] if stem.strip() else body
|
|||
|
|
n = len(re.findall(r'([ⅠⅡⅢ])|\([123]\)', seg))
|
|||
|
|
asks.append(n)
|
|||
|
|
for k, s in (('★★★', 3), ('★★☆', 2), ('★☆☆', 1)):
|
|||
|
|
if k in head:
|
|||
|
|
cnt[s] += 1
|
|||
|
|
break
|
|||
|
|
return (len(titles), cnt, asks, len(t), titles)
|
|||
|
|
|
|||
|
|
|
|||
|
|
def report(lecture, files):
|
|||
|
|
tot = {1: 0, 2: 0, 3: 0}
|
|||
|
|
allasks = []
|
|||
|
|
over = []
|
|||
|
|
print('=' * 62)
|
|||
|
|
print(lecture)
|
|||
|
|
print('=' * 62)
|
|||
|
|
for f in files:
|
|||
|
|
n, cnt, asks, chars, titles = analyze(f)
|
|||
|
|
if not n:
|
|||
|
|
continue
|
|||
|
|
allasks += asks
|
|||
|
|
for k in tot:
|
|||
|
|
tot[k] += cnt[k]
|
|||
|
|
flag = ' ⚠ 超 %d' % LIMIT if chars > LIMIT else ''
|
|||
|
|
multi = sum(1 for a in asks if a >= 1)
|
|||
|
|
print(' %-42s %2d题 %2d字符 多问%2d/%2d%s'
|
|||
|
|
% (os.path.basename(f)[:42], n, chars, multi, n, flag))
|
|||
|
|
if chars > LIMIT:
|
|||
|
|
over.append(os.path.basename(f))
|
|||
|
|
for h, a in zip(titles, asks):
|
|||
|
|
if a == 0:
|
|||
|
|
print(' · 单问题: %s' % h[:52])
|
|||
|
|
total = sum(tot.values())
|
|||
|
|
if not total:
|
|||
|
|
print(' (无题目)')
|
|||
|
|
return
|
|||
|
|
pct = lambda k: round(100 * tot[k] / total)
|
|||
|
|
print(' ' + '-' * 58)
|
|||
|
|
print(' 合计 %d 题 | ★☆☆ %d (%d%%) ★★☆ %d (%d%%) ★★★ %d (%d%%)'
|
|||
|
|
% (total, tot[1], pct(1), tot[2], pct(2), tot[3], pct(3)))
|
|||
|
|
if allasks:
|
|||
|
|
print(' 每道题小问数: 平均 %.1f | 单问 %d 题, 2问 %d 题, 3问+ %d 题'
|
|||
|
|
% (sum(allasks) / len(allasks),
|
|||
|
|
sum(1 for a in allasks if a == 0),
|
|||
|
|
sum(1 for a in allasks if a == 1),
|
|||
|
|
sum(1 for a in allasks if a >= 2)))
|
|||
|
|
if over:
|
|||
|
|
print(' ⚠ 超 13000 字符需拆分: ' + ', '.join(over))
|
|||
|
|
print()
|
|||
|
|
|
|||
|
|
|
|||
|
|
def main():
|
|||
|
|
args = sys.argv[1:]
|
|||
|
|
if not args:
|
|||
|
|
args = [os.path.join(BASE, d) for d in sorted(os.listdir(BASE))
|
|||
|
|
if d.startswith('线性代数-第') and os.path.isdir(os.path.join(BASE, d))]
|
|||
|
|
for a in args:
|
|||
|
|
target = a if os.path.isfile(a) or os.path.isdir(a) else os.path.join(BASE, a)
|
|||
|
|
if os.path.isfile(target):
|
|||
|
|
n, cnt, asks, chars, titles = analyze(target)
|
|||
|
|
print('%s' % os.path.basename(target))
|
|||
|
|
print(' %d 题, %d 字符%s' % (n, chars, ' ⚠ 超上限' if chars > LIMIT else ''))
|
|||
|
|
for h, q in zip(titles, asks):
|
|||
|
|
print(' %2d问 %s' % (q, h))
|
|||
|
|
continue
|
|||
|
|
files = sorted(os.path.join(target, f) for f in os.listdir(target)
|
|||
|
|
if re.match(r'^\d\d[^\d].*\.md$', f) and '速查' not in f and '盘点' not in f)
|
|||
|
|
report(os.path.basename(target.rstrip('/\\')), files)
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == '__main__':
|
|||
|
|
main()
|