diff --git a/pyerm/experiment.py b/pyerm/experiment.py index fe96339..1c69952 100644 --- a/pyerm/experiment.py +++ b/pyerm/experiment.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -# Version: 0.2.0 +# Version: 0.2.3 import os import typing @@ -57,6 +57,7 @@ def experiment_start(self, description:str=None, start_time:float=None, tags:str assert self._method is not None, 'Method not initialized, run method_init() first' assert self._task is not None, 'Task not initialized, run task_init() first' self._id = self.experiment_table.experiment_start(description, self._method, self._method_id, self._data, self._data_id, self._task, start_time, tags, experimenters) + atexit.register(self.experiment_table.experiment_failed, self._id) def experiment_over(self, rst_dict:typing.Dict[str, typing.Union[int, float, str, bool, bytearray, bytes]], images:typing.List[typing.Union[Image.Image, str]]=[], end_time:float=None, useful_time_cost:float=None) -> None: assert self._id is not None, 'Experiment not started, run experiment_start() first' @@ -67,11 +68,12 @@ def experiment_over(self, rst_dict:typing.Dict[str, typing.Union[int, float, str self.rst_table.record_rst(experiment_id=self._id, **rst_dict) self.rst_table.record_image(self._id, images) self.experiment_table.experiment_over(self._id, end_time=end_time, useful_time_cost=useful_time_cost) + atexit.unregister(self.experiment_table.experiment_failed) - def experiment_failed(self, exception:Exception, end_time:float=None) -> None: + def experiment_failed(self, end_time:float=None) -> None: assert self._id is not None, 'Experiment not started, run experiment_start() first' - self.experiment_table.experiment_failed(self._id, exception, end_time=end_time) - atexit.register(self.experiment_table.experiment_failed, self._id, exception, end_time=end_time) + self.experiment_table.experiment_failed(self._id, end_time=end_time) + def detail_update(self, detail_dict:typing.Dict[str, typing.Union[int, float, str, bool, bytearray, bytes]]): assert self._id is not None, 'Experiment not started, run experiment_start() first' diff --git a/pyerm/tables.py b/pyerm/tables.py index 128385a..8d3b2e0 100644 --- a/pyerm/tables.py +++ b/pyerm/tables.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -# Version: 0.2.2 +# Version: 0.2.3 from PIL import Image from io import BytesIO @@ -65,12 +65,12 @@ def experiment_over(self, experiment_id:int, end_time:float=None, useful_time_co end_time = strftime("%Y-%m-%d %H:%M:%S", end_time) super().update(f"id={experiment_id}", end_time=strftime(end_time), useful_time_cost=useful_time_cost, status='finished') - def experiment_failed(self, experiment_id:int, exception:Exception, end_time:float=None) -> None: + def experiment_failed(self, experiment_id:int, end_time:float=None) -> None: if end_time is None: end_time = time() end_time = localtime(end_time) end_time = strftime("%Y-%m-%d %H:%M:%S", end_time) - error_info = str(exception) + error_info = traceback.format_exc() super().update(f"id={experiment_id}", end_time=strftime(end_time), status='failed', failed_reason=error_info) def get_experiment(self, experiment_id:int) -> dict: diff --git a/pyerm/webUI/home.py b/pyerm/webUI/home.py index 5ed1b8c..61c2849 100644 --- a/pyerm/webUI/home.py +++ b/pyerm/webUI/home.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -# Version: 0.2.2 +# Version: 0.2.3 import streamlit as st import os @@ -34,7 +34,8 @@ def home(): title() load_db() - download_xls() + if os.path.exists(st.session_state.db_path) and st.session_state.db_path.endswith('.db'): + download_xls() def title(): st.title('Python Experiment Record Manager WebUI') diff --git a/setup.py b/setup.py index 9b57540..3b1bab8 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -# Version: 0.2.2 +# Version: 0.2.3 from setuptools import setup, find_packages with open("README.md", "r", encoding="utf-8") as f: @@ -28,7 +28,7 @@ setup( name='pyerm', - version='0.2.2', + version='0.2.3', author='Yuxuan Shao', author_email='yx_shao@qq.com', description='This project is an local experiment record manager for python based on SQLite DMS, suitable for recording experiment and analysing experiment data with a web UI, which can help you efficiently save your experiment settings and results for later analysis.',