diff --git a/__pycache__/auxiliary.cpython-313.pyc b/__pycache__/auxiliary.cpython-313.pyc index bcd17a1..8fbc6f5 100644 Binary files a/__pycache__/auxiliary.cpython-313.pyc and b/__pycache__/auxiliary.cpython-313.pyc differ diff --git a/__pycache__/particles.cpython-313.pyc b/__pycache__/particles.cpython-313.pyc index 3febeec..4fd1865 100644 Binary files a/__pycache__/particles.cpython-313.pyc and b/__pycache__/particles.cpython-313.pyc differ diff --git a/__pycache__/reactor.cpython-313.pyc b/__pycache__/reactor.cpython-313.pyc index de9b7aa..cb0f8e2 100644 Binary files a/__pycache__/reactor.cpython-313.pyc and b/__pycache__/reactor.cpython-313.pyc differ diff --git a/auxiliary.py b/auxiliary.py index 442ca20..b5e394c 100644 --- a/auxiliary.py +++ b/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 \ No newline at end of file + 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)) diff --git a/config.toml b/config.toml index 4062be5..538c6d0 100644 --- a/config.toml +++ b/config.toml @@ -1,4 +1,8 @@ -# 将更改保存到文件 +# [调试] 将更改保存到文件 save = 1 +# [调试] 覆写时间 +time_override = 10 # 对于每个项目的新记忆核子数量 -tasked_number = 8 \ No newline at end of file +tasked_number = 12 +# 竖屏适配 +mobile_mode = 1 \ No newline at end of file diff --git a/main.py b/main.py index f4904a7..5a832e1 100644 --- a/main.py +++ b/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() diff --git a/particles.py b/particles.py index 6b74aae..d54e2d4 100644 --- a/particles.py +++ b/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 = "" diff --git a/generate_audio_cache.py b/precaching.py similarity index 100% rename from generate_audio_cache.py rename to precaching.py diff --git a/reactor.py b/reactor.py index 59db57c..038045a 100644 --- a/reactor.py +++ b/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: - atom[0].is_activated = 1 - self.atoms_new.append(atom) + 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):