fix(heat-rank): take the reference row from the 24h window, not whichever loaded last

`U.setdefault(key,{})['ref']=t` only guaranteed the key existed -- the assignment
that followed ran unconditionally, so the reference row ended up being whichever
window was loaded last. Iteration order is 24h, 6h, 1h, so for any token that
appeared in the 1h list the reference row was the 1h row.

Most fields read off that row are a current snapshot and are unaffected, but
`price_change_percent` is the change over that row's own window, so the column
headed `24h%` printed a 1h move -- and printed a 24h move for tokens that only
appeared in the 24h list, so the column was not even consistent between rows.
Measured on a stored 7-chain sweep, all five listed tokens were showing their 1h
change: 4Stock printed +29.7% where its 24h move was -21.2%, and MEME printed
+0.1% against a real -18.7%. A reader comparing the list against the exchange
would have found two of five names moving the opposite way.

setdefault now keeps the first window that carried the token, which is 24h for
every listed name (a token absent from the 24h list is already rejected).
Re-scored against the same sweep: same five names, same order, and all five
percentages now match the 24h files exactly. Scores shift by up to 0.5 because a
few snapshot fields differ slightly between the 24h and 1h responses, which were
fetched seconds apart.

One thing this exposes rather than fixes: a token younger than a day now shows
its true 24h change, and for an 8-hour-old token that is +128168%. The number is
correct and useless; a separate change should blank the cell below a day of age.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
chenjunfeng
2026-09-10 14:46:39 +08:00
co-authored by Claude Opus 5
parent 3c49980398
commit ad9ff57741
+6 -1
View File
@@ -278,8 +278,13 @@ if missing: print('missing (excluded):', ', '.join(missing))
VOL ={(ch,iv):{t['address']:(t.get('volume') or 0) for t in ROWS[ch][iv]} for ch in USE for iv in IV if iv in ROWS[ch]}
U={}
for ch in USE:
# The reference row must be the 24h one. Most of what is read off it is a current snapshot and reads
# the same in every window -- market cap, pool, holders, the risk fields -- but price_change_percent is
# that window's own move, so a row taken from the 1h file prints a 1h change under a 24h heading, and
# which window a row came from varied per token. setdefault keeps the FIRST window that carried the
# token (24h, then 6h, then 1h) instead of letting the last one loaded overwrite it.
for iv in ['24h','6h','1h']:
for t in ROWS[ch].get(iv,[]): U.setdefault((ch,t['address']),{})['ref']=t
for t in ROWS[ch].get(iv,[]): U.setdefault((ch,t['address']),{}).setdefault('ref',t)
UNI=[dict(ch=k[0],a=k[1],t=v['ref']) for k,v in U.items()]
def pctl(v):