Skip to content

Commit 54073d6

Browse files
committed
- Refactor code for fetching JSON data and creating a report.
- Add check for response status code when checking URL reachability. - Add functions to retrieve various statistics from the data. - Update report generation with new statistics. - Remove unused function. - Update variable names for better clarity.
1 parent 9d1c2b1 commit 54073d6

File tree

2 files changed

+64
-54
lines changed

2 files changed

+64
-54
lines changed

braininventory/get.py

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
from datetime import date
55

6+
67
def today():
78
"""
89
Get today's snapshot of Brain Image Library.
@@ -23,82 +24,97 @@ def today():
2324
else:
2425
print("Error: Failed to fetch JSON data")
2526
return pd.DataFrame()
26-
27+
28+
2729
def __get_number_of_datasets(df):
28-
return len(df)
30+
return len(df)
31+
2932

3033
def __get_completeness_score(df):
31-
return df['score'].sum()/len(df)
34+
return df["score"].sum() / len(df)
35+
3236

3337
def __is_reachable(url):
34-
response = requests.get(url)
38+
response = requests.get(url)
39+
40+
if response.status_code == 200:
41+
return True
42+
else:
43+
return False
3544

36-
if response.status_code == 200:
37-
return True
38-
else:
39-
return False
4045

4146
def __get_metadata_version(df):
42-
return df['metadata_version'] .value_counts().to_dict()
47+
return df["metadata_version"].value_counts().to_dict()
48+
4349

4450
def __get_contributor(df):
45-
return df['contributor'].value_counts().to_dict()
51+
return df["contributor"].value_counts().to_dict()
52+
4653

4754
def __get_affilation(df):
48-
return df['affiliation'].value_counts().to_dict()
55+
return df["affiliation"].value_counts().to_dict()
56+
57+
58+
def __get_awards(df):
59+
return df["award_number"].unique()
60+
4961

5062
def __get_award_number(df):
51-
return df['award_number'].value_counts().to_dict()
63+
return df["award_number"].value_counts().to_dict()
64+
5265

5366
def __get_species(df):
54-
return df['species'].value_counts().to_dict()
67+
return df["species"].value_counts().to_dict()
68+
5569

5670
def __get_cnbtaxonomy(df):
57-
return df['cnbtaxonomy'].value_counts().to_dict()
71+
return df["cnbtaxonomy"].value_counts().to_dict()
72+
5873

5974
def __get_samplelocalid(df):
60-
return df['samplelocalid'].value_counts().to_dict()
75+
return df["samplelocalid"].value_counts().to_dict()
76+
6177

6278
def __get_genotype(df):
63-
return df['genotype'].value_counts().to_dict()
79+
return df["genotype"].value_counts().to_dict()
80+
6481

6582
def __get_generalmodality(df):
66-
return df['generalmodality'].value_counts().to_dict()
83+
return df["generalmodality"].value_counts().to_dict()
84+
6785

6886
def __get_technique(df):
69-
return df['technique'].value_counts().to_dict()
87+
return df["technique"].value_counts().to_dict()
88+
7089

7190
def __get_locations(df):
72-
return df['locations'].value_counts().to_dict()
91+
return df["locations"].value_counts().to_dict()
92+
7393

7494
def report():
7595
# Get today's date
76-
tdate = date.today()
77-
78-
# Convert date to string
79-
tdate = tdate.strftime("%Y-%m-%d")
80-
81-
df = today()
82-
83-
report = {}
84-
report['date'] = tdate
85-
report['number_of_datasets'] = __get_number_of_datasets(df)
86-
report['completeness_score'] = __get_completeness_score(df)
87-
report['metadata_version'] = __get_metadata_version(df)
88-
report['contributor'] = __get_contributor(df)
89-
report['affiliation'] = __get_affilation(df)
90-
report['award_number'] = __get_award_number(df)
91-
report['species'] = __get_species(df)
92-
report['cnbtaxonomy'] = __get_cnbtaxonomy(df)
93-
report['samplelocalid'] = __get_samplelocalid(df)
94-
report['genotype'] = __get_genotype(df)
95-
report['generalmodality'] = __get_generalmodality(df)
96-
report['technique'] = __get_technique(df)
97-
report['locations'] = __get_locations(df)
98-
99-
report['is_reachable'] = df['URL'].apply(__is_reachable)
100-
101-
return report
102-
103-
def __get_awards(df):
104-
return df['award_number'].unique()
96+
tdate = date.today()
97+
98+
# Convert date to string
99+
tdate = tdate.strftime("%Y-%m-%d")
100+
101+
df = today()
102+
103+
report = {}
104+
report["date"] = tdate
105+
report["number_of_datasets"] = __get_number_of_datasets(df)
106+
report["completeness_score"] = __get_completeness_score(df)
107+
report["metadata_version"] = __get_metadata_version(df)
108+
report["contributor"] = __get_contributor(df)
109+
report["affiliation"] = __get_affilation(df)
110+
report["award_number"] = __get_award_number(df)
111+
report["species"] = __get_species(df)
112+
report["cnbtaxonomy"] = __get_cnbtaxonomy(df)
113+
report["samplelocalid"] = __get_samplelocalid(df)
114+
report["genotype"] = __get_genotype(df)
115+
report["generalmodality"] = __get_generalmodality(df)
116+
report["technique"] = __get_technique(df)
117+
report["locations"] = __get_locations(df)
118+
report["is_reachable"] = df["URL"].apply(__is_reachable)
119+
120+
return report

setup.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,3 @@
2020
],
2121
python_requires=">=3.6",
2222
)
23-
24-
def __get_awards(df):
25-
return df['award_number'].unique()
26-
27-
awards = __get_awards(df)
28-
print(awards)

0 commit comments

Comments
 (0)