diff --git a/tests/unit/handlers/finance.handlers.test.js b/tests/unit/handlers/finance.handlers.test.js index 0127a15..baae43a 100644 --- a/tests/unit/handlers/finance.handlers.test.js +++ b/tests/unit/handlers/finance.handlers.test.js @@ -355,6 +355,34 @@ test('processTailLogData - processes power and hashrate', (t) => { t.pass() }) +test('processTailLogData - drills into .val (production shape)', (t) => { + const results = [ + [ + { + type: 'powermeter', + data: [ + { ts: 1700006400000, val: { site_power_w: 5000 } }, + { ts: 1700092800000, val: { site_power_w: 6000 } } + ] + }, + { + type: 'miner', + data: [ + { ts: 1700006400000, val: { hashrate_mhs_5m_sum_aggr: 100000 } }, + { ts: 1700092800000, val: { hashrate_mhs_5m_sum_aggr: 120000 } } + ] + } + ] + ] + + const daily = processTailLogData(results) + t.is(daily[1700006400000].powerW, 5000, 'extracts powerW from .val on day 1') + t.is(daily[1700006400000].hashrateMhs, 100000, 'extracts hashrateMhs from .val on day 1') + t.is(daily[1700092800000].powerW, 6000, 'extracts powerW from .val on day 2') + t.is(daily[1700092800000].hashrateMhs, 120000, 'extracts hashrateMhs from .val on day 2') + t.pass() +}) + test('processTailLogData - handles error results', (t) => { const results = [{ error: 'timeout' }] const daily = processTailLogData(results) diff --git a/workers/lib/server/handlers/finance.handlers.js b/workers/lib/server/handlers/finance.handlers.js index 444e90d..9f822b0 100644 --- a/workers/lib/server/handlers/finance.handlers.js +++ b/workers/lib/server/handlers/finance.handlers.js @@ -432,8 +432,10 @@ function processTailLogData (results) { for (const item of items) { const ts = getStartOfDay(item.ts || item.timestamp) if (!daily[ts]) daily[ts] = { powerW: 0, hashrateMhs: 0 } - daily[ts].powerW += (item[AGGR_FIELDS.SITE_POWER] || 0) - daily[ts].hashrateMhs += (item[AGGR_FIELDS.HASHRATE_SUM] || 0) + // Production response wraps measurements under .val; legacy shape was flat. + const val = item.val || item + daily[ts].powerW += (val[AGGR_FIELDS.SITE_POWER] || 0) + daily[ts].hashrateMhs += (val[AGGR_FIELDS.HASHRATE_SUM] || 0) } } }