Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -95,27 +95,7 @@ countries = {
|
|
95 |
}
|
96 |
}
|
97 |
|
98 |
-
def
|
99 |
-
try:
|
100 |
-
if os.path.exists("include.csv"):
|
101 |
-
include_df = pd.read_csv("include.csv")
|
102 |
-
if "Nombre en Discord / username" in include_df.columns and "Número de preguntas / number of questions" in include_df.columns:
|
103 |
-
include_dict = defaultdict(int)
|
104 |
-
for _, row in include_df.iterrows():
|
105 |
-
username = row["Nombre en Discord / username"]
|
106 |
-
questions = row["Número de preguntas / number of questions"]
|
107 |
-
if pd.notna(username) and pd.notna(questions):
|
108 |
-
include_dict[username.lower()] += int(questions)
|
109 |
-
return include_dict
|
110 |
-
except Exception as e:
|
111 |
-
print(f"Error loading include.csv: {e}")
|
112 |
-
return {}
|
113 |
-
|
114 |
-
@lru_cache(maxsize=32)
|
115 |
-
def get_user_contributions_cached(cache_buster: int):
|
116 |
-
return get_user_contributions()
|
117 |
-
|
118 |
-
def get_user_contributions():
|
119 |
user_contributions = defaultdict(lambda: {"username": "", "contributions": 0, "country_contributions": {}})
|
120 |
user_id_to_username = {}
|
121 |
|
@@ -157,22 +137,72 @@ def get_user_contributions():
|
|
157 |
except Exception as e:
|
158 |
print(f"Error processing dataset {dataset_name}: {e}")
|
159 |
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
rows = []
|
163 |
-
for user_id
|
164 |
-
|
165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
break
|
171 |
|
172 |
row = {
|
173 |
"Username": username,
|
174 |
-
"Total":
|
175 |
-
"Blend-es":
|
176 |
"INCLUDE": include_value
|
177 |
}
|
178 |
rows.append(row)
|
|
|
95 |
}
|
96 |
}
|
97 |
|
98 |
+
def get_blend_es_data():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
user_contributions = defaultdict(lambda: {"username": "", "contributions": 0, "country_contributions": {}})
|
100 |
user_id_to_username = {}
|
101 |
|
|
|
137 |
except Exception as e:
|
138 |
print(f"Error processing dataset {dataset_name}: {e}")
|
139 |
|
140 |
+
return user_contributions, user_id_to_username
|
141 |
+
|
142 |
+
def get_include_data(username_mapping):
|
143 |
+
result = defaultdict(int)
|
144 |
+
try:
|
145 |
+
if os.path.exists("include.csv"):
|
146 |
+
include_df = pd.read_csv("include.csv")
|
147 |
+
if "Nombre en Discord / username" in include_df.columns and "Número de preguntas / number of questions" in include_df.columns:
|
148 |
+
discord_users = defaultdict(int)
|
149 |
+
for _, row in include_df.iterrows():
|
150 |
+
username = row["Nombre en Discord / username"]
|
151 |
+
questions = row["Número de preguntas / number of questions"]
|
152 |
+
if pd.notna(username) and pd.notna(questions):
|
153 |
+
discord_users[username.lower()] += int(questions)
|
154 |
+
|
155 |
+
reverse_mapping = {}
|
156 |
+
for user_id, username in username_mapping.items():
|
157 |
+
reverse_mapping[username.lower()] = user_id
|
158 |
+
|
159 |
+
for discord_name, questions in discord_users.items():
|
160 |
+
matched = False
|
161 |
+
for argilla_name in reverse_mapping:
|
162 |
+
if discord_name in argilla_name or argilla_name in discord_name:
|
163 |
+
user_id = reverse_mapping[argilla_name]
|
164 |
+
result[user_id] += questions
|
165 |
+
matched = True
|
166 |
+
break
|
167 |
+
|
168 |
+
if not matched:
|
169 |
+
result[f"discord_{discord_name}"] = questions
|
170 |
+
except Exception as e:
|
171 |
+
print(f"Error loading include.csv: {e}")
|
172 |
+
|
173 |
+
return result
|
174 |
+
|
175 |
+
@lru_cache(maxsize=32)
|
176 |
+
def get_user_contributions_cached(cache_buster: int):
|
177 |
+
return consolidate_all_data()
|
178 |
+
|
179 |
+
def consolidate_all_data():
|
180 |
+
user_data = {}
|
181 |
+
|
182 |
+
blend_es_data, username_mapping = get_blend_es_data()
|
183 |
+
include_data = get_include_data(username_mapping)
|
184 |
+
|
185 |
+
all_user_ids = set(blend_es_data.keys()) | set(include_data.keys())
|
186 |
|
187 |
rows = []
|
188 |
+
for user_id in all_user_ids:
|
189 |
+
blend_es_value = 0
|
190 |
+
username = user_id
|
191 |
+
|
192 |
+
if user_id in blend_es_data:
|
193 |
+
blend_es_value = blend_es_data[user_id]["contributions"]
|
194 |
+
username = blend_es_data[user_id]["username"]
|
195 |
+
|
196 |
+
include_value = include_data.get(user_id, 0)
|
197 |
|
198 |
+
if isinstance(user_id, str) and user_id.startswith("discord_"):
|
199 |
+
username = user_id.replace("discord_", "")
|
200 |
+
blend_es_value = 0
|
|
|
201 |
|
202 |
row = {
|
203 |
"Username": username,
|
204 |
+
"Total": blend_es_value + include_value,
|
205 |
+
"Blend-es": blend_es_value,
|
206 |
"INCLUDE": include_value
|
207 |
}
|
208 |
rows.append(row)
|