get rid of circular imports part 2
This commit is contained in:
parent
ac3eb272ad
commit
46b97acf95
2 changed files with 38 additions and 3 deletions
|
|
@ -6,6 +6,7 @@ import numpy as np
|
||||||
from .input.implementations import codes
|
from .input.implementations import codes
|
||||||
from .tools import k2m, get_db_file
|
from .tools import k2m, get_db_file
|
||||||
from .tracker import get
|
from .tracker import get
|
||||||
|
from .integrity import has_valid_times
|
||||||
from .sql import thin_sql_wrapper
|
from .sql import thin_sql_wrapper
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -82,6 +83,9 @@ def _time_filter(results: pd.DataFrame, created_before: Optional[str]=None, cre
|
||||||
result = results.iloc[ind]
|
result = results.iloc[ind]
|
||||||
created_at = dt.datetime.fromisoformat(result['created_at'])
|
created_at = dt.datetime.fromisoformat(result['created_at'])
|
||||||
updated_at = dt.datetime.fromisoformat(result['updated_at'])
|
updated_at = dt.datetime.fromisoformat(result['updated_at'])
|
||||||
|
db_times_valid = has_valid_times(result)
|
||||||
|
if not db_times_valid:
|
||||||
|
raise ValueError('Time stamps not valid for result with path', result["path"])
|
||||||
|
|
||||||
if created_before is not None:
|
if created_before is not None:
|
||||||
date_created_before = dt.datetime.fromisoformat(created_before)
|
date_created_before = dt.datetime.fromisoformat(created_before)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ from .tracker import get
|
||||||
import pyerrors.input.json as pj
|
import pyerrors.input.json as pj
|
||||||
import os
|
import os
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from .find import list_ensembles, list_projects
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -64,6 +63,38 @@ def are_keys_unique(db: Path, table: str, col: str) -> bool:
|
||||||
return bool(results[0] == results[1])
|
return bool(results[0] == results[1])
|
||||||
|
|
||||||
|
|
||||||
|
def _list_projects(path: Path) -> list[tuple[str, str]]:
|
||||||
|
"""
|
||||||
|
List all projects known to the library.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
path: str
|
||||||
|
The path of the library.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
results: list[Any]
|
||||||
|
The projects known to the library.
|
||||||
|
"""
|
||||||
|
db_file = get_db_file(path)
|
||||||
|
get(path, db_file)
|
||||||
|
conn = sqlite3.connect(os.path.join(path, db_file))
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT id,aliases FROM projects")
|
||||||
|
results = c.fetchall()
|
||||||
|
conn.close()
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def _list_ensembles(path: Path) -> list[str]:
|
||||||
|
res = []
|
||||||
|
for item in os.listdir(path / "archive"):
|
||||||
|
if os.path.isdir(path / "archive" / item):
|
||||||
|
res.append(item)
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
def check_path_format(result: pd.Series, ensembles: list[str], projects: list[str]) -> None:
|
def check_path_format(result: pd.Series, ensembles: list[str], projects: list[str]) -> None:
|
||||||
"""
|
"""
|
||||||
Check whether the path of the given result has the right format.
|
Check whether the path of the given result has the right format.
|
||||||
|
|
@ -107,8 +138,8 @@ def check_db_integrity(path: Path) -> None:
|
||||||
search_expr = "SELECT * FROM 'backlogs'"
|
search_expr = "SELECT * FROM 'backlogs'"
|
||||||
conn = sqlite3.connect(path / db)
|
conn = sqlite3.connect(path / db)
|
||||||
results = pd.read_sql(search_expr, conn)
|
results = pd.read_sql(search_expr, conn)
|
||||||
ensembles = list_ensembles(path)
|
ensembles = _list_ensembles(path)
|
||||||
projects = [p[0] for p in list_projects(path)]
|
projects = [p[0] for p in _list_projects(path)]
|
||||||
|
|
||||||
for _, result in results.iterrows():
|
for _, result in results.iterrows():
|
||||||
if not has_valid_times(result):
|
if not has_valid_times(result):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue