zombie-squirrel 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zombie_squirrel-0.1.0/src/zombie_squirrel.egg-info → zombie_squirrel-0.1.2}/PKG-INFO +1 -1
- zombie_squirrel-0.1.2/src/zombie_squirrel/__init__.py +4 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/src/zombie_squirrel/acorns.py +1 -4
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/src/zombie_squirrel/squirrels.py +16 -6
- zombie_squirrel-0.1.2/src/zombie_squirrel/utils.py +20 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2/src/zombie_squirrel.egg-info}/PKG-INFO +1 -1
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/src/zombie_squirrel.egg-info/SOURCES.txt +1 -0
- zombie_squirrel-0.1.0/src/zombie_squirrel/__init__.py +0 -4
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/LICENSE +0 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/README.md +0 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/pyproject.toml +0 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/setup.cfg +0 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/setup.py +0 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/src/zombie_squirrel/sync.py +0 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/src/zombie_squirrel.egg-info/dependency_links.txt +0 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/src/zombie_squirrel.egg-info/requires.txt +0 -0
- {zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/src/zombie_squirrel.egg-info/top_level.txt +0 -0
|
@@ -4,10 +4,7 @@ import pandas as pd
|
|
|
4
4
|
import os
|
|
5
5
|
|
|
6
6
|
from aind_data_access_api.rds_tables import Client, RDSCredentials
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def prefix_table_name(table_name: str) -> str:
|
|
10
|
-
return "zs_" + table_name
|
|
7
|
+
from zombie_squirrel.utils import prefix_table_name
|
|
11
8
|
|
|
12
9
|
|
|
13
10
|
class Acorn(ABC):
|
|
@@ -4,6 +4,8 @@ from typing import Any, Callable, Optional
|
|
|
4
4
|
from zombie_squirrel.acorns import RedshiftAcorn, MemoryAcorn
|
|
5
5
|
from aind_data_access_api.document_db import MetadataDbClient
|
|
6
6
|
import os
|
|
7
|
+
import logging
|
|
8
|
+
from zombie_squirrel.utils import prefix_table_name, rds_get_handle_empty
|
|
7
9
|
|
|
8
10
|
# --- Backend setup ---------------------------------------------------
|
|
9
11
|
|
|
@@ -12,8 +14,10 @@ API_GATEWAY_HOST = "api.allenneuraldynamics.org"
|
|
|
12
14
|
tree_type = os.getenv("TREE_SPECIES", "memory").lower()
|
|
13
15
|
|
|
14
16
|
if tree_type == "redshift":
|
|
17
|
+
logging.info("Using Redshift acorn for caching")
|
|
15
18
|
ACORN = RedshiftAcorn()
|
|
16
19
|
else:
|
|
20
|
+
logging.info("Using in-memory acorn for caching")
|
|
17
21
|
ACORN = MemoryAcorn()
|
|
18
22
|
|
|
19
23
|
# --- Squirrel registry -----------------------------------------------------
|
|
@@ -31,13 +35,19 @@ def register_squirrel(name: str):
|
|
|
31
35
|
|
|
32
36
|
# --- Squirrels -----------------------------------------------------
|
|
33
37
|
|
|
38
|
+
NAMES = {
|
|
39
|
+
"upn": "unique-project-names",
|
|
40
|
+
"usi": "unique-subject-ids",
|
|
41
|
+
}
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
|
|
44
|
+
@register_squirrel(NAMES["upn"])
|
|
36
45
|
def unique_project_names(force_update: bool = False) -> list[str]:
|
|
37
|
-
df = ACORN
|
|
46
|
+
df = rds_get_handle_empty(ACORN, NAMES["upn"])
|
|
38
47
|
|
|
39
48
|
if df.empty or force_update:
|
|
40
49
|
# If cache is missing, fetch data
|
|
50
|
+
logging.info("Updating cache for unique project names")
|
|
41
51
|
client = MetadataDbClient(
|
|
42
52
|
host=API_GATEWAY_HOST,
|
|
43
53
|
version="v2",
|
|
@@ -49,14 +59,14 @@ def unique_project_names(force_update: bool = False) -> list[str]:
|
|
|
49
59
|
]
|
|
50
60
|
)
|
|
51
61
|
df = pd.DataFrame(unique_project_names)
|
|
52
|
-
ACORN.hide("
|
|
62
|
+
ACORN.hide(NAMES["upn"], df)
|
|
53
63
|
|
|
54
64
|
return df["project_name"].tolist()
|
|
55
65
|
|
|
56
66
|
|
|
57
|
-
@register_squirrel("
|
|
67
|
+
@register_squirrel(NAMES["usi"])
|
|
58
68
|
def unique_subject_ids(force_update: bool = False) -> list[str]:
|
|
59
|
-
df = ACORN
|
|
69
|
+
df = rds_get_handle_empty(ACORN, NAMES["usi"])
|
|
60
70
|
|
|
61
71
|
if df.empty or force_update:
|
|
62
72
|
# If cache is missing, fetch data
|
|
@@ -71,6 +81,6 @@ def unique_subject_ids(force_update: bool = False) -> list[str]:
|
|
|
71
81
|
]
|
|
72
82
|
)
|
|
73
83
|
df = pd.DataFrame(unique_subject_ids)
|
|
74
|
-
ACORN.hide("
|
|
84
|
+
ACORN.hide(NAMES["usi"], df)
|
|
75
85
|
|
|
76
86
|
return df["subject_id"].tolist()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Utility functions"""
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from zombie_squirrel.acorns import Acorn
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def prefix_table_name(table_name: str) -> str:
|
|
9
|
+
return "zs_" + table_name
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def rds_get_handle_empty(acorn: Acorn, table_name: str) -> pd.DataFrame:
|
|
13
|
+
"""Utility function for testing purposes."""
|
|
14
|
+
try:
|
|
15
|
+
df = acorn.scurry(table_name)
|
|
16
|
+
except Exception as e:
|
|
17
|
+
logging.warning(f"Error fetching from cache: {e}")
|
|
18
|
+
df = pd.DataFrame()
|
|
19
|
+
|
|
20
|
+
return df
|
|
@@ -6,6 +6,7 @@ src/zombie_squirrel/__init__.py
|
|
|
6
6
|
src/zombie_squirrel/acorns.py
|
|
7
7
|
src/zombie_squirrel/squirrels.py
|
|
8
8
|
src/zombie_squirrel/sync.py
|
|
9
|
+
src/zombie_squirrel/utils.py
|
|
9
10
|
src/zombie_squirrel.egg-info/PKG-INFO
|
|
10
11
|
src/zombie_squirrel.egg-info/SOURCES.txt
|
|
11
12
|
src/zombie_squirrel.egg-info/dependency_links.txt
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{zombie_squirrel-0.1.0 → zombie_squirrel-0.1.2}/src/zombie_squirrel.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|