Next init
This commit is contained in:
83
particles.py
Normal file
83
particles.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import pathlib
|
||||
import toml
|
||||
import time
|
||||
import copy
|
||||
import datetime
|
||||
import json
|
||||
|
||||
class Atom():
|
||||
"""原子: 由电子(分析数据)和核子(材料元数据)组成的反应(运行时)中间对象"""
|
||||
|
||||
class Electron():
|
||||
"""电子: 记忆分析数据及算法"""
|
||||
algorithm = "SM-2"
|
||||
"""
|
||||
origin = "陈情表" # 来源
|
||||
content = "" # 内容
|
||||
efactor = 2.5 # 易度系数, 越大越简单, 最大为5
|
||||
real_rept = 0 # (实际)重复次数
|
||||
rept = 0 # (有效)重复次数
|
||||
interval = 0 # 最佳间隔
|
||||
ept', last_date = 0 # 上一次复习的时间戳
|
||||
next_date = 0 # 将要复习的时间戳
|
||||
is_activated = 0 # 激活状态
|
||||
# *NOTE: 这里的"时间戳" 是以天为单位的整数, 即 UNIX 时间戳除以一天的秒数取整
|
||||
last_modify = 0 # 最后修改时间戳(此处是UNIX时间戳)
|
||||
"""
|
||||
def __init__(self, content: str, data: dict):
|
||||
self.content = content
|
||||
self.efactor = data.get('efactor', 2.5)
|
||||
self.real_rept = data.get('real_rept', 0)
|
||||
self.rept = data.get('rept', 0)
|
||||
self.interval = data.get('interval', 0)
|
||||
self.last_date = data.get('last_date', 0)
|
||||
self.next_date = data.get('next_date', 0)
|
||||
self.is_activated = data.get('is_activated', 0)
|
||||
self.last_modify = time.time()
|
||||
|
||||
def activate(self):
|
||||
self.is_activated = 1
|
||||
|
||||
def modify(self, var: str, value):
|
||||
setattr(self, var, value)
|
||||
self.last_modify = time.time()
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.content)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def import_from_file(path: pathlib.Path):
|
||||
name = path.name.replace(path.suffix, "")
|
||||
with open(path, 'r') as f:
|
||||
all = toml.load(f)
|
||||
lst = list()
|
||||
for i in all.keys():
|
||||
lst.append(Electron(i, all[i]))
|
||||
return (name, lst)
|
||||
@staticmethod
|
||||
def save_to_file(electron_list, path: pathlib.Path):
|
||||
with open(path, 'w') as f:
|
||||
toml.dump(electron_list, f)
|
||||
|
||||
class Nucleon():
|
||||
"""核子: 材料元数据"""
|
||||
def __init__(self, content: str, data: dict):
|
||||
self.metadata = data
|
||||
self.content = content
|
||||
|
||||
@staticmethod
|
||||
def import_from_file(path: pathlib.Path):
|
||||
name = path.name.replace(path.suffix, "")
|
||||
with open(path, 'r') as f:
|
||||
all = toml.load(f)
|
||||
lst = list()
|
||||
for i in all.keys():
|
||||
lst.append(Nucleon(i, all[i]))
|
||||
return (name, lst)
|
||||
|
||||
@staticmethod
|
||||
def save_to_file(nucleon_list, path: pathlib.Path):
|
||||
with open(path, 'w') as f:
|
||||
toml.dump(nucleon_list, f)
|
||||
|
Reference in New Issue
Block a user