33import json
44from datetime import date
55
6+
67def today ():
78 """
8- Get today's snapshot of Brain Image Library.
9- """
9+ Get today's snapshot of Brain Image Library.
10+ """
1011
1112 server = "https://download.brainimagelibrary.org/inventory/daily/reports/"
1213 filename = "today.json"
@@ -23,94 +24,105 @@ def today():
2324 else :
2425 print ("Error: Failed to fetch JSON data" )
2526 return pd .DataFrame ()
26-
27+
28+
2729def __get_number_of_datasets (df ):
28- return len (df )
30+ return len (df )
31+
2932
3033def __get_completeness_score (df ):
31- return df ['score' ].sum ()/ len (df )
34+ return df ["score" ].sum () / len (df )
35+
3236
3337def __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
4146def __get_metadata_version (df ):
42- return df ['metadata_version' ] .value_counts ().to_dict ()
47+ return df ["metadata_version" ].value_counts ().to_dict ()
48+
4349
4450def __get_contributor (df ):
45- return df ['contributor' ].value_counts ().to_dict ()
51+ return df ["contributor" ].value_counts ().to_dict ()
52+
4653
4754def __get_affilation (df ):
48- return df ['affiliation' ].value_counts ().to_dict ()
55+ return df ["affiliation" ].value_counts ().to_dict ()
56+
57+
58+ def __get_award_numbers (df ):
59+ return df ["award_number" ].value_counts ().to_dict ()
4960
50- def __get_award_number (df ):
51- return df ['award_number' ].value_counts ().to_dict ()
5261
5362def __get_species (df ):
54- return df ['species' ].value_counts ().to_dict ()
63+ return df ["species" ].value_counts ().to_dict ()
64+
5565
5666def __get_cnbtaxonomy (df ):
57- return df ['cnbtaxonomy' ].value_counts ().to_dict ()
67+ return df ["cnbtaxonomy" ].value_counts ().to_dict ()
68+
5869
5970def __get_samplelocalid (df ):
60- return df ['samplelocalid' ].value_counts ().to_dict ()
71+ return df ["samplelocalid" ].value_counts ().to_dict ()
72+
6173
6274def __get_genotype (df ):
63- return df ['genotype' ].value_counts ().to_dict ()
75+ return df ["genotype" ].value_counts ().to_dict ()
76+
6477
6578def __get_generalmodality (df ):
66- return df [' generalmodality' ].value_counts ().to_dict ()
79+ return df [" generalmodality" ].value_counts ().to_dict ()
6780
68- def __get_technique (df ):
69- return df ['technique' ].value_counts ().to_dict ()
7081
71- def __get_locations (df ):
72- return df ['locations' ].value_counts ().to_dict ()
82+ def __get_techniques (df ):
83+ """
84+ Write documentation here.
85+ """
86+ return df ["technique" ].unique ().to_dict ()
7387
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- import pandas as pd
101- def _get_technique_ (df ):
102- return df ['technique' ].unique ()
103- number_of_techniques = len (_get_technique_ (df ))
10488
105- def technique_frequency (df ):
106- number_of_techniques = len ( _get_technique_ ( df ))
107- print ( "Number of Techniques: " , number_of_techniques )
108- technique_counts = df [ 'technique' ]. value_counts ()
109- for technique , count in technique_counts . items ():
110- print ( f"Technique: { technique } , Count: { count } " )
89+ def techniques_frequency (df ):
90+ """
91+ Write documentation here.
92+ """
93+ return df [ "technique" ]. value_counts (). to_dict ()
94+
11195
112- technique_frequency (df )
96+ def __get_locations (df ):
97+ return df ["locations" ].value_counts ().to_dict ()
11398
11499
115- return report
100+ technique_frequency (df )
101+
116102
103+ def report ():
104+ # 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 ["affiliation" ] = __get_affilation (df )
119+ report ["award_number" ] = __get_award_number (df )
120+ report ["species" ] = __get_species (df )
121+ report ["cnbtaxonomy" ] = __get_cnbtaxonomy (df )
122+ report ["samplelocalid" ] = __get_samplelocalid (df )
123+ report ["genotype" ] = __get_genotype (df )
124+ report ["generalmodality" ] = __get_generalmodality (df )
125+ report ["technique" ] = __get_technique (df )
126+ report ["locations" ] = __get_locations (df )
127+
128+ return report
0 commit comments