5
5
6
6
link = "https://download.brainimagelibrary.org"
7
7
8
+
8
9
def today ():
9
10
"""
10
- Get today's snapshot of Brain Image Library.
11
- """
11
+ Get today's snapshot of Brain Image Library.
12
+ """
12
13
13
14
server = f"{ link } /inventory/daily/reports/"
14
15
filename = "today.json"
@@ -25,94 +26,108 @@ def today():
25
26
else :
26
27
print ("Error: Failed to fetch JSON data" )
27
28
return pd .DataFrame ()
28
-
29
+
30
+
29
31
def __get_number_of_datasets (df ):
30
- return len (df )
32
+ return len (df )
33
+
31
34
32
35
def __get_completeness_score (df ):
33
- return df ['score' ].sum ()/ len (df )
36
+ return df ["score" ].sum () / len (df )
37
+
34
38
35
39
def __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
37
46
38
- if response .status_code == 200 :
39
- return True
40
- else :
41
- return False
42
47
43
48
def __get_metadata_version (df ):
44
- return df ['metadata_version' ] .value_counts ().to_dict ()
49
+ return df ["metadata_version" ].value_counts ().to_dict ()
50
+
45
51
46
52
def __get_contributor (df ):
47
- return df ['contributor' ].value_counts ().to_dict ()
53
+ return df ["contributor" ].value_counts ().to_dict ()
54
+
48
55
49
56
def __get_affilation (df ):
50
- return df ['affiliation' ].value_counts ().to_dict ()
57
+ return df ["affiliation" ].value_counts ().to_dict ()
58
+
51
59
52
60
def __get_award_number (df ):
53
- return df ['award_number' ].value_counts ().to_dict ()
61
+ return df ["award_number" ].value_counts ().to_dict ()
62
+
54
63
55
64
def __get_species (df ):
56
- return df ['species' ].value_counts ().to_dict ()
65
+ return df ["species" ].value_counts ().to_dict ()
66
+
57
67
58
68
def __get_cnbtaxonomy (df ):
59
- return df ['cnbtaxonomy' ].value_counts ().to_dict ()
69
+ return df ["cnbtaxonomy" ].value_counts ().to_dict ()
70
+
60
71
61
72
def __get_samplelocalid (df ):
62
- return df ['samplelocalid' ].value_counts ().to_dict ()
73
+ return df ["samplelocalid" ].value_counts ().to_dict ()
74
+
63
75
64
76
def __get_genotype (df ):
65
- return df ['genotype' ].value_counts ().to_dict ()
77
+ return df ["genotype" ].value_counts ().to_dict ()
78
+
66
79
67
80
def __get_generalmodality (df ):
68
- return df ['generalmodality' ].value_counts ().to_dict ()
81
+ return df ["generalmodality" ].value_counts ().to_dict ()
82
+
69
83
70
84
def __get_technique (df ):
71
- return df ['technique' ].value_counts ().to_dict ()
85
+ return df ["technique" ].value_counts ().to_dict ()
86
+
72
87
73
88
def __get_locations (df ):
74
- return df [' locations' ].value_counts ().to_dict ()
89
+ return df [" locations" ].value_counts ().to_dict ()
75
90
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.
77
95
"""
78
- Retrieve the json_file from the Brain Image Library of a dataset.
79
- """
80
-
96
+
81
97
# 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 )
83
102
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
87
106
88
- return response .json ()
89
107
90
108
def report ():
91
109
# 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