[toc]
## 效果預覽
#### 生成測試文件

#### 文件內容

#### 同學填寫完后的內容

#### 批改單詞

#### 單詞批改結果

## 升級信息
相比于 1.0, 升級如下:
1. 支持并行操作, 1.0 版本一次只能一個同學, 一次提問`10`個單詞/次, 共計耗時`45`分鐘.
2. 2.0 版本, 可以所有同學同時進行, `50`個單詞/次, 共計耗時`20`分鐘.
3. 1.0 版本需要很多支持, php, 數據庫, apache, layui. 2.0 版本只需要兩個, python 和 svn
4. 使用方便, 直接運行 python 文件即可
## 文件說明
1. `index.py` 生成單詞測試文件, 每個同學 50 個單詞, 相鄰同學的單詞各不相同.
2. `check.py` 單詞批改文件, 可以生成批改結果`checkRes.txt`文件
3. 通過 svn 把測試文件發給同學們, 同學們寫完之后, 通過 svn 提交
4. 每天的批改結果(`checkRes.txt`), 也可以通過 svn 分享給大家
## 使用方式
1. `python index.py`, 生成單詞測試文件
2. 通過 svn 共享給同學們
3. 同學們完成單詞并提交
4. 老師更新 svn 并批改(`python check.py`)
5. 把批改的文件加上當天日期, 通過 svn 發給同學們
## Python 源碼
#### index.py
```python
# coding=utf-8
import random
words = [
'compare',
'Fn',
'interchange',
'standard',
'information',
'info',
'ASCII',
'parse',
'Integer',
'Float',
'function',
'extension',
'language',
'default',
'browser',
'variable',
'console',
'arguments',
'break',
'catch',
'class',
'constant',
'continue',
'type',
'unexpected',
'document',
'identifier',
'model',
'current',
'computed',
'plus',
'multiply',
'snippet',
'prefix',
'description',
'result',
'divide',
'square root',
'math',
'method',
'minus',
'param',
'length',
'concat',
'separator',
'shift',
'insert',
'slice',
'sort',
'splice',
'lower',
'pretty',
'format',
'negative',
'negative infinity',
'upper',
'Infinity',
'brown',
'lazy',
'reference',
'positive',
'positive infinity',
'statement',
'syntax',
'score',
'illegal',
'property',
'defer',
'instance',
'global',
'static',
'declare',
'active',
'clipboard',
'declaration',
'hoisting',
'factorial',
'range',
'maximum',
'call',
'stack',
'queue',
'heap',
'exceeded',
'overflow',
'prompt',
'confirm',
'tick',
'interval',
'timeout',
'uniform',
'resource',
'collection',
'foreach',
'area',
'map',
'rectangular',
'coords',
'undescribable',
'ignore',
'Iterator',
'split',
'toggle',
'previous',
'prev',
'equal',
'attribute',
'odd',
'even',
'visible',
'onload',
'device-width',
'viewport',
'initial-scale',
'compatible',
'filter',
'query',
'next',
'parent',
'meta-information',
'index',
'remove',
'append',
'prepend',
'scroll',
'create',
'resize',
'cursor',
'pointer',
'offset',
'target',
'trigger',
'event',
'client',
'hover',
'display',
'fadeIn',
'fadeOut',
'slide',
'fade',
'detach',
'sibling',
'wrap',
'unwrap',
'serialize',
'animate',
'swing',
'linear',
'delegate',
'undelegate',
'compress',
'container',
'task',
'item',
'vertical',
'align',
'current',
'focus',
'outline',
'drop',
'shadow',
'drop-shadow',
'transition',
'delay',
'inset',
'keypress',
'keyCode',
'storage',
'local',
'localStorage',
'stringify',
'through',
'decoration',
'text-decoration',
'line-through',
'content',
'notation',
'collection',
'an ordered list',
'associative',
'associative array',
'record',
'struct',
'dictionary',
'hash',
'employees',
'tips',
'stopPropagation',
'preventDefault',
'entry/entries',
'search',
'find',
'regular',
'expression',
'match',
'replace',
'create',
'update',
'retrieve',
'delete',
'alter',
'pattern',
'engine',
'primary',
'unique',
'column',
'affected',
'average',
'count',
'distinct',
'descend',
'desc',
'repository',
'initialize',
'status',
'difference',
'graph',
'staged',
'remote',
'master',
'untracked',
'branch',
'bugFix',
'merge',
'issue',
'stash',
'feature',
'secure',
'safe',
'path',
'set',
'warning',
'mixed',
'label'
]
words = list(set(words))
students = [
'耿澤陽',
'尚國強',
'吳雨陽',
'賈方園',
'岳風華',
'邱俊鴿',
'趙海成',
'姚林佳',
'周鑫鑫',
'李宏剛',
'路寬闊',
'徐曉航',
'康瑞植',
'李亞南',
'宋姝瑩',
'劉余先',
'徐帥',
'成龍龍',
'孫巖濤',
'周蕭',
'鄭彬彬',
'耿富源',
'李攀登'
]
new_words = []
for i in students:
file_obj = open(i+".txt", 'w+')
student_words = []
while len(student_words) < 50:
if not len(words):
words = new_words
new_words = []
y = random.randint(0, len(words)-1)
if words[y] not in student_words:
if len(student_words) is 49:
file_obj.write(words[y]+' ===> ')
else:
file_obj.write(words[y]+' ===> '+"\n")
new_words.append(words[y])
student_words.append(words[y])
words.remove(words[y])
file_obj.close()
print("\"%s\" 同學的單詞列表, 已經生成!" % i)
```
#### check.py
```python
# coding=utf-8
import chardet
import os
word_dict = {
'compare': '比較/對比/代碼對比/代碼比較',
'fn': '函數縮寫/function縮寫/方法縮寫',
'interchange': '交換',
'standard': '標準/標準化',
'information': '信息',
'info': '信息縮寫/information縮寫',
'ascii': '美國信息交換標準代碼',
'parse': '分析/解析',
'integer': '整數/整型/整型',
'float': '浮點數/浮動',
'function': '函數/方法',
'extension': '擴展/插件',
'language': '語言',
'default': '默認',
'browser': '瀏覽器',
'variable': '變量/可變的',
'console': '控制臺',
'arguments': '參數',
'break': '中斷',
'catch': '捕獲',
'class': '類',
'constant': '常量/常數',
'continue': '繼續/跳過當前循環',
'type': '類別/類型',
'unexpected': '不符合期望的/未符合期望的',
'document': '文檔',
'identifier': '標識符',
'model': '模型',
'current': '當前的',
'computed': '計算/經過計算的',
'plus': '加法/相加',
'multiply': '乘法/相乘',
'snippet': '代碼段',
'prefix': '前綴',
'description': '描述/描寫',
'result': '結果',
'divide': '除法/相除',
'square root': '開方/開平方根',
'math': '數學',
'method': '方法/函數',
'minus': '減法/相減',
'param': '參數',
'length': '長度/數組長度/字符串長度',
'concat': '合并',
'separator': '分隔符',
'shift': '移位/移出/移除/刪除',
'insert': '插入',
'slice': '切片/數組切片/字符串切片',
'sort': '排序/排列',
'splice': '拼接/接合',
'lower': '小寫',
'pretty': '可愛的',
'format': '格式化',
'negative': '消極的',
'negative infinity': '負無窮',
'upper': '大寫',
'infinity': '無窮/無限',
'brown': '棕色的',
'lazy': '懶惰的',
'reference': '引用',
'positive': '積極地',
'positive infinity': '正無窮',
'statement': '語句',
'syntax': '語法',
'score': '分數/得分/成績',
'illegal': '非法的',
'property': '屬性',
'defer': '延遲',
'instance': '實例',
'global': '全局的',
'static': '靜態/靜態的',
'declare': '聲明',
'active': '活動的/積極地/活躍的',
'clipboard': '剪切板/粘貼板/剪貼板',
'declaration': '聲明',
'hoisting': '提升',
'factorial': '階乘',
'range': '范圍/幅度',
'maximum': '最大值',
'call': '調用',
'stack': '棧',
'queue': '隊列',
'heap': '堆',
'exceeded': '超越/超過/超出/越出',
'overflow': '溢出',
'prompt': '提示',
'confirm': '確認',
'tick': '滴答/滴答聲',
'interval': '間隔/間距',
'timeout': '超時/延遲',
'uniform': '統一/統一的',
'resource': '資源',
'collection': '收集/集合',
'foreach': '循環/數組循環/數組遍歷/遍歷數組',
'area': '區域/面積/范圍',
'map': '映射',
'rectangular': '矩形/矩形的',
'coords': '坐標',
'undescribable': '不可描述的/難以描述的',
'ignore': '忽視/忽略',
'iterator': '迭代器',
'split': '分割/分解/',
'toggle': '開關/切換',
'previous': '上一個/前一個',
'prev': '上一個的縮寫/前一個的縮寫/previous的縮寫/前一個縮寫',
'equal': '相等',
'attribute': '屬性',
'odd': '奇數的',
'even': '偶數的',
'visible': '可見的/可見性',
'onload': '裝載/加載',
'device-width': '設備寬度',
'viewport': '觀察口/視窗口/瀏覽器視窗',
'initial-scale': '初始縮放值/初始縮放值',
'compatible': '兼容性/兼容的',
'filter': '過濾器',
'query': '查詢',
'next': '下一個/下個',
'parent': '父級/上層/上級',
'meta-information': '元信息',
'index': '索引',
'remove': '移除/刪除',
'append': '追加/后加/后插/附加',
'prepend': '前面追加/前加/前插',
'scroll': '滾動/卷軸/屏幕滾動',
'create': '創造/新建',
'resize': '調整大小/設置大小',
'cursor': '光標/游標',
'pointer': '指針',
'offset': '位移/移位',
'target': '目標',
'trigger': '觸發器/扳機',
'event': '事件',
'client': '客戶端/機',
'hover': '懸停/懸停',
'display': '展示/顯示',
'fadein': '淡入',
'fadeout': '淡出',
'slide': '滑動',
'fade': '平淡的',
'detach': '分離',
'sibling': '兄弟姐妹/同胞/兄弟姊妹',
'wrap': '包裹/包裝',
'unwrap': '打開/解包裝',
'serialize': '串行化/字符串化',
'animate': '動畫',
'swing': '振幅',
'linear': '線性的',
'delegate': '代理/事件委托',
'undelegate': '阻止代理/阻止事件委托',
'compress': '壓縮',
'container': '容器',
'task': '任務/工作/作業/項目',
'item': '項目/一項',
'vertical': '垂直的',
'align': '對齊',
'current': '當前',
'focus': '焦點/使聚焦',
'outline': '輪廓',
'drop': '下落',
'shadow': '陰影',
'drop-shadow': '下落式陰影',
'transition': '過渡/轉變/轉換',
'delay': '延遲/延期/推遲/',
'inset': '嵌入式/插入/內陰影',
'keypress': '按鍵響應/鍵盤事件',
'keycode': '鍵碼/按鍵序列號/按鍵值',
'storage': '存儲/緩存',
'local': '本地',
'localstorage': '本地存儲/本地儲存/本地緩存',
'stringify': '字符串化',
'through': '穿過/透過',
'decoration': '裝飾/修飾',
'text-decoration': '文本裝飾/文本修飾',
'line-through': '刪除線/中劃線',
'content': '內容',
'notation': '表示法',
'collection': '集合',
'an ordered list': '有序列表',
'associative': '關聯',
'associative array': '關聯數組',
'record': '記錄',
'struct': '結構',
'dictionary': '字典',
'hash': '哈希表',
'employees': '雇員/員工',
'tips': '貼士/提示框',
'stoppropagation': '停止冒泡/阻止冒泡',
'preventdefault': '阻止默認事件/阻止默認行為',
'entry/entries': '進入/入口/項目',
'search': '查找/查詢/搜索/搜尋/搜查',
'find': '查找/查詢',
'regular': '正則',
'expression': '表達式',
'match': '匹配/相配',
'replace': '替換/更換',
'create': '新增/新建/增加',
'update': '更新',
'retrieve': '讀取/查詢',
'delete': '刪除',
'alter': '改變/更改',
'pattern': '匹配模式',
'engine': '數據庫引擎 ',
'primary': '主要的',
'primary key': '主鍵',
'unique': '唯一性',
'column': '列/字段',
'affected': '受影響的',
'average': '平均/平均數',
'count': '計數',
'distinct': '不同的(用于去重)/數據去重',
'descend': '下降',
'desc': '降序排序',
'repository': '倉庫',
'initialize': '初始化',
'status': '狀態',
'difference': '差異',
'graph': '圖形',
'staged': '(已放入)暫存區',
'remote': '遠程',
'master': '主要的',
'untracked': '未追蹤/未跟蹤',
'branch': '分支',
'bugfix': 'bug修復',
'merge': '合并',
'issue': '問題',
'stash': '暫存/隱藏',
'feature': '功能/特性',
'secure': '安全的',
'safe': '安全',
'path': '路徑',
'set': '設置',
'warning': '警告',
'mixed': '混合(類型)',
'label': '標簽',
'notice': '提示'
}
students = [
'耿澤陽',
'尚國強',
'吳雨陽',
'賈方園',
'岳風華',
'邱俊鴿',
'趙海成',
'姚林佳',
'周鑫鑫',
'李宏剛',
'路寬闊',
'徐曉航',
'康瑞植',
'李亞南',
'宋姝瑩',
'劉余先',
'徐帥',
'成龍龍',
'孫巖濤',
'周蕭',
'鄭彬彬',
'耿富源',
'李攀登'
]
resObj = open('checkRes.txt', 'w+', encoding='utf-8')
for student in students:
check_str = ""
wrong_words = 0
total_words = 0
final_res = ""
not_enough = ""
white = ""
good = ""
if not os.path.exists(student+'.txt'):
print('\n天哪!!! \"'+student+"\" 同學, 你還沒有交啊...\n\n")
else:
encoding1 = chardet.detect(open(student+".txt", "rb").read())['encoding']
# print(encoding1)
fileObj = open(student+'.txt', "r", encoding=encoding1)
for word_line in fileObj.readlines():
if "===>" in word_line:
total_words = total_words+1
tmpList = word_line.split('===>')
current_en = tmpList[0].strip()
current_zh = tmpList[1].strip()
if current_zh:
if current_zh[-1] == "的" or current_zh[-1] == "地" or current_zh[-1] == "得":
current_zh = current_zh[:-1]
word_real = word_dict[current_en.lower()]
if current_zh not in word_real or not current_zh:
wrong_words = wrong_words+1
check_str = check_str+current_en+" ===> "+current_zh+" ===> "+word_real+"\n"
if total_words < 50:
not_enough = "\n什么情況?"+str(total_words)+"個? 單詞量不夠啊?"
if wrong_words == total_words:
white = "\n天哪, 你這是交了白卷嗎?\n\n"
if not wrong_words and total_words:
good = "\n全對了, 太牛逼了!!!\n\n"
final_res = "\""+student+"\" 同學的單詞成績:"+str(total_words-wrong_words)+"/"+str(total_words)+"\n\n"
print(final_res)
final_res = final_res+check_str
if not_enough:
final_res = final_res+not_enough
if white:
final_res = final_res+white
if good and not not_enough:
final_res = final_res+good
resObj.write(final_res+"\n")
resObj.close()
```