Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove cache to count_unique() #307

Merged
merged 4 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions icees_api/features/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ def wrapper(*args):
return decorator


@cached(key=lambda db, *args: json.dumps(args))
def count_unique(conn, table_name, year, *columns):
"""Count each unique combination of column values.

Expand Down Expand Up @@ -587,48 +586,9 @@ def select_feature_matrix(
"""Select feature matrix."""
table_name = create_cohort_view(conn, table_name, cohort_features)

# start_time = time.time()
# cohort_features_norm = normalize_features(cohort_year, cohort_features)
feature_a_norm = normalize_feature(year, feature_a)
feature_b_norm = normalize_feature(year, feature_b)
# print(f"{time.time() - start_time} seconds spent normalizing")

# start_time = time.time()
# cohort_features_json = json.dumps(cohort_features_norm, sort_keys=True)
# feature_a_json = json.dumps(feature_a_norm, sort_keys=True)
# feature_b_json = json.dumps(feature_b_norm, sort_keys=True)
# print(f"{time.time() - start_time} seconds spent json.dumping")

# cohort_year = cohort_year if len(cohort_features_norm) == 0 else None

# start_time = time.time()
# digest = get_digest(
# json.dumps(table_name),
# cohort_features_json,
# json.dumps(cohort_year),
# feature_a_json,
# feature_b_json,
# )
# print(f"{time.time() - start_time} seconds spent getting digest")

# start_time = time.time()
# result = conn.execute(
# select([cache.c.association])\
# .select_from(cache)\
# .where(cache.c.digest == digest)\
# .where(cache.c.table == table_name)\
# .where(cache.c.cohort_features == cohort_features_json)\
# .where(cache.c.cohort_year == cohort_year)\
# .where(cache.c.feature_a == feature_a_json)\
# .where(cache.c.feature_b == feature_b_json)
# ).first()
# print(f"{time.time() - start_time} seconds spent checking cache")
# if result is None:
# print("cache miss...")
# else:
# print("cache hit!")

# timestamp = datetime.now(timezone.utc)
ka = feature_a_norm["feature_name"]
vas = feature_a_norm["feature_qualifiers"]
kb = feature_b_norm["feature_name"]
Expand All @@ -645,7 +605,6 @@ def select_feature_matrix(
}
for el in result
]
#print(f"{time.time() - start_time} seconds spent doing it the fast way")
feature_matrix = [
[
get_count(result, **{
Expand Down Expand Up @@ -741,13 +700,8 @@ def select_feature_matrix(
"log_odds_ratio_95_confidence_interval": None
}

# association_json = json.dumps(association, sort_keys=True)

drop_cohort_view(conn, cohort_features)

# start_time = time.time()
# conn.execute(cache.insert().values(digest=digest, association=association_json, table=table_name, cohort_features=cohort_features_json, feature_a=feature_a_json, feature_b=feature_b_json, access_time=timestamp))
# print(f"{time.time() - start_time} seconds spent writing to cache")
return association


Expand Down
140 changes: 70 additions & 70 deletions test/api/test_associations_to_all_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
APP,
"""
PatientId,year,AgeStudyStart,Albuterol
varchar(255),int,varchar(255),varchar(255)
1,2010,0-2,
2,2010,0-2,
3,2010,0-2,
4,2010,0-2,
5,2010,0-2,
6,2010,0-2,
7,2010,0-2,
8,2010,0-2,
9,2010,0-2,
10,2010,0-2,
11,2010,0-2,
12,2010,0-2,
varchar(255),int,int,varchar(255)
1,2010,2,
2,2010,2,
3,2010,2,
4,2010,2,
5,2010,2,
6,2010,2,
7,2010,2,
8,2010,2,
9,2010,2,
10,2010,2,
11,2010,2,
12,2010,2,
""",
"""
cohort_id,size,features,table,year
Expand All @@ -41,7 +41,7 @@ def test_associations_to_all_features_nulls():
"feature_name": "AgeStudyStart",
"feature_qualifier": {
"operator": "=",
"value": "0-2"
"value": 2
}
},
"maximum_p_value": 1,
Expand All @@ -62,19 +62,19 @@ def test_associations_to_all_features_nulls():
APP,
"""
PatientId,year,AgeStudyStart,Albuterol,AvgDailyPM2.5Exposure,EstResidentialDensity,AsthmaDx
varchar(255),int,varchar(255),varchar(255),int,int,int
1,2010,0-2,0,1,0,1
2,2010,0-2,1,1,0,0
3,2010,3-7,>1,1,0,0
4,2010,0-2,0,2,0,1
5,2010,3-7,1,2,0,1
6,2010,3-7,>1,2,0,1
7,2010,0-2,0,3,0,0
8,2010,0-2,1,3,0,0
9,2010,0-2,>1,3,0,0
10,2010,0-2,0,4,0,0
11,2010,0-2,1,4,0,0
12,2010,3-7,>1,4,0,1
varchar(255),int,int,varchar(255),int,int,int
1,2010,2,0,1,0,1
2,2010,2,1,1,0,0
3,2010,7,1,1,0,0
4,2010,2,0,2,0,1
5,2010,7,1,2,0,1
6,2010,7,1,2,0,1
7,2010,2,0,3,0,0
8,2010,2,1,3,0,0
9,2010,2,1,3,0,0
10,2010,2,0,4,0,0
11,2010,2,1,4,0,0
12,2010,7,1,4,0,1
""",
"""
cohort_id,size,features,table,year
Expand All @@ -88,7 +88,7 @@ def test_associations_to_all_features_explicit():
"feature_name": "AgeStudyStart",
"feature_qualifier": {
"operator": "=",
"value": "0-2"
"value": 2
}
},
"maximum_p_value": 1
Expand All @@ -106,19 +106,19 @@ def test_associations_to_all_features_explicit():
APP,
"""
PatientId,year,AgeStudyStart,Albuterol,AvgDailyPM2.5Exposure,EstResidentialDensity,AsthmaDx
varchar(255),int,varchar(255),varchar(255),int,int,int
1,2010,0-2,0,1,0,1
2,2010,0-2,1,1,0,1
3,2010,0-2,>1,1,0,1
4,2010,0-2,0,2,0,1
5,2010,0-2,1,2,0,1
6,2010,0-2,>1,2,0,1
7,2010,0-2,0,3,0,1
8,2010,0-2,1,3,0,1
9,2010,0-2,>1,3,0,1
10,2010,0-2,0,4,0,1
11,2010,0-2,1,4,0,1
12,2010,0-2,>1,4,0,1
varchar(255),int,int,varchar(255),int,int,int
1,2010,2,0,1,0,1
2,2010,2,1,1,0,1
3,2010,2,1,1,0,1
4,2010,2,0,2,0,1
5,2010,2,1,2,0,1
6,2010,2,1,2,0,1
7,2010,2,0,3,0,1
8,2010,2,1,3,0,1
9,2010,2,1,3,0,1
10,2010,2,0,4,0,1
11,2010,2,1,4,0,1
12,2010,2,1,4,0,1
""",
"""
cohort_id,size,features,table,year
Expand All @@ -132,7 +132,7 @@ def test_associations_to_all_features_explicit_non_integer_p_value():
"feature_name": "AgeStudyStart",
"feature_qualifier": {
"operator": "=",
"value": "0-2"
"value": 2
}
},
"maximum_p_value": 0.5
Expand All @@ -150,19 +150,19 @@ def test_associations_to_all_features_explicit_non_integer_p_value():
APP,
"""
PatientId,year,AgeStudyStart,Albuterol,AvgDailyPM2.5Exposure,EstResidentialDensity,AsthmaDx
varchar(255),int,varchar(255),varchar(255),int,int,int
1,2010,0-2,0,1,0,1
2,2010,0-2,1,1,0,1
3,2010,0-2,>1,1,0,1
4,2010,0-2,0,2,0,1
5,2010,0-2,1,2,0,1
6,2010,0-2,>1,2,0,1
7,2010,0-2,0,3,0,1
8,2010,0-2,1,3,0,1
9,2010,0-2,>1,3,0,1
10,2010,0-2,0,4,0,1
11,2010,0-2,1,4,0,1
12,2010,0-2,>1,4,0,1
varchar(255),int,int,varchar(255),int,int,int
1,2010,2,0,1,0,1
2,2010,2,1,1,0,1
3,2010,2,1,1,0,1
4,2010,2,0,2,0,1
5,2010,2,1,2,0,1
6,2010,2,1,2,0,1
7,2010,2,0,3,0,1
8,2010,2,1,3,0,1
9,2010,2,1,3,0,1
10,2010,2,0,4,0,1
11,2010,2,1,4,0,1
12,2010,2,1,4,0,1
""",
"""
cohort_id,size,features,table,year
Expand All @@ -175,7 +175,7 @@ def test_associations_to_all_features_with_correction():
"feature": {
"AgeStudyStart": {
"operator": "=",
"value": "0-2"
"value": 2
}
},
"correction": {
Expand All @@ -196,19 +196,19 @@ def test_associations_to_all_features_with_correction():
APP,
"""
PatientId,year,AgeStudyStart,Albuterol,AvgDailyPM2.5Exposure,EstResidentialDensity,AsthmaDx
varchar(255),int,varchar(255),varchar(255),int,int,int
1,2010,0-2,0,1,0,1
2,2010,0-2,1,1,0,1
3,2010,0-2,>1,1,0,1
4,2010,0-2,0,2,0,1
5,2010,0-2,1,2,0,1
6,2010,0-2,>1,2,0,1
7,2010,0-2,0,3,0,1
8,2010,0-2,1,3,0,1
9,2010,0-2,>1,3,0,1
10,2010,0-2,0,4,0,1
11,2010,0-2,1,4,0,1
12,2010,0-2,>1,4,0,1
varchar(255),int,int,varchar(255),int,int,int
1,2010,2,0,1,0,1
2,2010,2,1,1,0,1
3,2010,2,1,1,0,1
4,2010,2,0,2,0,1
5,2010,2,1,2,0,1
6,2010,2,1,2,0,1
7,2010,2,0,3,0,1
8,2010,2,1,3,0,1
9,2010,2,1,3,0,1
10,2010,2,0,4,0,1
11,2010,2,1,4,0,1
12,2010,2,1,4,0,1
""",
"""
cohort_id,size,features,table,year
Expand All @@ -221,7 +221,7 @@ def test_associations_to_all_features_with_correction_with_alpha():
"feature": {
"AgeStudyStart": {
"operator": "=",
"value": "0-2"
"value": 2
}
},
"correction": {
Expand Down
Loading
Loading