Skip to content
Snippets Groups Projects
Commit c75f5c15 authored by Gomez Goiri, Aitor's avatar Gomez Goiri, Aitor
Browse files

Considering empty tables

parent 724c468f
No related branches found
No related tags found
No related merge requests found
...@@ -53,32 +53,41 @@ const toSteelLine = stat => [ ...@@ -53,32 +53,41 @@ const toSteelLine = stat => [
const toCementLine = stat => [stat.total.toFixed(3), humanizePrice(stat.price)] const toCementLine = stat => [stat.total.toFixed(3), humanizePrice(stat.price)]
const getStats = async apiClient => { const printMainTable = ({ perSteelCompany = [] }) => {
const stats = await apiClient.getStats() const header = [
let tableValues = [
[
"", "",
"Total slag\nt", "Total slag\nt",
"Reused\nt [%]", "Reused\nt [%]",
"Discarded\nt [%]", "Discarded\nt [%]",
"Price (€/t)\n Avg [Min, Max]" "Price (€/t)\n Avg [Min, Max]"
], ]
...Object.entries(stats.perSteelCompany || []).map(([org, val]) => [ let body = Object.entries(perSteelCompany).map(([org, val]) => [
org, org,
...toSteelLine(val) ...toSteelLine(val)
]) ])
] if (body.length === 0) {
console.log(table(tableValues, TABLE_CONFIG)) body = [header.map(() => "-")]
}
console.log(table([header, ...body], TABLE_CONFIG))
}
tableValues = [ const printCementOrgsTable = ({ perCementCompany = [] }) => {
["", "Total slag\nt", "Price (€/t)\n Avg [Min, Max]"], const header = ["", "Total slag\nt", "Price (€/t)\n Avg [Min, Max]"]
...Object.entries(stats.perCementCompany || []).map(([org, val]) => [ let body = Object.entries(perCementCompany).map(([org, val]) => [
org, org,
...toCementLine(val) ...toCementLine(val)
]) ])
] if (body.length === 0) {
console.log(table(tableValues, TABLE_CONFIG)) body = [header.map(() => "-")]
}
console.log(table([header, ...body], TABLE_CONFIG))
}
const getStats = async apiClient => {
const stats = await apiClient.getStats()
printMainTable(stats)
printCementOrgsTable(stats)
} }
const program = createCLIApp() const program = createCLIApp()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment