ouhenio commited on
Commit
65deab8
·
verified ·
1 Parent(s): 465e95c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -21
app.py CHANGED
@@ -13,11 +13,88 @@ client = rg.Argilla(
13
  )
14
 
15
  # List of countries to check
16
- COUNTRIES = [
17
- "MEX", "ARG", "COL", "CHL", "PER", "ESP", "BRA",
18
- "VEN", "ECU", "BOL", "PRY", "URY", "CRI", "PAN",
19
- "DOM", "GTM", "HND", "SLV", "NIC", "CUB"
20
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def count_answers_per_space(country: str):
23
  """
@@ -29,19 +106,11 @@ def count_answers_per_space(country: str):
29
  Returns:
30
  Dictionary with statistics about answers in the space
31
  """
32
- # Convert country code to full country name
33
- country_mapping = {
34
- "MEX": "Mexico", "ARG": "Argentina", "COL": "Colombia",
35
- "CHL": "Chile", "PER": "Peru", "ESP": "Spain",
36
- "BRA": "Brazil", "VEN": "Venezuela", "ECU": "Ecuador",
37
- "BOL": "Bolivia", "PRY": "Paraguay", "URY": "Uruguay",
38
- "CRI": "Costa Rica", "PAN": "Panama", "DOM": "Dominican Republic",
39
- "GTM": "Guatemala", "HND": "Honduras", "SLV": "El Salvador",
40
- "NIC": "Nicaragua", "CUB": "Cuba"
41
- }
42
 
43
- full_country_name = country_mapping.get(country, country)
44
- dataset_name = f"{full_country_name}_responder_preguntas"
45
 
46
  try:
47
  dataset = client.datasets(dataset_name)
@@ -74,7 +143,7 @@ def count_answers_per_space(country: str):
74
  percentage_complete = (answered_questions / total_questions * 100) if total_questions > 0 else 0
75
 
76
  return {
77
- "name": full_country_name,
78
  "total_questions": total_questions,
79
  "answered_questions": answered_questions,
80
  "total_answers": total_answers,
@@ -86,7 +155,7 @@ def count_answers_per_space(country: str):
86
  # If space doesn't exist, return zero values
87
  print(f"No dataset found for {dataset_name}: {e}")
88
  return {
89
- "name": full_country_name,
90
  "total_questions": 0,
91
  "answered_questions": 0,
92
  "total_answers": 0,
@@ -102,8 +171,8 @@ app = FastAPI()
102
  async def serve_map():
103
  # Generate data for each country by querying Argilla
104
  country_data = {}
105
- for country_code in COUNTRIES:
106
- country_data[country_code] = count_answers_per_space(country_code)
107
 
108
  # Convert to JSON for JavaScript
109
  country_data_json = json.dumps(country_data)
 
13
  )
14
 
15
  # List of countries to check
16
+ countries = {
17
+ "Argentina": {
18
+ "iso": "ARG",
19
+ "emoji": "🇦🇷"
20
+ },
21
+ "Bolivia": {
22
+ "iso": "BOL",
23
+ "emoji": "🇧🇴"
24
+ },
25
+ "Chile": {
26
+ "iso": "CHL",
27
+ "emoji": "🇨🇱"
28
+ },
29
+ "Colombia": {
30
+ "iso": "COL",
31
+ "emoji": "🇨🇴"
32
+ },
33
+ "Costa Rica": {
34
+ "iso": "CRI",
35
+ "emoji": "🇨🇷"
36
+ },
37
+ "Cuba": {
38
+ "iso": "CUB",
39
+ "emoji": "🇨🇺"
40
+ },
41
+ "Ecuador": {
42
+ "iso": "ECU",
43
+ "emoji": "🇪🇨"
44
+ },
45
+ "El Salvador": {
46
+ "iso": "SLV",
47
+ "emoji": "🇸🇻"
48
+ },
49
+ "España": {
50
+ "iso": "ESP",
51
+ "emoji": "🇪🇸"
52
+ },
53
+ "Guatemala": {
54
+ "iso": "GTM",
55
+ "emoji": "🇬🇹"
56
+ },
57
+ "Honduras": {
58
+ "iso": "HND",
59
+ "emoji": "🇭🇳"
60
+ },
61
+ "México": {
62
+ "iso": "MEX",
63
+ "emoji": "🇲🇽"
64
+ },
65
+ "Nicaragua": {
66
+ "iso": "NIC",
67
+ "emoji": "🇳🇮"
68
+ },
69
+ "Panamá": {
70
+ "iso": "PAN",
71
+ "emoji": "🇵🇦"
72
+ },
73
+ "Paraguay": {
74
+ "iso": "PRY",
75
+ "emoji": "🇵🇾"
76
+ },
77
+ "Perú": {
78
+ "iso": "PER",
79
+ "emoji": "🇵🇪"
80
+ },
81
+ "Puerto Rico": {
82
+ "iso": "PRI",
83
+ "emoji": "🇵🇷"
84
+ },
85
+ "República Dominicana": {
86
+ "iso": "DOM",
87
+ "emoji": "🇩🇴"
88
+ },
89
+ "Uruguay": {
90
+ "iso": "URY",
91
+ "emoji": "🇺🇾"
92
+ },
93
+ "Venezuela": {
94
+ "iso": "VEN",
95
+ "emoji": "🇻🇪"
96
+ }
97
+ }
98
 
99
  def count_answers_per_space(country: str):
100
  """
 
106
  Returns:
107
  Dictionary with statistics about answers in the space
108
  """
109
+
110
+ iso = countries[country]["iso"]
111
+ emoji = countries[country]["emoji"]
 
 
 
 
 
 
 
112
 
113
+ dataset_name = f"{emoji} {country} - {iso} - Responder"
 
114
 
115
  try:
116
  dataset = client.datasets(dataset_name)
 
143
  percentage_complete = (answered_questions / total_questions * 100) if total_questions > 0 else 0
144
 
145
  return {
146
+ "name": country,
147
  "total_questions": total_questions,
148
  "answered_questions": answered_questions,
149
  "total_answers": total_answers,
 
155
  # If space doesn't exist, return zero values
156
  print(f"No dataset found for {dataset_name}: {e}")
157
  return {
158
+ "name": country,
159
  "total_questions": 0,
160
  "answered_questions": 0,
161
  "total_answers": 0,
 
171
  async def serve_map():
172
  # Generate data for each country by querying Argilla
173
  country_data = {}
174
+ for country in countries.keys():
175
+ country_data[country] = count_answers_per_space(country)
176
 
177
  # Convert to JSON for JavaScript
178
  country_data_json = json.dumps(country_data)