55
66link = "https://download.brainimagelibrary.org"
77
8+
89def today ():
910 """
10- Get today's snapshot of Brain Image Library.
11- """
11+ Get today's snapshot of Brain Image Library.
12+ """
1213
1314 server = f"{ link } /inventory/daily/reports/"
1415 filename = "today.json"
@@ -25,94 +26,108 @@ def today():
2526 else :
2627 print ("Error: Failed to fetch JSON data" )
2728 return pd .DataFrame ()
28-
29+
30+
2931def __get_number_of_datasets (df ):
30- return len (df )
32+ return len (df )
33+
3134
3235def __get_completeness_score (df ):
33- return df ['score' ].sum ()/ len (df )
36+ return df ["score" ].sum () / len (df )
37+
3438
3539def __is_reachable (url ):
36- response = requests .get (url )
40+ response = requests .get (url )
41+
42+ if response .status_code == 200 :
43+ return True
44+ else :
45+ return False
3746
38- if response .status_code == 200 :
39- return True
40- else :
41- return False
4247
4348def __get_metadata_version (df ):
44- return df ['metadata_version' ] .value_counts ().to_dict ()
49+ return df ["metadata_version" ].value_counts ().to_dict ()
50+
4551
4652def __get_contributor (df ):
47- return df ['contributor' ].value_counts ().to_dict ()
53+ return df ["contributor" ].value_counts ().to_dict ()
54+
4855
4956def __get_affilation (df ):
50- return df ['affiliation' ].value_counts ().to_dict ()
57+ return df ["affiliation" ].value_counts ().to_dict ()
58+
5159
5260def __get_award_number (df ):
53- return df ['award_number' ].value_counts ().to_dict ()
61+ return df ["award_number" ].value_counts ().to_dict ()
62+
5463
5564def __get_species (df ):
56- return df ['species' ].value_counts ().to_dict ()
65+ return df ["species" ].value_counts ().to_dict ()
66+
5767
5868def __get_cnbtaxonomy (df ):
59- return df ['cnbtaxonomy' ].value_counts ().to_dict ()
69+ return df ["cnbtaxonomy" ].value_counts ().to_dict ()
70+
6071
6172def __get_samplelocalid (df ):
62- return df ['samplelocalid' ].value_counts ().to_dict ()
73+ return df ["samplelocalid" ].value_counts ().to_dict ()
74+
6375
6476def __get_genotype (df ):
65- return df ['genotype' ].value_counts ().to_dict ()
77+ return df ["genotype" ].value_counts ().to_dict ()
78+
6679
6780def __get_generalmodality (df ):
68- return df ['generalmodality' ].value_counts ().to_dict ()
81+ return df ["generalmodality" ].value_counts ().to_dict ()
82+
6983
7084def __get_technique (df ):
71- return df ['technique' ].value_counts ().to_dict ()
85+ return df ["technique" ].value_counts ().to_dict ()
86+
7287
7388def __get_locations (df ):
74- return df [' locations' ].value_counts ().to_dict ()
89+ return df [" locations" ].value_counts ().to_dict ()
7590
76- def __get_json_file (df ):
91+
92+ def __is_json_file_reachable (df ):
93+ """
94+ Retrieve the json_file from the Brain Image Library of a dataset.
7795 """
78- Retrieve the json_file from the Brain Image Library of a dataset.
79- """
80-
96+
8197 # Make sure there is data to request
82- assert df ['score' ].values [0 ] != 0
98+ if df ["score" ].values [0 ] != 0 :
99+ # Create working link
100+ url = df ["json_file" ].values [0 ].replace ("/bil/data" , link )
101+ response = requests .get (url )
83102
84- # Create working link
85- url = sample [ 'json_file' ]. values [ 0 ]. replace ( '/bil/data' , link )
86- response = requests . get ( url )
103+ return response . json ()
104+ else :
105+ return None
87106
88- return response .json ()
89107
90108def report ():
91109 # Get today's date
92- tdate = date .today ()
93-
94- # Convert date to string
95- tdate = tdate .strftime ("%Y-%m-%d" )
96-
97- df = today ()
98-
99- report = {}
100- report ['date' ] = tdate
101- report ['number_of_datasets' ] = __get_number_of_datasets (df )
102- report ['completeness_score' ] = __get_completeness_score (df )
103- report ['metadata_version' ] = __get_metadata_version (df )
104- report ['contributor' ] = __get_contributor (df )
105- report ['affiliation' ] = __get_affilation (df )
106- report ['award_number' ] = __get_award_number (df )
107- report ['species' ] = __get_species (df )
108- report ['cnbtaxonomy' ] = __get_cnbtaxonomy (df )
109- report ['samplelocalid' ] = __get_samplelocalid (df )
110- report ['genotype' ] = __get_genotype (df )
111- report ['generalmodality' ] = __get_generalmodality (df )
112- report ['technique' ] = __get_technique (df )
113- report ['locations' ] = __get_locations (df )
114-
115- report ['is_reachable' ] = df ['URL' ].apply (__is_reachable )
116-
117- return report
118-
110+ tdate = date .today ()
111+
112+ # Convert date to string
113+ tdate = tdate .strftime ("%Y-%m-%d" )
114+
115+ df = today ()
116+
117+ report = {}
118+ report ["date" ] = tdate
119+ report ["number_of_datasets" ] = __get_number_of_datasets (df )
120+ report ["completeness_score" ] = __get_completeness_score (df )
121+ report ["metadata_version" ] = __get_metadata_version (df )
122+ report ["contributor" ] = __get_contributor (df )
123+ report ["affiliation" ] = __get_affilation (df )
124+ report ["award_number" ] = __get_award_number (df )
125+ report ["species" ] = __get_species (df )
126+ report ["cnbtaxonomy" ] = __get_cnbtaxonomy (df )
127+ report ["samplelocalid" ] = __get_samplelocalid (df )
128+ report ["genotype" ] = __get_genotype (df )
129+ report ["generalmodality" ] = __get_generalmodality (df )
130+ report ["technique" ] = __get_technique (df )
131+ report ["locations" ] = __get_locations (df )
132+
133+ return report
0 commit comments