feat: 基本完成对象系统更新
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
schedule = ["quick_review", "recognition", "final_review"]
|
||||||
|
[phases]
|
||||||
quick_review = [["FillBlank", "1.0"], ["SelectMeaning", "0.5"], ["Recognition", "1.0"]]
|
quick_review = [["FillBlank", "1.0"], ["SelectMeaning", "0.5"], ["Recognition", "1.0"]]
|
||||||
recognition = [["Recognition", "1.0"]]
|
recognition = [["Recognition", "1.0"]]
|
||||||
final_review = [["FillBlank", "0.7"], ["SelectMeaning", "0.7"], ["Recognition", "1.0"]]
|
final_review = [["FillBlank", "0.7"], ["SelectMeaning", "0.7"], ["Recognition", "1.0"]]
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
from .atom import Atom
|
||||||
|
from .electron import Electron
|
||||||
|
from .nucleon import Nucleon
|
||||||
|
from .orbital import Orbital
|
||||||
@@ -40,6 +40,7 @@ class Atom:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, nucleon_obj = None, electron_obj = None, orbital_obj = None):
|
def __init__(self, nucleon_obj = None, electron_obj = None, orbital_obj = None):
|
||||||
|
self.ident = nucleon_obj["ident"] # type: ignore
|
||||||
self.registry: AtomRegister = { # type: ignore
|
self.registry: AtomRegister = { # type: ignore
|
||||||
"ident": nucleon_obj["ident"], # type: ignore
|
"ident": nucleon_obj["ident"], # type: ignore
|
||||||
"nucleon": nucleon_obj,
|
"nucleon": nucleon_obj,
|
||||||
|
|||||||
14
src/heurams/kernel/particles/orbital.py
Normal file
14
src/heurams/kernel/particles/orbital.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from heurams.utils.lict import Lict
|
||||||
|
from heurams.utils.evalizor import Evalizer
|
||||||
|
|
||||||
|
class Orbital():
|
||||||
|
@classmethod
|
||||||
|
def create_orbital(cls, schedule: list, phase_def: dict):
|
||||||
|
phase_def = Lict(initdict=phase_def) # type: ignore
|
||||||
|
orbital = Lict()
|
||||||
|
for i in schedule:
|
||||||
|
orbital[i] = Lict(phase_def[i])
|
||||||
|
return orbital
|
||||||
|
@classmethod
|
||||||
|
def create_orbital_on_orbitic_data(cls, orbitic_data):
|
||||||
|
return cls.create_orbital(orbitic_data["schedule"], orbitic_data["phases"])
|
||||||
@@ -4,7 +4,6 @@ import heurams.kernel.particles as pt
|
|||||||
import toml
|
import toml
|
||||||
import json
|
import json
|
||||||
from ...utils.lict import Lict
|
from ...utils.lict import Lict
|
||||||
from .refvar import RefVar
|
|
||||||
|
|
||||||
class Repo():
|
class Repo():
|
||||||
file_mapping = {
|
file_mapping = {
|
||||||
@@ -45,6 +44,7 @@ class Repo():
|
|||||||
def generate_particles_data(self):
|
def generate_particles_data(self):
|
||||||
self.nucleonic_data_lict = Lict(initlist=list(map(self._attach(self.typedef), self.payload)))
|
self.nucleonic_data_lict = Lict(initlist=list(map(self._attach(self.typedef), self.payload)))
|
||||||
self.electronic_data_lict = self.algodata
|
self.electronic_data_lict = self.algodata
|
||||||
|
self.orbitic_data = self.schedule
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _attach(value):
|
def _attach(value):
|
||||||
@@ -52,6 +52,12 @@ class Repo():
|
|||||||
return (x, value)
|
return (x, value)
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _merge(value):
|
||||||
|
def inner(x):
|
||||||
|
return map(x, value)
|
||||||
|
return inner
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.payload)
|
return len(self.payload)
|
||||||
|
|
||||||
@@ -104,7 +110,7 @@ class Repo():
|
|||||||
else:
|
else:
|
||||||
raise ValueError(f"不支持的文件类型: {filename}")
|
raise ValueError(f"不支持的文件类型: {filename}")
|
||||||
if cls.type_mapping[keyname] == "lict":
|
if cls.type_mapping[keyname] == "lict":
|
||||||
database[keyname] = Lict(loaded.items())
|
database[keyname] = Lict(list(loaded.items()))
|
||||||
elif cls.type_mapping[keyname] == "dict":
|
elif cls.type_mapping[keyname] == "dict":
|
||||||
database[keyname] = loaded
|
database[keyname] = loaded
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
from collections import UserList
|
from collections import UserList
|
||||||
from typing import Any
|
from typing import Any, Iterator
|
||||||
|
|
||||||
class Lict(UserList): #TODO: 优化同步(惰性同步), 当前性能为 O(n)
|
class Lict(UserList): #TODO: 优化同步(惰性同步), 当前性能为 O(n)
|
||||||
""""列典" 对象
|
""""列典" 对象
|
||||||
|
|
||||||
同时兼容字典和列表大多数 API, 两边数据同步的容器
|
同时兼容字典和列表大多数 API, 两边数据同步的容器
|
||||||
列表数据是 dictobj.items() 的格式
|
列表数据是 dictobj.items() 的格式
|
||||||
支持根据字典或列表初始化
|
支持根据字典或列表初始化
|
||||||
@@ -13,17 +14,22 @@ class Lict(UserList): #TODO: 优化同步(惰性同步), 当前性能为 O(n)
|
|||||||
- 不使用并发
|
- 不使用并发
|
||||||
- 不在乎列表顺序语义(严格按键名字符序排列)和列表索引查找, 因此外部的 sort, index 等功能不可用
|
- 不在乎列表顺序语义(严格按键名字符序排列)和列表索引查找, 因此外部的 sort, index 等功能不可用
|
||||||
- append 的元组中, 表示键名的元素不能重复, 否则会导致覆盖行为
|
- append 的元组中, 表示键名的元素不能重复, 否则会导致覆盖行为
|
||||||
|
|
||||||
|
只有在 Python 3.7+ 中, forced_order 行为才能被取消.
|
||||||
"""
|
"""
|
||||||
def __init__(self, initlist = None, initdict = None):
|
def __init__(self, initlist: list | None = None, initdict: dict | None = None, forced_order = True):
|
||||||
self.dicted_data = {}
|
self.dicted_data = {}
|
||||||
if initdict != None:
|
if initdict != None:
|
||||||
initlist = list(initdict.items())
|
initlist = list(initdict.items())
|
||||||
super().__init__(initlist=initlist)
|
super().__init__(initlist=initlist)
|
||||||
|
self.forced_order = forced_order
|
||||||
self._sync_based_on_list()
|
self._sync_based_on_list()
|
||||||
|
if self.forced_order:
|
||||||
self.data.sort()
|
self.data.sort()
|
||||||
|
|
||||||
def _sync_based_on_dict(self):
|
def _sync_based_on_dict(self):
|
||||||
self.data = list(self.dicted_data.items())
|
self.data = list(self.dicted_data.items())
|
||||||
|
if self.forced_order:
|
||||||
self.data.sort()
|
self.data.sort()
|
||||||
|
|
||||||
def _sync_based_on_list(self):
|
def _sync_based_on_list(self):
|
||||||
@@ -31,6 +37,9 @@ class Lict(UserList): #TODO: 优化同步(惰性同步), 当前性能为 O(n)
|
|||||||
for i in self.data:
|
for i in self.data:
|
||||||
self.dicted_data[i[0]] = i[1]
|
self.dicted_data[i[0]] = i[1]
|
||||||
|
|
||||||
|
def __iter__(self) -> Iterator:
|
||||||
|
return self.data.__iter__()
|
||||||
|
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
if isinstance(i, str):
|
if isinstance(i, str):
|
||||||
return self.dicted_data[i]
|
return self.dicted_data[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user