feat: 基本完成对象系统更新
This commit is contained in:
@@ -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):
|
||||
self.ident = nucleon_obj["ident"] # type: ignore
|
||||
self.registry: AtomRegister = { # type: ignore
|
||||
"ident": nucleon_obj["ident"], # type: ignore
|
||||
"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 json
|
||||
from ...utils.lict import Lict
|
||||
from .refvar import RefVar
|
||||
|
||||
class Repo():
|
||||
file_mapping = {
|
||||
@@ -45,6 +44,7 @@ class Repo():
|
||||
def generate_particles_data(self):
|
||||
self.nucleonic_data_lict = Lict(initlist=list(map(self._attach(self.typedef), self.payload)))
|
||||
self.electronic_data_lict = self.algodata
|
||||
self.orbitic_data = self.schedule
|
||||
|
||||
@staticmethod
|
||||
def _attach(value):
|
||||
@@ -52,6 +52,12 @@ class Repo():
|
||||
return (x, value)
|
||||
return inner
|
||||
|
||||
@staticmethod
|
||||
def _merge(value):
|
||||
def inner(x):
|
||||
return map(x, value)
|
||||
return inner
|
||||
|
||||
def __len__(self):
|
||||
return len(self.payload)
|
||||
|
||||
@@ -104,7 +110,7 @@ class Repo():
|
||||
else:
|
||||
raise ValueError(f"不支持的文件类型: {filename}")
|
||||
if cls.type_mapping[keyname] == "lict":
|
||||
database[keyname] = Lict(loaded.items())
|
||||
database[keyname] = Lict(list(loaded.items()))
|
||||
elif cls.type_mapping[keyname] == "dict":
|
||||
database[keyname] = loaded
|
||||
else:
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
|
||||
from collections import UserList
|
||||
from typing import Any
|
||||
from typing import Any, Iterator
|
||||
|
||||
class Lict(UserList): #TODO: 优化同步(惰性同步), 当前性能为 O(n)
|
||||
""""列典" 对象
|
||||
|
||||
同时兼容字典和列表大多数 API, 两边数据同步的容器
|
||||
列表数据是 dictobj.items() 的格式
|
||||
支持根据字典或列表初始化
|
||||
@@ -12,25 +13,33 @@ class Lict(UserList): #TODO: 优化同步(惰性同步), 当前性能为 O(n)
|
||||
- 值一定是引用对象
|
||||
- 不使用并发
|
||||
- 不在乎列表顺序语义(严格按键名字符序排列)和列表索引查找, 因此外部的 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 = {}
|
||||
if initdict != None:
|
||||
initlist = list(initdict.items())
|
||||
super().__init__(initlist=initlist)
|
||||
self.forced_order = forced_order
|
||||
self._sync_based_on_list()
|
||||
self.data.sort()
|
||||
if self.forced_order:
|
||||
self.data.sort()
|
||||
|
||||
def _sync_based_on_dict(self):
|
||||
self.data = list(self.dicted_data.items())
|
||||
self.data.sort()
|
||||
if self.forced_order:
|
||||
self.data.sort()
|
||||
|
||||
def _sync_based_on_list(self):
|
||||
self.dicted_data = {}
|
||||
for i in self.data:
|
||||
self.dicted_data[i[0]] = i[1]
|
||||
|
||||
def __iter__(self) -> Iterator:
|
||||
return self.data.__iter__()
|
||||
|
||||
def __getitem__(self, i):
|
||||
if isinstance(i, str):
|
||||
return self.dicted_data[i]
|
||||
|
||||
Reference in New Issue
Block a user