Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/unit/handlers/finance.handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions workers/lib/server/handlers/finance.handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Loading