v0.2.4 基本可用型
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
auxiliary.py
17
auxiliary.py
@@ -2,10 +2,6 @@ import time
|
||||
import pathlib
|
||||
import toml
|
||||
|
||||
def get_daystamp():
|
||||
#print("Daystamp: ", (time.time() // (24*3600))) # 20292.0
|
||||
return (time.time() // (24*3600))
|
||||
|
||||
class ConfigFile():
|
||||
def __init__(self, path):
|
||||
self.path = pathlib.Path(path)
|
||||
@@ -23,4 +19,15 @@ class ConfigFile():
|
||||
with open(path, 'w') as f:
|
||||
toml.dump(self.data, f)
|
||||
def get(self, key, default = None):
|
||||
pass
|
||||
return self.data.get(key, default)
|
||||
|
||||
def get_daystamp() -> int:
|
||||
config = ConfigFile("config.toml")
|
||||
|
||||
time_override = config.get("time_override", -1)
|
||||
|
||||
if time_override is not None and time_override != -1:
|
||||
print(f"TIME OVERRIDEED TO {time_override}")
|
||||
return int(time_override)
|
||||
|
||||
return int(time.time() // (24 * 3600))
|
||||
|
@@ -1,4 +1,8 @@
|
||||
# 将更改保存到文件
|
||||
# [调试] 将更改保存到文件
|
||||
save = 1
|
||||
# [调试] 覆写时间
|
||||
time_override = 10
|
||||
# 对于每个项目的新记忆核子数量
|
||||
tasked_number = 8
|
||||
tasked_number = 12
|
||||
# 竖屏适配
|
||||
mobile_mode = 1
|
24
main.py
24
main.py
@@ -2,17 +2,19 @@ from textual.app import App, ComposeResult
|
||||
from textual.widgets import Header, Footer, ListView, ListItem, Label, Static, Button
|
||||
from textual.containers import Container, Horizontal
|
||||
from textual.screen import Screen
|
||||
import particles as pt
|
||||
from reactor import Reactor
|
||||
import pathlib
|
||||
import threading
|
||||
import edge_tts as tts
|
||||
from playsound import playsound
|
||||
from textual.logging import TextualHandler
|
||||
|
||||
ver = '0.2.1'
|
||||
import particles as pt
|
||||
from reactor import Reactor
|
||||
import auxiliary as aux
|
||||
|
||||
debug = TextualHandler(stderr=True)
|
||||
ver = '0.2.4'
|
||||
|
||||
config = aux.ConfigFile("config.toml")
|
||||
|
||||
class MemScreen(Screen):
|
||||
BINDINGS = [
|
||||
@@ -37,7 +39,7 @@ class MemScreen(Screen):
|
||||
self,
|
||||
nucleon_file: pt.AtomicFile,
|
||||
electron_file: pt.AtomicFile,
|
||||
tasked_num: int
|
||||
tasked_num
|
||||
):
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
self.reactor = Reactor(nucleon_file, electron_file, tasked_num)
|
||||
@@ -104,13 +106,16 @@ class MemScreen(Screen):
|
||||
ret = self.reactor.forward(1)
|
||||
if ret == -1:
|
||||
if self.reactor.round_set == 0:
|
||||
if self.stage == 3:
|
||||
if self.stage == 4:
|
||||
# NOTE #
|
||||
#self.reactor.save()
|
||||
if config.get("save"):
|
||||
self.reactor.save()
|
||||
self._show_finished_screen("今日目标已完成")
|
||||
else:
|
||||
self.stage += 1
|
||||
self.reactor.set_round_templated(self.stage)
|
||||
self.reactor.forward(1)
|
||||
self._update_ui()
|
||||
self.stage += 1
|
||||
return
|
||||
#feedback_label.update("") # 清除反馈消息
|
||||
self._update_ui()
|
||||
@@ -168,7 +173,7 @@ class PreparationScreen(Screen):
|
||||
pass
|
||||
if event.button.id == "start_memorizing_button":
|
||||
#init_file(Path(self.atom_file).name)
|
||||
newscr = MemScreen(self.nucleon_file, self.electron_file, 8)
|
||||
newscr = MemScreen(self.nucleon_file, self.electron_file, config.get("tasked_number", 8))
|
||||
self.app.push_screen(
|
||||
newscr
|
||||
)
|
||||
@@ -236,6 +241,5 @@ class AppLauncher(App):
|
||||
self.push_screen("file_selection_screen")
|
||||
|
||||
if __name__ == "__main__":
|
||||
css_path = pathlib.Path("styles_dashboard.tcss")
|
||||
app = AppLauncher()
|
||||
app.run()
|
||||
|
27
particles.py
27
particles.py
@@ -36,6 +36,17 @@ class Electron():
|
||||
setattr(self, var, value)
|
||||
self.last_modify = time.time()
|
||||
|
||||
def export_data(self):
|
||||
return {
|
||||
'efactor': self.efactor,
|
||||
'real_rept': self.real_rept,
|
||||
'rept': self.rept,
|
||||
'interval': self.interval,
|
||||
'last_date': self.last_date,
|
||||
'next_date': self.next_date,
|
||||
'is_activated': self.is_activated
|
||||
}
|
||||
|
||||
def revisor(self, quality):
|
||||
"""SM-2 算法迭代决策机制实现
|
||||
根据 quality(0 ~ 5) 进行参数迭代最佳间隔
|
||||
@@ -66,7 +77,7 @@ class Electron():
|
||||
self.interval = round(self.interval * self.efactor)
|
||||
|
||||
self.last_date = aux.get_daystamp()
|
||||
self.next_date = self.last_date + self.interval
|
||||
self.next_date = aux.get_daystamp() + self.interval
|
||||
|
||||
def __str__(self):
|
||||
return (f"记忆单元预览 \n"
|
||||
@@ -98,9 +109,9 @@ class Electron():
|
||||
lst.append(Electron(i, all[i]))
|
||||
return (name, lst)
|
||||
@staticmethod
|
||||
def save_to_file(electron_list, path: pathlib.Path):
|
||||
def save_to_file(electron_dictized, path: pathlib.Path):
|
||||
with open(path, 'w') as f:
|
||||
toml.dump(electron_list, f)
|
||||
toml.dump(electron_dictized, f)
|
||||
|
||||
class Nucleon():
|
||||
"""核子: 材料元数据"""
|
||||
@@ -119,9 +130,9 @@ class Nucleon():
|
||||
return (name, lst)
|
||||
|
||||
@staticmethod
|
||||
def save_to_file(nucleon_list, path: pathlib.Path):
|
||||
def save_to_file(nucleon_dictized, path: pathlib.Path):
|
||||
with open(path, 'w') as f:
|
||||
toml.dump(nucleon_list, f)
|
||||
toml.dump(nucleon_dictized, f)
|
||||
|
||||
@staticmethod
|
||||
def placeholder():
|
||||
@@ -136,10 +147,12 @@ class AtomicFile():
|
||||
if type_ == "electron":
|
||||
self.name, self.datalist = Electron.import_from_file(pathlib.Path(path))
|
||||
def save(self):
|
||||
dictobj = {i.content: i.export_data() for i in self.datalist}
|
||||
print(dictobj)
|
||||
if self.type_ == "nucleon":
|
||||
Nucleon.save_to_file(self.datalist, self.path)
|
||||
Nucleon.save_to_file(dictobj, self.path)
|
||||
if self.type_ == "electron":
|
||||
Electron.save_to_file(self.datalist, self.path)
|
||||
Electron.save_to_file(dictobj, self.path)
|
||||
def get_full_content(self):
|
||||
if self.type_ == "nucleon":
|
||||
text = ""
|
||||
|
28
reactor.py
28
reactor.py
@@ -3,10 +3,10 @@ import particles as pt
|
||||
import pathlib
|
||||
import auxiliary as aux
|
||||
class Parser():
|
||||
"""轻量级版本文件解析器, 用于解析记忆状态"""
|
||||
"""轻量级版本文件解析器, 用于文件管理器的记忆状态解析"""
|
||||
|
||||
class Reactor():
|
||||
"""反应堆对象, 用于处理 & 分配一次文件记忆流程的资源/策略"""
|
||||
"""反应堆对象, 用于全面解析文件, 并处理和分配一次文件记忆流程的资源与策略"""
|
||||
def __init__(self, nucleon_file: pt.AtomicFile, electron_file: pt.AtomicFile, tasked_num):
|
||||
# 导入原子对象
|
||||
self.reported = set()
|
||||
@@ -15,14 +15,28 @@ class Reactor():
|
||||
self.tasked_num = tasked_num
|
||||
self.atoms_new = list()
|
||||
self.atoms_review = list()
|
||||
counter = self.tasked_num
|
||||
|
||||
electron_dict = {elect.content: elect for elect in electron_file.datalist}
|
||||
self.electron_dict = {elect.content: elect for elect in electron_file.datalist}
|
||||
|
||||
def electron_dict_get_fallback(key) -> pt.Electron:
|
||||
value = self.electron_dict.get(key)
|
||||
|
||||
# 如果值不存在,则设置默认值
|
||||
if value is None:
|
||||
value = pt.Electron(key, {}) # 获取默认值
|
||||
self.electron_dict[key] = value # 将默认值存入字典
|
||||
value = self.electron_dict[key]
|
||||
|
||||
return value # 返回获取的值(可能是默认值)
|
||||
|
||||
for nucleon in nucleon_file.datalist:
|
||||
atom = (electron_dict.get(nucleon_file, pt.Electron.placeholder()), nucleon)
|
||||
atom = (electron_dict_get_fallback(nucleon.content), nucleon)
|
||||
if atom[0].is_activated == 0:
|
||||
if counter > 0:
|
||||
atom[0].is_activated = 1
|
||||
self.atoms_new.append(atom)
|
||||
counter -= 1
|
||||
else:
|
||||
if atom[0].next_date <= aux.get_daystamp():
|
||||
atom[0].last_date = aux.get_daystamp()
|
||||
@@ -81,7 +95,11 @@ class Reactor():
|
||||
|
||||
def save(self):
|
||||
print("Progress saved")
|
||||
self.nucleon_file.save()
|
||||
# self.nucleon_file.save()
|
||||
temp = list()
|
||||
for i in self.electron_dict.keys():
|
||||
temp.append(self.electron_dict[i])
|
||||
self.electron_file.datalist = temp
|
||||
self.electron_file.save()
|
||||
|
||||
def report(self, atom, quality):
|
||||
|
Reference in New Issue
Block a user