UNPKG

pddl-workspace

Version:
61 lines 2.7 kB
"use strict"; /* -------------------------------------------------------------------------------------------- * Copyright (c) Jan Dolejsi 2020. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ Object.defineProperty(exports, "__esModule", { value: true }); exports.XmlPlanBuilder = void 0; const PlanStep_1 = require("../PlanStep"); class XmlPlanBuilder { constructor(planTimeScale) { this.planTimeScale = planTimeScale; this.xmlText = ''; } static isXmlStart(outputLine) { return outputLine.match(/<\?xml /) !== null; } appendLine(outputLine) { this.xmlText += outputLine; } isComplete() { return this.xmlText.match(/<\/Plan>\s*$/) !== null; } async getPlanSteps() { // eslint-disable-next-line @typescript-eslint/no-var-requires const xml2js = require('xml2js'); const parser = new xml2js.Parser(); // eslint-disable-next-line @typescript-eslint/no-explicit-any let plan; try { plan = await parser.parseStringPromise(this.xmlText); } catch (err) { console.log(err); throw err; } const steps = []; for (const happening of plan.Plan.Actions[0].OrderedHappening) { //const happeningId = happening.HappeningID[0]; if (happening.Happening[0].ActionStart) { const actionStart = happening.Happening[0].ActionStart[0]; const startTime = this.parseTimeStamp(actionStart.ExpectedStartTime[0]); const actionName = actionStart.Name[0]; const actionParameters = actionStart.Parameters // eslint-disable-next-line @typescript-eslint/no-explicit-any ? ' ' + actionStart.Parameters[0].Parameter.map((p) => p.Symbol[0]).join(' ') : ''; const isDurative = actionStart.ExpectedDuration !== undefined; const duration = isDurative ? this.parseTimeStamp(actionStart.ExpectedDuration[0]) : undefined; steps.push(new PlanStep_1.PlanStep(startTime, actionName + actionParameters, isDurative, duration, -1)); } } return steps; } parseTimeStamp(timestamp) { // eslint-disable-next-line @typescript-eslint/no-var-requires const pxd = require('parse-xsd-duration'); return pxd.default(timestamp) / this.planTimeScale; } } exports.XmlPlanBuilder = XmlPlanBuilder; //# sourceMappingURL=XmlPlanBuilder.js.map