Esempio n. 1
0
 def remove_db_entry(path: Union[str, Path], db=None):
     db = db or get_db_from_app()
     c = db.cursor()
     c.execute(
         f"DELETE FROM {Tables.EXPERIMENTS.value} WHERE path = ?", (str(path),)
     )
     db.commit()
Esempio n. 2
0
 def init_db_table(cls, db=None, entries: List[Tuple[str, str, int]] = None):
     db = db or get_db_from_app()
     entries = entries or [
         experiment.get_db_fields() for experiment in cls.find_experiments()
     ]
     c = db.cursor()
     c.execute(f"DELETE FROM {Tables.EXPERIMENTS.value}")
     field_names = cls.DB_FIELD_NAMES
     insert_stmnt = (
         f"INSERT OR REPLACE INTO {Tables.EXPERIMENTS.value} "
         f"({', '.join(field_names)}) VALUES "
         f"({','.join('?' for _ in field_names)})"
     )
     c.executemany(insert_stmnt, entries)
     db.commit()
Esempio n. 3
0
def get_dash_table_data(
    page: int = 0,
    page_size: int = PAGE_SIZE,
    sort_by: List[Dict[str, Any]] = None,
    filter_expression: str = None,
):
    db = get_db_from_app()
    offset = page * page_size
    if sort_by:
        sort_field = sort_by[0]["column_id"]
        sort_direction = "ASC" if sort_by[0]["direction"] == "asc" else "DESC"
    else:
        sort_field = "path"
        sort_direction = "ASC"
    if filter_expression and " contains " in filter_expression:
        where_clause, args = parse_filters(filter_expression)
        cursor = db.execute(
            f"SELECT * "
            f"FROM {Tables.EXPERIMENTS.value} "
            f"WHERE {where_clause} "
            f"ORDER BY {sort_field} {sort_direction} "
            f"LIMIT {offset}, {page_size}",
            args,
        )
    else:
        cursor = db.execute(
            f"SELECT * "
            f"FROM {Tables.EXPERIMENTS.value} "
            f"ORDER BY {sort_field} {sort_direction} "
            f"LIMIT {offset}, {page_size}"
        )
    return [
        {
            "path": row["path"],
            "tags": row["tags"],
            "finished": "Yes" if row["finished"] else "No",
        }
        for row in cursor
    ]
Esempio n. 4
0
 def __init__(self, db=None):
     if not db:
         db = get_db_from_app()
     self.db = db
     self.cursor = self.db.cursor()
Esempio n. 5
0
def get_all_tags() -> Set[str]:
    db = get_db_from_app()
    cursor = db.execute(f"SELECT tags FROM {Tables.EXPERIMENTS.value}")
    return set(t for r in cursor for t in r["tags"].split(" ") if t)
Esempio n. 6
0
 def db(self):
     return self._db or get_db_from_app()