Merge branch 'develop' into refactor/data_backend
This commit is contained in:
commit
641c612a59
26 changed files with 3012 additions and 110 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import sqlite3
|
||||
import datalad.api as dl
|
||||
import os
|
||||
import json
|
||||
import pandas as pd
|
||||
|
|
@ -7,24 +6,25 @@ import numpy as np
|
|||
from .input.implementations import codes
|
||||
from .tools import k2m
|
||||
from .tracker import get
|
||||
from typing import Any, Optional
|
||||
# this will implement the search functionality
|
||||
|
||||
|
||||
def _project_lookup_by_alias(db, alias):
|
||||
def _project_lookup_by_alias(db: str, alias: str) -> str:
|
||||
# this will lookup the project name based on the alias
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
c.execute(f"SELECT * FROM 'projects' WHERE alias = '{alias}'")
|
||||
results = c.fetchall()
|
||||
conn.close()
|
||||
if len(results) > 1:
|
||||
if len(results)>1:
|
||||
print("Error: multiple projects found with alias " + alias)
|
||||
elif len(results) == 0:
|
||||
raise Exception("Error: no project found with alias " + alias)
|
||||
return results[0][0]
|
||||
return str(results[0][0])
|
||||
|
||||
|
||||
def _project_lookup_by_id(db, uuid):
|
||||
def _project_lookup_by_id(db: str, uuid: str) -> list[tuple[str, str]]:
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
c.execute(f"SELECT * FROM 'projects' WHERE id = '{uuid}'")
|
||||
|
|
@ -33,7 +33,8 @@ def _project_lookup_by_id(db, uuid):
|
|||
return results
|
||||
|
||||
|
||||
def _db_lookup(db, ensemble, correlator_name,code, project=None, parameters=None, created_before=None, created_after=None, updated_before=None, updated_after=None, revision=None):
|
||||
def _db_lookup(db: str, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None,
|
||||
created_before: Optional[str]=None, created_after: Optional[Any]=None, updated_before: Optional[Any]=None, updated_after: Optional[Any]=None) -> pd.DataFrame:
|
||||
project_str = project
|
||||
|
||||
search_expr = f"SELECT * FROM 'backlogs' WHERE name = '{correlator_name}' AND ensemble = '{ensemble}'"
|
||||
|
|
@ -57,7 +58,7 @@ def _db_lookup(db, ensemble, correlator_name,code, project=None, parameters=Non
|
|||
return results
|
||||
|
||||
|
||||
def sfcf_filter(results, **kwargs):
|
||||
def sfcf_filter(results: pd.DataFrame, **kwargs: Any) -> pd.DataFrame:
|
||||
drops = []
|
||||
for ind in range(len(results)):
|
||||
result = results.iloc[ind]
|
||||
|
|
@ -140,24 +141,25 @@ def sfcf_filter(results, **kwargs):
|
|||
return results.drop(drops)
|
||||
|
||||
|
||||
def find_record(path, ensemble, correlator_name, code, project=None, parameters=None, created_before=None, created_after=None, updated_before=None, updated_after=None, revision=None, **kwargs):
|
||||
def find_record(path: str, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None,
|
||||
created_before: Optional[str]=None, created_after: Optional[str]=None, updated_before: Optional[str]=None, updated_after: Optional[str]=None, revision: Optional[str]=None, **kwargs: Any) -> pd.DataFrame:
|
||||
db = path + '/backlogger.db'
|
||||
if code not in codes:
|
||||
raise ValueError("Code " + code + "unknown, take one of the following:" + ", ".join(codes))
|
||||
get(path, "backlogger.db")
|
||||
results = _db_lookup(db, ensemble, correlator_name,code, project, parameters=parameters, created_before=created_before, created_after=created_after, updated_before=updated_before, updated_after=updated_after, revision=revision)
|
||||
results = _db_lookup(db, ensemble, correlator_name,code, project, parameters=parameters, created_before=created_before, created_after=created_after, updated_before=updated_before, updated_after=updated_after)
|
||||
if code == "sfcf":
|
||||
results = sfcf_filter(results, **kwargs)
|
||||
print("Found " + str(len(results)) + " result" + ("s" if len(results)>1 else ""))
|
||||
return results.reset_index()
|
||||
|
||||
|
||||
def find_project(path, name):
|
||||
def find_project(path: str, name: str) -> str:
|
||||
get(path, "backlogger.db")
|
||||
return _project_lookup_by_alias(os.path.join(path, "backlogger.db"), name)
|
||||
|
||||
|
||||
def list_projects(path):
|
||||
def list_projects(path: str) -> list[tuple[str, str]]:
|
||||
db = path + '/backlogger.db'
|
||||
get(path, "backlogger.db")
|
||||
conn = sqlite3.connect(db)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue