From 2b0e4a7dd553dcdb9f5ca69fcc1fdcfa08bddc9e Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Wed, 23 Nov 2022 21:26:26 +0000 Subject: [PATCH] feat(IFC): adds file id and parsing time to root commit object --- .../fileimport-service/ifc/import_file.js | 29 ++++++++++--------- packages/fileimport-service/ifc/index.js | 5 ++-- packages/fileimport-service/ifc/parser_v2.js | 23 +++++++-------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/packages/fileimport-service/ifc/import_file.js b/packages/fileimport-service/ifc/import_file.js index 32f5a146b..b6df86bb1 100644 --- a/packages/fileimport-service/ifc/import_file.js +++ b/packages/fileimport-service/ifc/import_file.js @@ -7,7 +7,7 @@ const { parseAndCreateCommit } = require('./index') async function main() { const cmdArgs = process.argv.slice(2) - const [filePath, userId, streamId, branchName, commitMessage] = cmdArgs + const [filePath, userId, streamId, branchName, commitMessage, fileId] = cmdArgs // eslint-disable-next-line no-console console.log('ARGV: ', filePath, userId, streamId, branchName, commitMessage) @@ -18,27 +18,28 @@ async function main() { data, streamId, userId, - message: filePath + commitMessage || ' Imported file' + message: filePath + commitMessage || ' Imported file', + fileId } if (branchName) ifcInput.branchName = branchName - const output = { + let output = { success: false, error: 'Unknown error' } const commitId = await parseAndCreateCommit(ifcInput) - // try { - // output = { - // success: true, - // commitId - // } - // } catch (err) { - // output = { - // success: false, - // error: err.toString() - // } - // } + try { + output = { + success: true, + commitId + } + } catch (err) { + output = { + success: false, + error: err.toString() + } + } fs.writeFileSync(TMP_RESULTS_PATH, JSON.stringify(output)) diff --git a/packages/fileimport-service/ifc/index.js b/packages/fileimport-service/ifc/index.js index a76625569..a0ca27ee1 100644 --- a/packages/fileimport-service/ifc/index.js +++ b/packages/fileimport-service/ifc/index.js @@ -8,10 +8,11 @@ async function parseAndCreateCommit({ streamId, branchName = 'uploads', userId, - message = 'Manual IFC file upload' + message = 'Manual IFC file upload', + fileId }) { const serverApi = new ServerAPI({ streamId }) - const myParser = new Parser({ serverApi }) + const myParser = new Parser({ serverApi, fileId }) const start = performance.now() const { id, tCount } = await myParser.parse(data) diff --git a/packages/fileimport-service/ifc/parser_v2.js b/packages/fileimport-service/ifc/parser_v2.js index 677d42f48..8f1969749 100644 --- a/packages/fileimport-service/ifc/parser_v2.js +++ b/packages/fileimport-service/ifc/parser_v2.js @@ -10,18 +10,19 @@ const { } = require('./utils') module.exports = class IFCParser { - constructor({ serverApi }) { + constructor({ serverApi, fileId }) { this.ifcapi = new WebIFC.IfcAPI() this.ifcapi.SetWasmPath('./', false) this.serverApi = serverApi + this.fileId = fileId } async parse(data) { await this.ifcapi.Init() this.modelId = this.ifcapi.OpenModel(new Uint8Array(data), { USE_FAST_BOOLS: true }) + this.startTime = performance.now() // prepoulate types - const p1 = performance.now() this.types = await this.getAllTypesOfModel() // prime caches for property sets and their relating objects, as well as, @@ -32,23 +33,15 @@ module.exports = class IFCParser { this.properties = properties this.propCache = {} - // create and save the geometries; we're storing only references locally. - const p2 = performance.now() - console.log(`prop warmup ${(p2 - p1).toFixed(2)}ms`) - this.geometryReferences = await this.createAndSaveMeshes() - const p3 = performance.now() - console.log(`geometry warmup ${(p3 - p2).toFixed(2)}ms`) + // create and save the geometries; we're storing only references locally. + this.geometryReferences = await this.createAndSaveMeshes() // create and save the spatial tree, populating both properties and geometry references // where appropriate this.spatialNodeCount = 0 this.nodeBatch = [] const structure = await this.createSpatialStructure() - const p4 = performance.now() - console.log(`structure ${(p4 - p3).toFixed(2)}ms`) - console.log(`total time spent: ${(p4 - p1).toFixed(2)}ms`) - console.log(structure.id) return { id: structure.id, tCount: structure.closureLen } } @@ -65,6 +58,10 @@ module.exports = class IFCParser { } await this.populateSpatialNode(project, chunks, []) + + this.endTime = performance.now() + project.parseTime = (this.endTime - this.startTime).toFixed(2) + 'ms' + project.fileId = this.fileId if (this.nodeBatch.length !== 0) { await this.flushNodeBatch() } @@ -93,7 +90,7 @@ module.exports = class IFCParser { node.closureLen = node.closure.length node.__closure = this.formatClosure(node.closure) node.id = getHash(node) - // delete node.closure + this.nodeBatch.push(node) if (this.nodeBatch.length > 3000) {