10
10
import squarify
11
11
import matplotlib .pyplot as plt
12
12
13
- def get_jsonFile (df ):
13
+
14
+ def get_random_sample (df ):
14
15
"""
16
+ Returns a random sample from the dataframe from a dataset with non-zero score.
17
+
15
18
Input: dataframe
16
- Output:open the jsonFile that was located in datasets Brain Image Library dataframe
19
+ Output:open the json file that was located in datasets Brain Image Library dataframe
17
20
"""
18
- isNotZero = df [df ["score" ] != 0.0 ] #only have files with the correct data
19
- randomRow = isNotZero .iloc [random .randint (0 , len (isNotZero ))] #select a random row of random index
20
- jsonFileLink = randomRow .json_file .replace ("/bil/data" , "https://download.brainimagelibrary.org" , 1 ) #create the link
21
+
22
+ isNotZero = df [df ["score" ] != 0.0 ] # only have files with the correct data
23
+ randomRow = isNotZero .iloc [
24
+ random .randint (0 , len (isNotZero ))
25
+ ] # select a random row of random index
26
+ jsonFileLink = randomRow .json_file .replace (
27
+ "/bil/data" , "https://download.brainimagelibrary.org" , 1
28
+ ) # create the link
21
29
result = requests .get (jsonFileLink )
22
30
23
31
return result .json ()
24
-
32
+
33
+
25
34
def today ():
26
35
"""
27
36
Get today's snapshot of Brain Image Library.
28
37
"""
29
38
39
+ # if file can be found locally, then load from disk
40
+ directory = "/bil/data/inventory/daily/reports/"
41
+ if Path (directory ).exists ():
42
+ data = json .loads (f"{ directory } /today.json" )
43
+ data = pd .DataFrame (data )
44
+ return data
45
+
46
+ # else get file from the web
30
47
server = "https://download.brainimagelibrary.org/inventory/daily/reports/"
31
48
filename = "today.json"
32
49
@@ -38,7 +55,6 @@ def today():
38
55
data = json .loads (response .text )
39
56
data = pd .DataFrame (data )
40
57
return data
41
-
42
58
else :
43
59
print ("Error: Failed to fetch JSON data" )
44
60
return pd .DataFrame ()
0 commit comments