3
3
import json
4
4
from datetime import date
5
5
6
+
6
7
def today ():
7
8
"""
8
9
Get today's snapshot of Brain Image Library.
@@ -23,84 +24,85 @@ def today():
23
24
else :
24
25
print ("Error: Failed to fetch JSON data" )
25
26
return pd .DataFrame ()
26
-
27
+
28
+
27
29
def __get_number_of_datasets (df ):
28
- return len (df )
30
+ return len (df )
31
+
29
32
30
33
def __get_completeness_score (df ):
31
- return df ['score' ].sum ()/ len (df )
34
+ return df ["score" ].sum () / len (df )
35
+
32
36
33
37
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
35
44
36
- if response .status_code == 200 :
37
- return True
38
- else :
39
- return False
40
45
41
46
def __get_metadata_version (df ):
42
- return df ['metadata_version' ] .value_counts ().to_dict ()
47
+ return df ["metadata_version" ].value_counts ().to_dict ()
48
+
43
49
44
50
def __get_contributor (df ):
45
- return df ['contributor' ].value_counts ().to_dict ()
51
+ return df ["contributor" ].value_counts ().to_dict ()
52
+
46
53
47
54
def __get_affilation (df ):
48
- return df ['affiliation' ].value_counts ().to_dict ()
55
+ return df ["affiliation" ].value_counts ().to_dict ()
56
+
49
57
50
58
def __get_award_number (df ):
51
- return df ['award_number' ].value_counts ().to_dict ()
59
+ return df ["award_number" ].value_counts ().to_dict ()
60
+
52
61
53
62
def __get_species (df ):
54
- return df ['species' ].value_counts ().to_dict ()
63
+ return df ["species" ].value_counts ().to_dict ()
64
+
55
65
56
66
def __get_cnbtaxonomy (df ):
57
- return df ['cnbtaxonomy' ].value_counts ().to_dict ()
67
+ return df ["cnbtaxonomy" ].value_counts ().to_dict ()
68
+
58
69
59
70
def __get_samplelocalid (df ):
60
- return df ['samplelocalid' ].value_counts ().to_dict ()
71
+ return df ["samplelocalid" ].value_counts ().to_dict ()
72
+
61
73
62
74
def __get_genotype (df ):
63
- return df ['genotype' ].value_counts ().to_dict ()
75
+ return df ["genotype" ].value_counts ().to_dict ()
76
+
64
77
65
78
def __get_generalmodality (df ):
66
- return df ['generalmodality' ].value_counts ().to_dict ()
79
+ return df ["generalmodality" ].value_counts ().to_dict ()
80
+
67
81
68
82
def __get_technique (df ):
69
- return df ['technique' ].value_counts ().to_dict ()
83
+ return df ["technique" ].value_counts ().to_dict ()
84
+
70
85
71
86
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
+
96
+
97
+ def __get_project_names (df ):
98
+ '''
99
+ Gets the unique list of project names.
100
+
101
+ Input: dataframe
102
+ Output: list
103
+ '''
104
+ return df ['project' ].unique ()
73
105
74
- def report ():
75
- # 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
- #
104
106
def __get_list_of_projects (df ):
105
107
'''
106
108
Get the list of names for unique projects
@@ -111,7 +113,6 @@ def __get_list_of_projects(df):
111
113
112
114
return df ['project' ].unique ().to_dict ()
113
115
114
- #
115
116
def __get_number_of_projects (df ):
116
117
'''
117
118
Get the number of unique projects
@@ -122,7 +123,37 @@ def __get_number_of_projects(df):
122
123
123
124
return len (df ['project' ].unique ())
124
125
126
+ def __get__percentage_of_metadata_version_1 (df ):
127
+ '''
128
+ Add documentation here.
129
+ '''
130
+ return len (df [df ['metadata_version' ] == 1 ])/ len (df )
125
131
126
- def __get__metadata_version_1 (df ):
127
- return len (df [df ['metadata_version' ] == 1 ]) / len (df )
128
-
132
+ def report ():
133
+ # Get today's date
134
+ tdate = date .today ()
135
+
136
+ # Convert date to string
137
+ tdate = tdate .strftime ("%Y-%m-%d" )
138
+
139
+ df = today ()
140
+
141
+ report = {}
142
+ report ["date" ] = tdate
143
+ report ["number_of_datasets" ] = __get_number_of_datasets (df )
144
+ report ["completeness_score" ] = __get_completeness_score (df )
145
+ report ["metadata_version" ] = __get_metadata_version (df )
146
+ report ["contributor" ] = __get_contributor (df )
147
+ report ["affiliation" ] = __get_affilation (df )
148
+ report ["award_number" ] = __get_award_number (df )
149
+ report ["species" ] = __get_species (df )
150
+ report ["cnbtaxonomy" ] = __get_cnbtaxonomy (df )
151
+ report ["samplelocalid" ] = __get_samplelocalid (df )
152
+ report ["genotype" ] = __get_genotype (df )
153
+ report ["generalmodality" ] = __get_generalmodality (df )
154
+ report ["technique" ] = __get_technique (df )
155
+ report ["locations" ] = __get_locations (df )
156
+ report ["percentage_of_version_1" ] = __get__percentage_of_metadata_version_1 (df )
157
+ report ["is_reachable" ] = df ["URL" ].apply (__is_reachable )
158
+
159
+ return report
0 commit comments