-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
64 lines (49 loc) · 1.67 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
class Word:
def __init__(self, name='', phonetic='', interp=''):
self.name = name
self.phonetic = phonetic
self.interp = interp
class ReciteRecord:
def __init__(self, wordName='', startTime=0, lastTime=0, stage=0, strange=0):
self.wordName = wordName
self.startTime = startTime
self.lastTime = lastTime
self.stage = stage
self.strange = strange
import time
class Ebbinghaus:
forgettingCurve = (
5, # 5分钟
30, # 30分钟
12*60, # 12小时
1*24*60, # 1天
2*24*60, # 2天
4*24*60, # 4天
7*24*60, # 7天
15*24*60, # 15天
)
def __init__(self, records):
self.records = records
self.neeReciteWords = []
# 根据记忆曲线,判断单词是否需要复习
def needRecite(self, record):
return self.isExpire(record)
def isExpire(self, record):
# 记忆曲线完成
# record.stage == 8
# len(forgettingCurve) == 8
if record.stage >= len(self.forgettingCurve):
return False
currentTime = time.time()
timeDiff = (currentTime - record.lastTime) / 60 # 将单位从秒转换为分钟
if timeDiff > self.forgettingCurve[record.stage]:
return True
else:
return False
def getNeedReciteWords(self):
self.neeReciteWords = []
for record in self.records:
if self.needRecite(record):
self.neeReciteWords.append(record)
return self.neeReciteWords