Skip to content

Commit 8502b11

Browse files
authored
Merge pull request #13 from brain-image-library/5-new-metric-request-contributors-names
Update get.py
2 parents cbd0dfc + 0a19812 commit 8502b11

File tree

2 files changed

+68
-46
lines changed

2 files changed

+68
-46
lines changed

braininventory/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .get import *
1+
from .get import *

braininventory/get.py

Lines changed: 67 additions & 45 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,53 +24,75 @@ 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+
4957

5058
def __get_award_number(df):
51-
return df['award_number'].value_counts().to_dict()
59+
return df["award_number"].value_counts().to_dict()
60+
5261

5362
def __get_species(df):
54-
return df['species'].value_counts().to_dict()
63+
return df["species"].value_counts().to_dict()
64+
5565

5666
def __get_cnbtaxonomy(df):
57-
return df['cnbtaxonomy'].value_counts().to_dict()
67+
return df["cnbtaxonomy"].value_counts().to_dict()
68+
5869

5970
def __get_samplelocalid(df):
60-
return df['samplelocalid'].value_counts().to_dict()
71+
return df["samplelocalid"].value_counts().to_dict()
72+
6173

6274
def __get_genotype(df):
63-
return df['genotype'].value_counts().to_dict()
75+
return df["genotype"].value_counts().to_dict()
76+
6477

6578
def __get_generalmodality(df):
66-
return df['generalmodality'].value_counts().to_dict()
79+
return df["generalmodality"].value_counts().to_dict()
80+
6781

6882
def __get_technique(df):
69-
return df['technique'].value_counts().to_dict()
83+
return df["technique"].value_counts().to_dict()
84+
7085

7186
def __get_locations(df):
72-
return df['locations'].value_counts().to_dict()
87+
return df["locations"].value_counts().to_dict()
88+
89+
90+
def __get_contributors(df):
91+
"""
92+
This returns an array of contributor names from the contributorname column.
93+
"""
94+
return df["contributorname"].unique()
95+
7396

7497
def __get_project_names(df):
7598
'''
@@ -102,29 +125,28 @@ def __get_number_of_projects(df):
102125

103126
def report():
104127
# Get today's date
105-
tdate = date.today()
106-
107-
# Convert date to string
108-
tdate = tdate.strftime("%Y-%m-%d")
109-
110-
df = today()
111-
112-
report = {}
113-
report['date'] = tdate
114-
report['number_of_datasets'] = __get_number_of_datasets(df)
115-
report['completeness_score'] = __get_completeness_score(df)
116-
report['metadata_version'] = __get_metadata_version(df)
117-
report['contributor'] = __get_contributor(df)
118-
report['projects'] = __get_list_of_projects(df)
119-
report['affiliation'] = __get_affilation(df)
120-
report['award_number'] = __get_award_number(df)
121-
report['species'] = __get_species(df)
122-
report['cnbtaxonomy'] = __get_cnbtaxonomy(df)
123-
report['samplelocalid'] = __get_samplelocalid(df)
124-
report['genotype'] = __get_genotype(df)
125-
report['generalmodality'] = __get_generalmodality(df)
126-
report['technique'] = __get_technique(df)
127-
report['locations'] = __get_locations(df)
128-
#report['is_reachable'] = df['URL'].apply(__is_reachable)
129-
130-
return report
128+
tdate = date.today()
129+
130+
# Convert date to string
131+
tdate = tdate.strftime("%Y-%m-%d")
132+
133+
df = today()
134+
135+
report = {}
136+
report["date"] = tdate
137+
report["number_of_datasets"] = __get_number_of_datasets(df)
138+
report["completeness_score"] = __get_completeness_score(df)
139+
report["metadata_version"] = __get_metadata_version(df)
140+
report["contributor"] = __get_contributor(df)
141+
report["affiliation"] = __get_affilation(df)
142+
report["award_number"] = __get_award_number(df)
143+
report["species"] = __get_species(df)
144+
report["cnbtaxonomy"] = __get_cnbtaxonomy(df)
145+
report["samplelocalid"] = __get_samplelocalid(df)
146+
report["genotype"] = __get_genotype(df)
147+
report["generalmodality"] = __get_generalmodality(df)
148+
report["technique"] = __get_technique(df)
149+
report["locations"] = __get_locations(df)
150+
report["is_reachable"] = df["URL"].apply(__is_reachable)
151+
152+
return report

0 commit comments

Comments
 (0)