|
2 | 2 | from datetime import date |
3 | 3 | import calendar |
4 | 4 | import pandas as pd |
5 | | -import urllib.request |
6 | 5 | import random |
7 | 6 | import requests |
8 | 7 | import calendar |
9 | 8 |
|
| 9 | +import geoip2.database |
| 10 | +from geopy.geocoders import Nominatim |
| 11 | +import folium |
| 12 | +import math |
| 13 | + |
10 | 14 | import humanize |
11 | 15 | import matplotlib.pyplot as plt |
12 | 16 | import pandas as pd |
@@ -245,12 +249,6 @@ def get_date(df): |
245 | 249 | return f"{yr}-{day}-{mnt}" # format in year-day-month |
246 | 250 |
|
247 | 251 |
|
248 | | -import geoip2.database |
249 | | -from geopy.geocoders import Nominatim |
250 | | -import folium |
251 | | -import math |
252 | | -import urllib.request |
253 | | - |
254 | 252 | """print(c.get_country_cities(country_code_iso="DE"))""" |
255 | 253 | """ |
256 | 254 | Geopy: input: University #correct some data (do later) Output: Address, lat, lon |
@@ -923,7 +921,6 @@ def __get_projects(df): |
923 | 921 | representing different projects and techniques, respectively. The function counts the occurrences of each |
924 | 922 | unique project and technique and returns them as part of a single dictionary. |
925 | 923 | """ |
926 | | - return df["project"].value_counts().to_dict() |
927 | 924 | return df["technique"].unique().to_dict() |
928 | 925 |
|
929 | 926 |
|
@@ -996,7 +993,7 @@ def __get_contributors(df): |
996 | 993 |
|
997 | 994 | def __get_project_names(df): |
998 | 995 | """ |
999 | | - Gets the unique list of project names. |
| 996 | + Gets the unique list of project names. |
1000 | 997 |
|
1001 | 998 | Input: dataframe |
1002 | 999 | Output: list |
@@ -1056,14 +1053,30 @@ def __get_modalities(df): |
1056 | 1053 |
|
1057 | 1054 | def __get__percentage_of_metadata_version_1(df): |
1058 | 1055 | """ |
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. |
1060 | 1057 |
|
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. |
1063 | 1063 | """ |
1064 | 1064 | return len(df[df["metadata_version"] == 1]) / len(df) |
1065 | 1065 |
|
1066 | 1066 |
|
| 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 | + |
1067 | 1080 | def report(): |
1068 | 1081 | # Get today's date |
1069 | 1082 | tdate = date.today() |
@@ -1098,34 +1111,3 @@ def report(): |
1098 | 1111 | get_projects_treemap(df) |
1099 | 1112 |
|
1100 | 1113 | 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