Commit
·
2044f09
1
Parent(s):
4e119bd
Integrate verification claim
Browse filesSigned-off-by: Aivin V. Solatorio <[email protected]>
- services.py +10 -2
- wdi_mcp_gradio.py +1 -1
- wdi_mcp_server.py +1 -1
services.py
CHANGED
|
@@ -3,7 +3,7 @@ import os
|
|
| 3 |
import pandas as pd
|
| 4 |
import torch
|
| 5 |
import httpx
|
| 6 |
-
|
| 7 |
|
| 8 |
from typing import Optional, Any
|
| 9 |
from sentence_transformers import SentenceTransformer
|
|
@@ -144,6 +144,10 @@ def indicator_info(indicator_ids: list[str]) -> list[DetailedOutput]:
|
|
| 144 |
]
|
| 145 |
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
def _simplify_wdi_data(data: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
| 148 |
"""Simplifies the WDI data to only include the necessary fields. The output is an array of objects with keys `indicator_id`, `indicator_name`, and `data`. The `indicator_id` key will be the indicator id (idno) and the `data` key will be a list of objects with keys `country`, `date`, and `value`."""
|
| 149 |
|
|
@@ -166,6 +170,10 @@ def _simplify_wdi_data(data: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
| 166 |
}
|
| 167 |
)
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
return list(tmp_data.values())
|
| 170 |
except Exception as e:
|
| 171 |
# If the data is not valid, return the original data
|
|
@@ -188,7 +196,7 @@ def get_wdi_data(
|
|
| 188 |
per_page: Number of results per page (default is 100, which is the maximum allowed).
|
| 189 |
|
| 190 |
Returns:
|
| 191 |
-
A dictionary with keys `data` and `note`. The `data` key contains a list of indicator data entries requested. The `note` key contains a note about the data returned.
|
| 192 |
"""
|
| 193 |
MAX_INFO = 500
|
| 194 |
note = ""
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import torch
|
| 5 |
import httpx
|
| 6 |
+
import zlib
|
| 7 |
|
| 8 |
from typing import Optional, Any
|
| 9 |
from sentence_transformers import SentenceTransformer
|
|
|
|
| 144 |
]
|
| 145 |
|
| 146 |
|
| 147 |
+
def short_hash(data: dict[str, Any]) -> str:
|
| 148 |
+
return f"{zlib.crc32(json.dumps(data, sort_keys=True).encode()) & 0xFFFF:04x}"
|
| 149 |
+
|
| 150 |
+
|
| 151 |
def _simplify_wdi_data(data: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
| 152 |
"""Simplifies the WDI data to only include the necessary fields. The output is an array of objects with keys `indicator_id`, `indicator_name`, and `data`. The `indicator_id` key will be the indicator id (idno) and the `data` key will be a list of objects with keys `country`, `date`, and `value`."""
|
| 153 |
|
|
|
|
| 170 |
}
|
| 171 |
)
|
| 172 |
|
| 173 |
+
tmp_data[item["indicator"]["id"]]["data"][-1]["claim_id"] = short_hash(
|
| 174 |
+
tmp_data[item["indicator"]["id"]]["data"][-1]
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
return list(tmp_data.values())
|
| 178 |
except Exception as e:
|
| 179 |
# If the data is not valid, return the original data
|
|
|
|
| 196 |
per_page: Number of results per page (default is 100, which is the maximum allowed).
|
| 197 |
|
| 198 |
Returns:
|
| 199 |
+
A dictionary with keys `data` and `note`. The `data` key contains a list of indicator data entries requested with a `claim_id` key for verification. The `note` key contains a note about the data returned.
|
| 200 |
"""
|
| 201 |
MAX_INFO = 500
|
| 202 |
note = ""
|
wdi_mcp_gradio.py
CHANGED
|
@@ -52,7 +52,7 @@ def get_wdi_data(
|
|
| 52 |
per_page: Number of results per page (default is 100, which is the maximum allowed).
|
| 53 |
|
| 54 |
Returns:
|
| 55 |
-
A dictionary with keys `data` and `note`. The `data` key contains a list of indicator data entries requested. The `note` key contains a note about the data returned.
|
| 56 |
"""
|
| 57 |
|
| 58 |
# Parse country_codes_str:
|
|
|
|
| 52 |
per_page: Number of results per page (default is 100, which is the maximum allowed).
|
| 53 |
|
| 54 |
Returns:
|
| 55 |
+
A dictionary with keys `data` and `note`. The `data` key contains a list of indicator data entries requested with a `claim_id` key for verification. The `note` key contains a note about the data returned.
|
| 56 |
"""
|
| 57 |
|
| 58 |
# Parse country_codes_str:
|
wdi_mcp_server.py
CHANGED
|
@@ -56,7 +56,7 @@ async def get_wdi_data(
|
|
| 56 |
per_page: Number of results per page (default is 100, which is the maximum allowed).
|
| 57 |
|
| 58 |
Returns:
|
| 59 |
-
A dictionary with keys `data` and `note`. The `data` key contains a list of indicator data entries requested. The `note` key contains a note about the data returned.
|
| 60 |
"""
|
| 61 |
|
| 62 |
return services.get_wdi_data(
|
|
|
|
| 56 |
per_page: Number of results per page (default is 100, which is the maximum allowed).
|
| 57 |
|
| 58 |
Returns:
|
| 59 |
+
A dictionary with keys `data` and `note`. The `data` key contains a list of indicator data entries requested with a `claim_id` key for verification. The `note` key contains a note about the data returned.
|
| 60 |
"""
|
| 61 |
|
| 62 |
return services.get_wdi_data(
|