Skip to content

Commit 0f82b4f

Browse files
authored
Merge pull request #75 from brain-image-library/74-new-metric-request-meta-version-20
Update get.py
2 parents 00bcd2d + 21b5d64 commit 0f82b4f

File tree

1 file changed

+25
-43
lines changed

1 file changed

+25
-43
lines changed

braininventory/get.py

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
from datetime import date
33
import calendar
44
import pandas as pd
5-
import urllib.request
65
import random
76
import requests
87
import calendar
98

9+
import geoip2.database
10+
from geopy.geocoders import Nominatim
11+
import folium
12+
import math
13+
1014
import humanize
1115
import matplotlib.pyplot as plt
1216
import pandas as pd
@@ -245,12 +249,6 @@ def get_date(df):
245249
return f"{yr}-{day}-{mnt}" # format in year-day-month
246250

247251

248-
import geoip2.database
249-
from geopy.geocoders import Nominatim
250-
import folium
251-
import math
252-
import urllib.request
253-
254252
"""print(c.get_country_cities(country_code_iso="DE"))"""
255253
"""
256254
Geopy: input: University #correct some data (do later) Output: Address, lat, lon
@@ -923,7 +921,6 @@ def __get_projects(df):
923921
representing different projects and techniques, respectively. The function counts the occurrences of each
924922
unique project and technique and returns them as part of a single dictionary.
925923
"""
926-
return df["project"].value_counts().to_dict()
927924
return df["technique"].unique().to_dict()
928925

929926

@@ -996,7 +993,7 @@ def __get_contributors(df):
996993

997994
def __get_project_names(df):
998995
"""
999-
Gets the unique list of project names.
996+
Gets the unique list of project names.
1000997
1001998
Input: dataframe
1002999
Output: list
@@ -1056,14 +1053,30 @@ def __get_modalities(df):
10561053

10571054
def __get__percentage_of_metadata_version_1(df):
10581055
"""
1059-
Get the percentage/ratio of metadata version 1 from all datasets
1056+
Calculates the percentage of rows in the DataFrame that have 'metadata_version' equal to 1.
10601057
1061-
Input: dataframe
1062-
Output: an integer
1058+
Parameters:
1059+
df (pandas.DataFrame): The input DataFrame containing the 'metadata_version' column.
1060+
1061+
Returns:
1062+
float: The percentage of rows with 'metadata_version' equal to 1 as a decimal value.
10631063
"""
10641064
return len(df[df["metadata_version"] == 1]) / len(df)
10651065

10661066

1067+
def __get__percentage_of_metadata_version_2(df):
1068+
"""
1069+
Calculates the percentage of rows in the DataFrame that have 'metadata_version' equal to 2.
1070+
1071+
Parameters:
1072+
df (pandas.DataFrame): The input DataFrame containing the 'metadata_version' column.
1073+
1074+
Returns:
1075+
float: The percentage of rows with 'metadata_version' equal to 2 as a decimal value.
1076+
"""
1077+
return len(df[df["metadata_version"] == 2]) / len(df)
1078+
1079+
10671080
def report():
10681081
# Get today's date
10691082
tdate = date.today()
@@ -1098,34 +1111,3 @@ def report():
10981111
get_projects_treemap(df)
10991112

11001113
return report
1101-
1102-
1103-
import pandas as pd
1104-
import urllib.request
1105-
import geoip2.database
1106-
from geopy.geocoders import Nominatim
1107-
import folium
1108-
1109-
"""
1110-
Import modules that will be used to create the world map, find coordinates of affiliations, and
1111-
"""
1112-
1113-
url = "https://download.brainimagelibrary.org/inventory/daily/reports/today.json"
1114-
file_path, _ = urllib.request.urlretrieve(url)
1115-
df = pd.read_json(file_path)
1116-
df
1117-
"""
1118-
Geopy - Input: University Output: Address, lat, lon
1119-
Folium - visual map creator
1120-
"""
1121-
1122-
map = folium.Map()
1123-
1124-
from tqdm import tqdm
1125-
1126-
for index, row in tqdm(df.iterrows()):
1127-
city = row["city"]
1128-
lat = row["lat"]
1129-
lon = row["lng"]
1130-
folium.Marker([lat, lon], popup=city).add_to(map)
1131-
map.save("project_map.html")

0 commit comments

Comments
 (0)