mindee
Version:
Mindee Client Library for Node.js
142 lines (141 loc) • 5.88 kB
JavaScript
"use strict";
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _EnergyBillV1EnergyUsage_instances, _EnergyBillV1EnergyUsage_printableValues;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnergyBillV1EnergyUsage = void 0;
const common_1 = require("../../../parsing/common");
const geometry_1 = require("../../../geometry");
/**
* Details of energy consumption.
*/
class EnergyBillV1EnergyUsage {
constructor({ prediction = {} }) {
_EnergyBillV1EnergyUsage_instances.add(this);
/** Confidence score */
this.confidence = 0.0;
/**
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
this.polygon = new geometry_1.Polygon();
if (prediction["consumption"] !== undefined &&
prediction["consumption"] !== null &&
!isNaN(prediction["consumption"])) {
this.consumption = +parseFloat(prediction["consumption"]);
}
else {
this.consumption = null;
}
this.description = prediction["description"];
this.endDate = prediction["end_date"];
this.startDate = prediction["start_date"];
if (prediction["tax_rate"] !== undefined &&
prediction["tax_rate"] !== null &&
!isNaN(prediction["tax_rate"])) {
this.taxRate = +parseFloat(prediction["tax_rate"]);
}
else {
this.taxRate = null;
}
if (prediction["total"] !== undefined &&
prediction["total"] !== null &&
!isNaN(prediction["total"])) {
this.total = +parseFloat(prediction["total"]);
}
else {
this.total = null;
}
this.unit = prediction["unit"];
if (prediction["unit_price"] !== undefined &&
prediction["unit_price"] !== null &&
!isNaN(prediction["unit_price"])) {
this.unitPrice = +parseFloat(prediction["unit_price"]);
}
else {
this.unitPrice = null;
}
this.pageId = prediction["page_id"];
this.confidence = prediction["confidence"] ? prediction.confidence : 0.0;
if (prediction["polygon"]) {
this.polygon = prediction.polygon;
}
}
/**
* Default string representation.
*/
toString() {
const printable = __classPrivateFieldGet(this, _EnergyBillV1EnergyUsage_instances, "m", _EnergyBillV1EnergyUsage_printableValues).call(this);
return ("Consumption: " +
printable.consumption +
", Description: " +
printable.description +
", End Date: " +
printable.endDate +
", Start Date: " +
printable.startDate +
", Tax Rate: " +
printable.taxRate +
", Total: " +
printable.total +
", Unit of Measure: " +
printable.unit +
", Unit Price: " +
printable.unitPrice);
}
/**
* Output in a format suitable for inclusion in an rST table.
*/
toTableLine() {
const printable = __classPrivateFieldGet(this, _EnergyBillV1EnergyUsage_instances, "m", _EnergyBillV1EnergyUsage_printableValues).call(this);
return ("| " +
printable.consumption.padEnd(11) +
" | " +
printable.description.padEnd(36) +
" | " +
printable.endDate.padEnd(10) +
" | " +
printable.startDate.padEnd(10) +
" | " +
printable.taxRate.padEnd(8) +
" | " +
printable.total.padEnd(9) +
" | " +
printable.unit.padEnd(15) +
" | " +
printable.unitPrice.padEnd(10) +
" |");
}
}
exports.EnergyBillV1EnergyUsage = EnergyBillV1EnergyUsage;
_EnergyBillV1EnergyUsage_instances = new WeakSet(), _EnergyBillV1EnergyUsage_printableValues = function _EnergyBillV1EnergyUsage_printableValues() {
return {
consumption: this.consumption !== undefined ? (0, common_1.floatToString)(this.consumption) : "",
description: this.description ?
this.description.length <= 36 ?
(0, common_1.cleanSpecialChars)(this.description) :
(0, common_1.cleanSpecialChars)(this.description).slice(0, 33) + "..." :
"",
endDate: this.endDate ?
this.endDate.length <= 10 ?
(0, common_1.cleanSpecialChars)(this.endDate) :
(0, common_1.cleanSpecialChars)(this.endDate).slice(0, 7) + "..." :
"",
startDate: this.startDate ?
this.startDate.length <= 10 ?
(0, common_1.cleanSpecialChars)(this.startDate) :
(0, common_1.cleanSpecialChars)(this.startDate).slice(0, 7) + "..." :
"",
taxRate: this.taxRate !== undefined ? (0, common_1.floatToString)(this.taxRate) : "",
total: this.total !== undefined ? (0, common_1.floatToString)(this.total) : "",
unit: this.unit ?
this.unit.length <= 15 ?
(0, common_1.cleanSpecialChars)(this.unit) :
(0, common_1.cleanSpecialChars)(this.unit).slice(0, 12) + "..." :
"",
unitPrice: this.unitPrice !== undefined ? (0, common_1.floatToString)(this.unitPrice) : "",
};
};