diff --git a/corrlib/cli.py b/corrlib/cli.py index d24d8ef..b4a42e0 100644 --- a/corrlib/cli.py +++ b/corrlib/cli.py @@ -1,14 +1,13 @@ -from typing import Optional +from typing import Optional, Any import typer from corrlib import __app_name__ from .initialization import create from .toml import import_tomls, update_project, reimport_project -from .find import find_record, list_projects +from .find import find_record, list_projects, get_stat from .tools import str2list from .main import update_aliases from .meas_io import drop_cache as mio_drop_cache -from .meas_io import load_record as mio_load_record from .integrity import full_integrity_check import os @@ -116,6 +115,11 @@ def find( if arg == 'all': print(results) else: + if arg == 'stat': + for r in results['path'].values: + stat = get_stat(path, r) + print(stat) + return for r in results[arg].values: print(r) @@ -132,10 +136,7 @@ def stat( """ Show the statistics of a given record. """ - record = mio_load_record(path, record_id) - if isinstance(record, (list, Corr)): - record = record[0] - statistics = record.idl + statistics = get_stat(path, record_id) print(statistics) return @@ -170,6 +171,7 @@ def importer( """ file_list = files.split(",") import_tomls(path, file_list, copy_file) + mio_drop_cache(path) return @@ -194,6 +196,7 @@ def reimporter( raise Exception("This file is not known for this project.") else: reimport_project(path, uuid) + mio_drop_cache(path) return diff --git a/corrlib/find.py b/corrlib/find.py index 1e6b4bf..738c832 100644 --- a/corrlib/find.py +++ b/corrlib/find.py @@ -13,6 +13,8 @@ from pathlib import Path import datetime as dt from collections.abc import Callable import warnings +from .meas_io import load_record +from pyerrors import Corr, Obs def _project_lookup_by_alias(path: Path, alias: str) -> str: @@ -381,3 +383,12 @@ def list_projects(path: Path) -> list[tuple[str, str]]: conn.close() return results + +def get_stat(path: Path, record_id: str) -> Any: + loaded_record: Obs = load_record(path, record_id) + if isinstance(loaded_record, (list, Corr)): + record: Obs = loaded_record[0] + else: + record = loaded_record + return record.idl +