mariagrandury commited on
Commit
6e6687a
·
1 Parent(s): 1534ae5

reorg functions

Browse files
Files changed (1) hide show
  1. app.py +55 -55
app.py CHANGED
@@ -52,6 +52,61 @@ countries = {
52
  }
53
 
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  def get_blend_es_data():
56
  data = []
57
 
@@ -127,61 +182,6 @@ def get_include_data():
127
  return data
128
 
129
 
130
- def get_user_mapping():
131
- """
132
- Get cached mapping of emails and hf_usernames to discord usernames.
133
- Returns a tuple of (email_to_discord, hf_username_to_discord) mappings.
134
- """
135
- email_to_discord = {}
136
- hf_username_to_discord = {}
137
-
138
- try:
139
- if os.path.exists(PARTICIPANTS_CSV):
140
- mapping_df = pd.read_csv(PARTICIPANTS_CSV)
141
-
142
- # Map emails to discord usernames
143
- if "gmail" in mapping_df.columns and "discord" in mapping_df.columns:
144
- for _, row in mapping_df.iterrows():
145
- mail = row["gmail"]
146
- discord = row["discord"]
147
- if pd.notna(mail) and pd.notna(discord) and discord != "NA":
148
- email_to_discord[mail.lower()] = discord.lower()
149
-
150
- # Map hf_usernames to discord usernames
151
- if "hf_username" in mapping_df.columns and "discord" in mapping_df.columns:
152
- for _, row in mapping_df.iterrows():
153
- hf_username = row["hf_username"]
154
- discord = row["discord"]
155
- if pd.notna(hf_username) and pd.notna(discord) and discord != "NA":
156
- hf_username_to_discord[hf_username.lower()] = discord.lower()
157
-
158
- except Exception as e:
159
- print(f"Error loading {PARTICIPANTS_CSV}: {e}")
160
-
161
- return email_to_discord, hf_username_to_discord
162
-
163
-
164
- def get_discord_username(identifier):
165
- """
166
- Get discord username from either email or hf_username. Returns the discord username if found, otherwise returns the identifier.
167
- """
168
- email_to_discord, hf_username_to_discord = get_user_mapping()
169
-
170
- # Try to find discord username by email first
171
- if "@" in identifier:
172
- discord_username = email_to_discord.get(identifier.lower())
173
- if discord_username:
174
- return discord_username
175
-
176
- # Try to find discord username by hf_username
177
- discord_username = hf_username_to_discord.get(identifier.lower())
178
- if discord_username:
179
- return discord_username
180
-
181
- # Fallback: use identifier as username
182
- return identifier.split("@")[0] if "@" in identifier else identifier
183
-
184
-
185
  def get_estereotipos_data():
186
  data = []
187
 
 
52
  }
53
 
54
 
55
+ def get_user_mapping():
56
+ """
57
+ Get cached mapping of emails and hf_usernames to discord usernames.
58
+ Returns a tuple of (email_to_discord, hf_username_to_discord) mappings.
59
+ """
60
+ email_to_discord = {}
61
+ hf_username_to_discord = {}
62
+
63
+ try:
64
+ if os.path.exists(PARTICIPANTS_CSV):
65
+ mapping_df = pd.read_csv(PARTICIPANTS_CSV)
66
+
67
+ # Map emails to discord usernames
68
+ if "gmail" in mapping_df.columns and "discord" in mapping_df.columns:
69
+ for _, row in mapping_df.iterrows():
70
+ mail = row["gmail"]
71
+ discord = row["discord"]
72
+ if pd.notna(mail) and pd.notna(discord) and discord != "NA":
73
+ email_to_discord[mail.lower()] = discord.lower()
74
+
75
+ # Map hf_usernames to discord usernames
76
+ if "hf_username" in mapping_df.columns and "discord" in mapping_df.columns:
77
+ for _, row in mapping_df.iterrows():
78
+ hf_username = row["hf_username"]
79
+ discord = row["discord"]
80
+ if pd.notna(hf_username) and pd.notna(discord) and discord != "NA":
81
+ hf_username_to_discord[hf_username.lower()] = discord.lower()
82
+
83
+ except Exception as e:
84
+ print(f"Error loading {PARTICIPANTS_CSV}: {e}")
85
+
86
+ return email_to_discord, hf_username_to_discord
87
+
88
+
89
+ def get_discord_username(identifier):
90
+ """
91
+ Get discord username from either email or hf_username. Returns the discord username if found, otherwise returns the identifier.
92
+ """
93
+ email_to_discord, hf_username_to_discord = get_user_mapping()
94
+
95
+ # Try to find discord username by email first
96
+ if "@" in identifier:
97
+ discord_username = email_to_discord.get(identifier.lower())
98
+ if discord_username:
99
+ return discord_username
100
+
101
+ # Try to find discord username by hf_username
102
+ discord_username = hf_username_to_discord.get(identifier.lower())
103
+ if discord_username:
104
+ return discord_username
105
+
106
+ # Fallback: use identifier as username
107
+ return identifier.split("@")[0] if "@" in identifier else identifier
108
+
109
+
110
  def get_blend_es_data():
111
  data = []
112
 
 
182
  return data
183
 
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  def get_estereotipos_data():
186
  data = []
187