diff --git a/apps/pubadmin-cli/index.js b/apps/pubadmin-cli/index.js index 86ddc4bea9011ed2b2b6162e693e8d069164736e..6c73a1fa3dca5b846a506630555f3a96bd81cb6d 100644 --- a/apps/pubadmin-cli/index.js +++ b/apps/pubadmin-cli/index.js @@ -53,32 +53,41 @@ const toSteelLine = stat => [ const toCementLine = stat => [stat.total.toFixed(3), humanizePrice(stat.price)] +const printMainTable = ({ perSteelCompany = [] }) => { + const header = [ + "", + "Total slag\nt", + "Reused\nt [%]", + "Discarded\nt [%]", + "Price (€/t)\n Avg [Min, Max]" + ] + let body = Object.entries(perSteelCompany).map(([org, val]) => [ + org, + ...toSteelLine(val) + ]) + if (body.length === 0) { + body = [header.map(() => "-")] + } + console.log(table([header, ...body], TABLE_CONFIG)) +} + +const printCementOrgsTable = ({ perCementCompany = [] }) => { + const header = ["", "Total slag\nt", "Price (€/t)\n Avg [Min, Max]"] + let body = Object.entries(perCementCompany).map(([org, val]) => [ + org, + ...toCementLine(val) + ]) + if (body.length === 0) { + body = [header.map(() => "-")] + } + console.log(table([header, ...body], TABLE_CONFIG)) +} + const getStats = async apiClient => { const stats = await apiClient.getStats() - let tableValues = [ - [ - "", - "Total slag\nt", - "Reused\nt [%]", - "Discarded\nt [%]", - "Price (€/t)\n Avg [Min, Max]" - ], - ...Object.entries(stats.perSteelCompany || []).map(([org, val]) => [ - org, - ...toSteelLine(val) - ]) - ] - console.log(table(tableValues, TABLE_CONFIG)) - - tableValues = [ - ["", "Total slag\nt", "Price (€/t)\n Avg [Min, Max]"], - ...Object.entries(stats.perCementCompany || []).map(([org, val]) => [ - org, - ...toCementLine(val) - ]) - ] - console.log(table(tableValues, TABLE_CONFIG)) + printMainTable(stats) + printCementOrgsTable(stats) } const program = createCLIApp()