Skip to content

Commit ba21e8d

Browse files
committed
ITN fixes
Additional changes made live during the ITN.
1 parent 12f5e0e commit ba21e8d

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

htmx/diagnostics.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ User = orcfax
1111
Type = simple
1212
WorkingDirectory = /home/orcfax/itn-api/
1313
ExecStart = /bin/bash -c '/home/orcfax/itn-api/htmx/start_diag.sh'
14-
KillSignal = SIGINT
14+
KillSignal = SIGKILL
1515
TimeoutStopSec = 300
1616
LimitNOFILE = 32768
1717
Restart = always

htmx/index.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h2>Node counts</h2>
5656
<h2>Active collector counts</h2>
5757
<div
5858
hx-get="{baseURL}/online_collectors"
59-
hx-trigger="every 30s"
59+
hx-trigger="every 120s"
6060
hx-swap="innerHTML"
6161
/>
6262
</div>

service/itn-api.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ User = orcfax
1111
Type = simple
1212
WorkingDirectory = /home/orcfax/itn-api/
1313
ExecStart = /bin/bash -c '/home/orcfax/itn-api/service/start_itn_api.sh'
14-
KillSignal = SIGINT
14+
KillSignal = SIGKILL
1515
TimeoutStopSec = 300
1616
LimitNOFILE = 32768
1717
Restart = always

src/itn_api/api.py

+2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ async def get_participants_counts_day_csv(
182182
date_start: str = "1970-01-01", date_end: str = "1970-01-03"
183183
) -> str:
184184
"""Return participants in ITN."""
185+
logger.info("generating participant csv: get db data")
185186
report = reports.get_participants_counts_date_range(app, date_start, date_end)
187+
logger.info("data retrieved for participant csv: creating count csv")
186188
csv_report = reports.generate_participant_count_csv(report)
187189
return csv_report
188190

src/itn_api/reports.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ def get_participants_counts_date_range(
232232
logger.info("no addresses: '%s'", len(feeds))
233233
addr_minute_values, addr_feed_values = _get_addr_minute_feed_dicts(data, addresses)
234234
addr_minute_values = helpers.dedupe_dicts(addr_minute_values)
235+
logger.info("retrieving data from kupo")
235236
address_data = _get_basic_addr_data(app.state.kupo_url, app.state.kupo_port)
237+
logger.info("processing json report")
236238
report = _process_json_report(
237239
address_data, date_start, date_end, addr_minute_values, addr_feed_values, feeds
238240
)
@@ -248,8 +250,8 @@ def _get_participant_data_by_date_range(
248250
f"""
249251
select address, date_time, feed_id
250252
from data_points
251-
where date_time > date('{date_start}')
252-
and date_time < date('{date_end}')
253+
where date_time > '{date_start}'
254+
and date_time < '{date_end}'
253255
order by address;
254256
"""
255257
)
@@ -271,7 +273,17 @@ def generate_participant_count_csv(report: dict) -> str:
271273
rows = []
272274
for stake_addr, value in data.items():
273275
participant = stake_addr
274-
license_no = value.get("license", "").replace("Validator License", "").strip()
276+
try:
277+
license_no = (
278+
value.get("license", "").replace("Validator License", "").strip()
279+
)
280+
except AttributeError:
281+
logger.error(
282+
"cannot retrieve license no from: value '%s' stake: '%s'",
283+
value,
284+
stake_addr,
285+
)
286+
continue
275287
stake = humanize.intcomma(int(value.get("stake", 0))).replace(",", "")
276288
total_data_points = value.get("total_data_points", 0)
277289
average_per_feed = value.get("average_mins_collecting_per_feed", 0)
@@ -321,7 +333,11 @@ async def get_locations(app: FastAPI) -> list:
321333
cursor = app.state.connection.cursor()
322334
try:
323335
cursor.execute(
324-
"select min(node_id), raw_data from data_points group by node_id;"
336+
"""select min(node_id), raw_data
337+
from data_points
338+
where date_time >= (SELECT date_sub(Now(), interval 60 minute))
339+
group by node_id;
340+
"""
325341
)
326342
except mariadb.Error:
327343
return "zero collectors online"
@@ -366,7 +382,7 @@ async def get_locations_stake_key(app: FastAPI) -> list:
366382
cursor.execute(
367383
"""select node_id, raw_data, min(address), date_time
368384
from data_points
369-
where date_time >= (SELECT DATE_SUB(NOW(), INTERVAL 1 DAY))
385+
where date_time >= (SELECT DATE_SUB(NOW(), INTERVAL 60 minute))
370386
group by address;
371387
"""
372388
)

0 commit comments

Comments
 (0)