fix: 修复 Lict 问题
This commit is contained in:
@@ -12,7 +12,7 @@ for i in repo.ident_index:
|
||||
n = pt.Nucleon.from_data(nucleonic_data=repo.nucleonic_data_lict.get_itemic_unit(i))
|
||||
e = pt.Electron.from_data(
|
||||
electronic_data=repo.electronic_data_lict.get_itemic_unit(i),
|
||||
algo_name=repo.config['algorithm']
|
||||
algo_name=repo.config["algorithm"],
|
||||
)
|
||||
print(n)
|
||||
input()
|
||||
|
||||
@@ -35,8 +35,8 @@ class DashboardScreen(Screen):
|
||||
("q", "go_back", "返回"),
|
||||
]
|
||||
|
||||
CSS_PATH = Path(__file__).parent.parent / 'css' / "screens" / "dashboard.tcss"
|
||||
|
||||
CSS_PATH = Path(__file__).parent.parent / "css" / "screens" / "dashboard.tcss"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str | None = None,
|
||||
@@ -109,7 +109,10 @@ class DashboardScreen(Screen):
|
||||
}
|
||||
initial_time = float("inf")
|
||||
for i in range(repo.data_length):
|
||||
e = pt.Electron.from_data(electronic_data=repo.electronic_data_lict[i], algo_name=repo.config['algorithm'])
|
||||
e = pt.Electron.from_data(
|
||||
electronic_data=repo.electronic_data_lict[i],
|
||||
algo_name=repo.config["algorithm"],
|
||||
)
|
||||
n = pt.Nucleon.from_data(repo.nucleonic_data_lict[i])
|
||||
if e.is_activated():
|
||||
repo.progress["have_activated_ever"] = 1
|
||||
|
||||
@@ -48,9 +48,7 @@ class PreparationScreen(Screen):
|
||||
yield Header(show_clock=True)
|
||||
with ScrollableContainer(id="vice_container"):
|
||||
yield Label(f"准备就绪: [b]{self.repo.manifest['title']}[/b]\n")
|
||||
yield Label(
|
||||
f"[b]仓库路径: {self.repo.source}[/b]"
|
||||
)
|
||||
yield Label(f"[b]仓库路径: {self.repo.source}[/b]")
|
||||
yield Label(f"\n单元数量: {len(self.repo)}\n")
|
||||
yield Label(f"最小记忆分组: {self.scheduled_num}\n", id="schnum_label")
|
||||
|
||||
@@ -93,7 +91,7 @@ class PreparationScreen(Screen):
|
||||
)
|
||||
e = pt.Electron.from_data(
|
||||
electronic_data=self.repo.electronic_data_lict.get_itemic_unit(i),
|
||||
algo_name=self.repo.config['algorithm']
|
||||
algo_name=self.repo.config["algorithm"],
|
||||
)
|
||||
statstr = ""
|
||||
|
||||
@@ -148,7 +146,7 @@ def launch(repo, app, scheduled_num):
|
||||
)
|
||||
e = pt.Electron.from_data(
|
||||
electronic_data=repo.electronic_data_lict.get_itemic_unit(i),
|
||||
algo_name=repo.config['algorithm']
|
||||
algo_name=repo.config["algorithm"],
|
||||
)
|
||||
a = pt.Atom(n, e, repo.orbitic_data)
|
||||
atoms.append(a)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# 已弃用
|
||||
from collections import UserList
|
||||
from typing import Any, Iterator
|
||||
|
||||
@@ -2,23 +2,36 @@ from collections.abc import MutableSequence
|
||||
from typing import Any, Iterator, Optional
|
||||
|
||||
class Lict(MutableSequence):
|
||||
|
||||
def __init__(self, initlist: Optional[list] = None,
|
||||
""" "列典" 对象
|
||||
|
||||
同时兼容字典和列表大多数 API, 两边数据同步的容器, 性能与 list/dict 大体相当
|
||||
列表数据是 dictobj.items() 的格式
|
||||
支持根据字典或列表初始化
|
||||
限制要求:
|
||||
- 键名一定唯一, 且仅能为字符串
|
||||
- append 的元组中, 表示键名的元素不能重复, 否则会导致覆盖行为
|
||||
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
initlist: Optional[list] = None,
|
||||
initdict: Optional[dict] = None,
|
||||
forced_order: bool = False):
|
||||
forced_order: bool = False,
|
||||
):
|
||||
self._dict = {}
|
||||
self._list = []
|
||||
self._dict_dirty = False
|
||||
self._list_dirty = False
|
||||
self.forced_order = forced_order
|
||||
|
||||
if initdict: # initdict 更优先
|
||||
|
||||
if initdict: # initdict 更优先
|
||||
self._dict = initdict.copy()
|
||||
self._list_dirty = True
|
||||
elif initlist:
|
||||
self._list = initlist.copy()
|
||||
self._dict_dirty = True
|
||||
|
||||
|
||||
self._sync_if_needed()
|
||||
|
||||
def _sync_if_needed(self):
|
||||
@@ -28,20 +41,20 @@ class Lict(MutableSequence):
|
||||
if self.forced_order:
|
||||
self._list.sort()
|
||||
self._dict_dirty = False
|
||||
|
||||
|
||||
if self._list_dirty:
|
||||
self._list = list(self._dict.items())
|
||||
if self.forced_order:
|
||||
self._list.sort()
|
||||
self._list_dirty = False
|
||||
|
||||
|
||||
def __getitem__(self, key):
|
||||
if isinstance(key, str):
|
||||
return self._dict[key]
|
||||
else:
|
||||
self._sync_if_needed()
|
||||
return self._list[key]
|
||||
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
"""传入键值对时等同于操作字典, 传入索引+元组时等用于替换某索引的列表值为新元组"""
|
||||
if isinstance(key, str):
|
||||
@@ -54,34 +67,34 @@ class Lict(MutableSequence):
|
||||
old_key = self._list[key][0]
|
||||
self._dict.pop(old_key)
|
||||
self._list[key] = value
|
||||
self._dict[value[0]] = value[1] # 避免全量同步
|
||||
self._dict[value[0]] = value[1] # 避免全量同步
|
||||
|
||||
def __delitem__(self, key):
|
||||
if isinstance(key, str): # 字符串键
|
||||
if isinstance(key, str): # 字符串键
|
||||
del self._dict[key]
|
||||
self._list_dirty = True
|
||||
else: # 数字索引
|
||||
else: # 数字索引
|
||||
self._sync_if_needed()
|
||||
del_key = self._list[key][0]
|
||||
del self._list[key]
|
||||
del self._dict[del_key]
|
||||
|
||||
|
||||
def keys(self):
|
||||
self._sync_if_needed()
|
||||
return self._dict.keys()
|
||||
|
||||
|
||||
def values(self):
|
||||
self._sync_if_needed()
|
||||
return self._dict.values()
|
||||
|
||||
|
||||
def items(self):
|
||||
self._sync_if_needed()
|
||||
return self._list
|
||||
|
||||
|
||||
def __len__(self):
|
||||
self._sync_if_needed()
|
||||
return len(self._list)
|
||||
|
||||
|
||||
def __iter__(self):
|
||||
self._sync_if_needed()
|
||||
return iter(self._list)
|
||||
@@ -89,24 +102,24 @@ class Lict(MutableSequence):
|
||||
def __contains__(self, item):
|
||||
self._sync_if_needed()
|
||||
return item in self._list or item in self.keys() or item in self.values()
|
||||
|
||||
|
||||
def append(self, item):
|
||||
if item != (item[0], item[1]):
|
||||
raise NotImplementedError
|
||||
self._sync_if_needed() # 以防 forced_order
|
||||
self._sync_if_needed() # 以防 forced_order
|
||||
key, value = item
|
||||
self._dict[key] = value
|
||||
self._list.append(item) # 两端都已同步
|
||||
self._sync_if_needed() # 以防 forced_order
|
||||
self._list.append(item) # 两端都已同步
|
||||
self._sync_if_needed() # 以防 forced_order
|
||||
|
||||
def append_if_it_donesnt_exist_before(self, item: Any):
|
||||
def append_if_it_doesnt_exist_before(self, item: Any):
|
||||
if item != (item[0], item[1]):
|
||||
raise NotImplementedError
|
||||
self._sync_if_needed()
|
||||
if item[0] not in self:
|
||||
super().append(item)
|
||||
self.append(item)
|
||||
self._sync_if_needed()
|
||||
|
||||
|
||||
def insert(self, i: int, item: Any) -> None:
|
||||
if item != (item[0], item[1]):
|
||||
raise NotImplementedError
|
||||
@@ -147,18 +160,6 @@ class Lict(MutableSequence):
|
||||
def reverse(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def keys(self):
|
||||
self._sync_if_needed()
|
||||
return self._dict.keys()
|
||||
|
||||
def values(self):
|
||||
self._sync_if_needed()
|
||||
return self._dict.values()
|
||||
|
||||
def items(self):
|
||||
self._sync_if_needed()
|
||||
return self._list
|
||||
|
||||
def get_itemic_unit(self, ident):
|
||||
return (ident, self._dict[ident])
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# 已弃用
|
||||
class RefVar:
|
||||
def __init__(self, initvalue) -> None:
|
||||
self.data = initvalue
|
||||
@@ -64,11 +64,11 @@ class Repo:
|
||||
"source": self.source,
|
||||
}
|
||||
self.config = {
|
||||
"algorithm": config_var.get()['interface']['global']['algorithm'],
|
||||
"scheduled_num": config_var.get()['interface']['global']['scheduled_num'],
|
||||
"algorithm": config_var.get()["interface"]["global"]["algorithm"],
|
||||
"scheduled_num": config_var.get()["interface"]["global"]["scheduled_num"],
|
||||
}
|
||||
try:
|
||||
self.config.update(dict(config_var.get()['repo'][self.manifest['package']]))
|
||||
self.config.update(dict(config_var.get()["repo"][self.manifest["package"]]))
|
||||
except:
|
||||
pass
|
||||
self._generate_particles_data()
|
||||
@@ -82,7 +82,7 @@ class Repo:
|
||||
self.data_length = len(self.nucleonic_data_lict)
|
||||
self.ident_index = self.nucleonic_data_lict.keys()
|
||||
for i in self.ident_index:
|
||||
self.algodata.append_if_it_donesnt_exist_before((i, {}))
|
||||
self.algodata.append_if_it_doesnt_exist_before((i, {}))
|
||||
self.electronic_data_lict = self.algodata
|
||||
|
||||
def _nucleonic_proc(self, unit):
|
||||
|
||||
Reference in New Issue
Block a user