Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 103x 103x 103x 103x 103x 26x 7x 21x | import type { EconomicsResultLineRead } from "@/api/apiStore.gen";
import {
isPresent,
numericField,
objectValue,
stringField,
} from "./valueParsing";
export const OPERATING_EXPENSE_LABELS = [
"Derived fuel costs",
"Utility costs",
"Feedstock costs",
"Disposal costs",
"Maintenance",
"Labour",
"Custom",
];
export const ANNUAL_EXPENSES_ROW_KEY = "metric.annual_opex";
export const ANNUAL_REVENUE_ROW_KEY = "metric.annual_revenue";
export const ANNUAL_PROFIT_ROW_KEY = "metric.annual_profit";
export const OPERATING_SUMMARY_ROW_KEYS = [
ANNUAL_EXPENSES_ROW_KEY,
ANNUAL_REVENUE_ROW_KEY,
ANNUAL_PROFIT_ROW_KEY,
];
export function operatingBreakdownLabel(line: EconomicsResultLineRead) {
const category = operatingCategory(line);
if (category === "energy") {
return operatingLineIsRevenue(line) ? "Utility credits" : "Utility costs";
}
Iif (category === "feedstock") return "Feedstock costs";
Iif (category === "output_revenue") return "Sold output revenue";
Iif (category === "disposal") return "Disposal costs";
Iif (category === "maintenance") return "Maintenance";
Iif (category === "labour") return "Labour";
Iif (category === "fixed_annual") return null;
return "Custom";
}
export function operatingCategory(line: EconomicsResultLineRead) {
const payload = objectValue(line.warning_payload);
return stringField(payload?.category || payload?.line_type);
}
export function operatingLineIsRevenue(line: EconomicsResultLineRead) {
const payload = objectValue(line.warning_payload);
return (
stringField(payload?.economic_effect) === "revenue" ||
stringField(payload?.category) === "output_revenue"
);
}
export function operatingExpenseRows(lines: EconomicsResultLineRead[]) {
return lines.filter(
(line) => line.group === "operating_lines" && !operatingLineIsRevenue(line),
);
}
export function revenueRows(lines: EconomicsResultLineRead[]) {
return lines.filter(
(line) => line.group === "operating_lines" && operatingLineIsRevenue(line),
);
}
export function operatingBreakdownRows(lines: EconomicsResultLineRead[]) {
const grouped = new Map<string, EconomicsResultLineRead[]>();
for (const line of operatingExpenseRows(lines)) {
const label = operatingBreakdownLabel(line);
Iif (!label) continue;
grouped.set(label, [...(grouped.get(label) ?? []), line]);
}
return grouped;
}
export function operatingSummaryRows(lines: EconomicsResultLineRead[]) {
const byRowKey = new Map(lines.map((line) => [line.row_key, line]));
return OPERATING_SUMMARY_ROW_KEYS.map((rowKey) =>
byRowKey.get(rowKey),
).filter(isPresent);
}
export function sumLineAmounts(lines: EconomicsResultLineRead[]) {
return lines.reduce(
(total, line) => total + (numericField(line.amount) ?? 0),
0,
);
}
|