cm-grade 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: cm_grade
3
+ Version: 1.0.0
4
+ Summary: 计算概论C课程成绩 CSV 分析和报告工具
5
+ Author: Chen Mo
6
+ Author-email: chenmoemail@126.com
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Natural Language :: Chinese (Simplified)
11
+ Classifier: Intended Audience :: Education
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # cm_grade
23
+
24
+ 成绩 CSV 分析和报告工具,适合文件、字典、排序之后做综合练习。
25
+
26
+ ```bash
27
+ pip install cm_grade
28
+ ```
29
+
30
+ ```python
31
+ import cm_grade
32
+
33
+ records = cm_grade.read_scores('成绩.csv')
34
+ print(cm_grade.summary(records))
35
+ print(cm_grade.rank_scores(records)[:5])
36
+
37
+ report = cm_grade.make_report(records)
38
+ cm_grade.save_report(report, '成绩报告.txt')
39
+ ```
@@ -0,0 +1,18 @@
1
+ # cm_grade
2
+
3
+ 成绩 CSV 分析和报告工具,适合文件、字典、排序之后做综合练习。
4
+
5
+ ```bash
6
+ pip install cm_grade
7
+ ```
8
+
9
+ ```python
10
+ import cm_grade
11
+
12
+ records = cm_grade.read_scores('成绩.csv')
13
+ print(cm_grade.summary(records))
14
+ print(cm_grade.rank_scores(records)[:5])
15
+
16
+ report = cm_grade.make_report(records)
17
+ cm_grade.save_report(report, '成绩报告.txt')
18
+ ```
@@ -0,0 +1,13 @@
1
+ """cm_grade - 成绩 CSV 分析和报告工具。"""
2
+
3
+ from .core import (
4
+ read_scores,
5
+ summary,
6
+ rank_scores,
7
+ score_bands,
8
+ make_report,
9
+ save_report,
10
+ )
11
+
12
+ __version__ = '1.0.0'
13
+ __all__ = ['read_scores', 'summary', 'rank_scores', 'score_bands', 'make_report', 'save_report']
@@ -0,0 +1,79 @@
1
+ import csv
2
+ from pathlib import Path
3
+ from statistics import mean, median
4
+
5
+
6
+ def read_scores(filename, name_col='姓名', score_col='成绩'):
7
+ """读取包含姓名和成绩两列的 CSV,返回 [{'姓名': ..., '成绩': ...}, ...]。"""
8
+ result = []
9
+ with open(filename, 'r', encoding='utf-8-sig', newline='') as f:
10
+ reader = csv.DictReader(f)
11
+ for row in reader:
12
+ if not row.get(name_col):
13
+ continue
14
+ result.append({'姓名': row[name_col], '成绩': float(row[score_col])})
15
+ return result
16
+
17
+
18
+ def _scores(records):
19
+ scores = [float(row['成绩']) for row in records]
20
+ if not scores:
21
+ raise ValueError('没有成绩数据')
22
+ return scores
23
+
24
+
25
+ def summary(records):
26
+ """计算平均分、中位数、最高分、最低分。"""
27
+ scores = _scores(records)
28
+ return {
29
+ '人数': len(scores),
30
+ '平均分': round(mean(scores), 2),
31
+ '中位数': round(median(scores), 2),
32
+ '最高分': max(scores),
33
+ '最低分': min(scores),
34
+ }
35
+
36
+
37
+ def rank_scores(records, reverse=True):
38
+ """按成绩排序并添加名次。"""
39
+ ordered = sorted(records, key=lambda row: float(row['成绩']), reverse=reverse)
40
+ return [{**row, '名次': index} for index, row in enumerate(ordered, start=1)]
41
+
42
+
43
+ def score_bands(records, bands=None):
44
+ """按分数段统计人数。"""
45
+ if bands is None:
46
+ bands = [(90, 100, '90-100'), (80, 89.999, '80-89'), (70, 79.999, '70-79'), (60, 69.999, '60-69'), (0, 59.999, '0-59')]
47
+ result = {label: 0 for _, _, label in bands}
48
+ for row in records:
49
+ score = float(row['成绩'])
50
+ for low, high, label in bands:
51
+ if low <= score <= high:
52
+ result[label] += 1
53
+ break
54
+ return result
55
+
56
+
57
+ def make_report(records):
58
+ """生成中文成绩分析报告。"""
59
+ s = summary(records)
60
+ bands = score_bands(records)
61
+ lines = [
62
+ '成绩分析报告',
63
+ f"人数:{s['人数']}",
64
+ f"平均分:{s['平均分']}",
65
+ f"中位数:{s['中位数']}",
66
+ f"最高分:{s['最高分']}",
67
+ f"最低分:{s['最低分']}",
68
+ '分数段统计:',
69
+ ]
70
+ lines.extend(f'{band}:{count} 人' for band, count in bands.items())
71
+ return '\n'.join(lines)
72
+
73
+
74
+ def save_report(report, filename):
75
+ """保存文字报告。"""
76
+ path = Path(filename)
77
+ path.parent.mkdir(parents=True, exist_ok=True)
78
+ path.write_text(report, encoding='utf-8')
79
+ return str(path)
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: cm_grade
3
+ Version: 1.0.0
4
+ Summary: 计算概论C课程成绩 CSV 分析和报告工具
5
+ Author: Chen Mo
6
+ Author-email: chenmoemail@126.com
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Natural Language :: Chinese (Simplified)
11
+ Classifier: Intended Audience :: Education
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # cm_grade
23
+
24
+ 成绩 CSV 分析和报告工具,适合文件、字典、排序之后做综合练习。
25
+
26
+ ```bash
27
+ pip install cm_grade
28
+ ```
29
+
30
+ ```python
31
+ import cm_grade
32
+
33
+ records = cm_grade.read_scores('成绩.csv')
34
+ print(cm_grade.summary(records))
35
+ print(cm_grade.rank_scores(records)[:5])
36
+
37
+ report = cm_grade.make_report(records)
38
+ cm_grade.save_report(report, '成绩报告.txt')
39
+ ```
@@ -0,0 +1,8 @@
1
+ README.md
2
+ setup.py
3
+ cm_grade/__init__.py
4
+ cm_grade/core.py
5
+ cm_grade.egg-info/PKG-INFO
6
+ cm_grade.egg-info/SOURCES.txt
7
+ cm_grade.egg-info/dependency_links.txt
8
+ cm_grade.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ cm_grade
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,20 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='cm_grade',
5
+ version='1.0.0',
6
+ author='Chen Mo',
7
+ author_email='chenmoemail@126.com',
8
+ description='计算概论C课程成绩 CSV 分析和报告工具',
9
+ long_description=open('README.md', encoding='utf-8').read(),
10
+ long_description_content_type='text/markdown',
11
+ packages=find_packages(),
12
+ python_requires='>=3.8',
13
+ classifiers=[
14
+ 'Programming Language :: Python :: 3',
15
+ 'License :: OSI Approved :: MIT License',
16
+ 'Operating System :: OS Independent',
17
+ 'Natural Language :: Chinese (Simplified)',
18
+ 'Intended Audience :: Education',
19
+ ],
20
+ )