UNPKG

gnss_solutions

Version:

Javascript GNSS solution analysis library

130 lines (114 loc) 4.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CSVWriter = exports.SOLUTION_STATUS_CSV_HEADER = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); exports.makeFileName = makeFileName; var _coords = require("../coords"); var _solution_table = require("../solution_table"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /* * Copyright (c) 2016 Swift Navigation Inc. * Contact: engineering@swiftnav.com * * This source is subject to the license found in the file 'LICENSE' which must * be be distributed together with this source. All other rights reserved. * * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. */ // Streaming CSV writer for solution events. var csvWriter = require('csv-write-stream'); /** * CSV header for SolutionStatusEvent. */ var SOLUTION_STATUS_CSV_HEADER = exports.SOLUTION_STATUS_CSV_HEADER = Object.keys(new _solution_table.SolutionStatusEvent(new _coords.SolutionStatus(new Date(), new _coords.ECEFSolution(0, 0, 0))).toJSON()); /** * Get a timestamped CSV filename. Follows the timestamping convention used by * SBP serial link @ * https://github.com/swift-nav/piksi_tools/blob/master/piksi_tools/serial_link.py#L39: * will look like: gnss-solutions-%Y%m%d-%H%M%S.log.csv. * * @param {string} suffix - Optional suffix * @return {string} - Timestamped filename. */ function makeFileName() { var suffix = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0]; var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); var pfx = suffix === undefined ? '' : "-" + suffix; var fmt = "gnss-solutions-" + year + month + day + "-" + hours + minutes + seconds + pfx + ".log.csv"; return fmt; } /** * A CSV writer writes out JSON objects to a text file. * * In this library, this is typically used to save out SolutionStatusEvent's to * CSV. For example: * * ``` * let filename = CSVWriter.makeFileName(); * let headers = SOLUTION_STATUS_CSV_HEADER; * let writer = CSVWriter(headers); * writer.getWriter().pipe(fs.createWriteStream(filename)); * let simEvent = SolutionStatusEvent(...); * writer.write(simEvent.toJSON()); * writer.end(); * ``` * * @param {Array<string>} headers - CSV headers */ var CSVWriter = exports.CSVWriter = function () { /** * Construct a CSV writer object. * * @param {Array<string>} headers - CSV headers * @return {CSVWriter} */ function CSVWriter(headers) { _classCallCheck(this, CSVWriter); var options = { separator: ',', newline: '\n', headers: headers, sendHeaders: true }; this.writer = csvWriter(options); } /** * Get underlying CSV writer as a Node stream.Transform. * * @return {stream.Transform} */ _createClass(CSVWriter, [{ key: "getWriter", value: function getWriter() { return this.writer; } /** * Write an object record to the CSV file. * * @param {Object} obj - The record to write to CSV. */ }, { key: "write", value: function write(obj) { this.writer.write(obj); } /** * Indicate end of stream. */ }, { key: "end", value: function end() { this.writer.end(); } }]); return CSVWriter; }();