node-djiparsetxt
Version:
command-line application that reads a DJI '.txt' file and outputs a json.
123 lines • 4.48 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CsvService = exports.RECORD_ORDER = void 0;
var lodash_1 = __importDefault(require("lodash"));
var BaseService_1 = __importDefault(require("./BaseService"));
exports.RECORD_ORDER = [
"CUSTOM",
"OSD",
"HOME",
"GIMBAL",
"RC",
"DEFORM",
"CENTER_BATTERY",
"SMART_BATTERY",
"APP_TIP",
"APP_WARN",
"RC_GPS",
"RC_DEBUG",
"RECOVER",
"APP_GPS",
"FIRMWARE",
"OFDM_DEBUG",
"VISION_GROUP",
"VISION_WARN",
"MC_PARAM",
"APP_OPERATION",
"APP_SER_WARN",
// "JPEG",
"OTHER",
];
var CsvService = /** @class */ (function (_super) {
__extends(CsvService, _super);
function CsvService() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Create header rows data for csv production. Each row object contains properties
* that are stored to be able to create a header of the form 'row.property'.
* @param rows Array of rows to extract the header info from.
*/
CsvService.prototype.getRowHeaders = function (rows) {
var presentTypes = new Set();
var typeProps = {};
for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
var row = rows_1[_i];
for (var _a = 0, _b = lodash_1.default.keys(row); _a < _b.length; _a++) {
var type = _b[_a];
presentTypes.add(type);
typeProps[type] = lodash_1.default.keys(row[type]);
}
}
var headers = [];
for (var _c = 0, RECORD_ORDER_1 = exports.RECORD_ORDER; _c < RECORD_ORDER_1.length; _c++) {
var type = RECORD_ORDER_1[_c];
if (presentTypes.has(type)) {
var props = typeProps[type];
headers.push({ type: type, props: props });
}
}
return headers;
};
/**
* Prints the given rows in `rows` in csv format.
* @param rows Array of rows to print the values of.
* @param headerDef The header definition already extracted from the rows.
*/
CsvService.prototype.printRowValues = function (rows, headerDef) {
var lines = [];
for (var _i = 0, rows_2 = rows; _i < rows_2.length; _i++) {
var datarow = rows_2[_i];
var values = [];
for (var _a = 0, headerDef_1 = headerDef; _a < headerDef_1.length; _a++) {
var header = headerDef_1[_a];
for (var _b = 0, _c = header.props; _b < _c.length; _b++) {
var prop = _c[_b];
var path = header.type + "." + prop;
if (lodash_1.default.has(datarow, path)) {
values.push(lodash_1.default.get(datarow, path).toString());
}
else {
values.push("");
}
}
}
lines.push(values.join(","));
}
return lines.join("\n");
};
/**
* Prints the header for the first line of the csv file.
* @param headerDef The header definiton to print.
*/
CsvService.prototype.createHeader = function (headerDef) {
var headers = [];
for (var _i = 0, headerDef_2 = headerDef; _i < headerDef_2.length; _i++) {
var header = headerDef_2[_i];
for (var _a = 0, _b = header.props; _a < _b.length; _a++) {
var prop = _b[_a];
headers.push(header.type + "." + prop);
}
}
return headers.join(",");
};
return CsvService;
}(BaseService_1.default));
exports.CsvService = CsvService;
//# sourceMappingURL=CsvService.js.map