Skip to content

Commit

Permalink
Combine staking addr with location
Browse files Browse the repository at this point in the history
This information is needed to optimize what folks are doing.
  • Loading branch information
ross-spencer committed Jan 14, 2025
1 parent af7e2ed commit c5106a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/itn_api/htm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def locations_table(locations):
head = """
<table>
<tr>
<th>Stake</th>
<th>Region</th>
<th>Country</th>
</tr>
Expand All @@ -113,13 +114,13 @@ def locations_table(locations):
seen = []
rows = ""
idx = 0
for idx, locale in enumerate(locations):
for addr, locale in locations.items():
idx += 1
region = locale["region"]
country = locale["country"]
if (region, country) in seen:
continue
row = f"""
<tr>
<td>{addr}</td>
<td>{region}</td>
<td nowrap>&nbsp;{country}&nbsp;</td>
</tr>
Expand Down
24 changes: 12 additions & 12 deletions src/itn_api/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,26 +317,26 @@ async def get_locations(app: FastAPI) -> list:
"""
try:
unique_raw_data = app.state.connection.execute(
"select min(node_id), raw_data from data_points group by node_id;"
"select node_id, raw_data, min(address), date_time from data_points group by address;"
)
except apsw.SQLError:
return "zero collectors online"
res = list(unique_raw_data)
countries = []
key_loc = {}
for item in res:
node = item[0]
address = item[2]
if address in key_loc:
continue
message = json.loads(item[1])
try:
loc = message["message"]["identity"]["location"]
countries.append(
(
{
"geo": loc.get("loc"),
"region": loc.get("region"),
"country": loc.get("country"),
}
)
)
country = {
"geo": loc.get("loc"),
"region": loc.get("region"),
"country": loc.get("country"),
}
key_loc[address] = country
except KeyError as err:
logger.error("node: '%s' not reporting location (%s)", node, err)
return countries
return key_loc

0 comments on commit c5106a8

Please sign in to comment.