示例#1
0
 /// <summary>
 /// Constructor for the <c>DocumentReader</c> object. This
 /// makes use of a DOM document to extract events and provide them
 /// to the core framework. All nodes will be extracted from the
 /// document and queued for extraction as they are requested. This
 /// will ignore any comment nodes as they should not be considered.
 /// </summary>
 /// <param name="document">
 /// this is the document that is to be read
 /// </param>
 public DocumentReader(Document document) {
    this.queue = new NodeExtractor(document);
    this.stack = new NodeStack();
    this.stack.push(document);
 }
示例#2
0
        public async Task <IActionResult> ExtractNodes([FromBody] FeatureCollection josm)
        {
            try
            {
                // Start a timer.
                DateTime start = DateTime.Now;

                // Attempt to classify.
                if (!NodeClassifier.Classify(josm, out List <string> errors))
                {
                    return(BadRequest(new { NodeExtractorErrors = errors }));
                }

                // Validate the data.
                if (!NodeValidator.Validate(josm, out errors, out List <string> warnings))
                {
                    return(BadRequest(new { NodeExtractorErrors = errors, NodeExtractorWarnings = warnings }));
                }

                // Parse the JOSM data to nodes and edges.
                if (!NodeExtractor.ParseNodeSource(josm, out List <Node> nodes, out List <NodeEdge> edges))
                {
                    errors.Add("Parsing of JOSM failed!");
                    return(BadRequest(new { NodeExtractorErrors = errors }));
                }

                // Check for broken connections on this floor.
                List <string> brokenConnections = NodeExtractor.VerifyNodeEdgesSingleFloor(nodes, edges);

                if (brokenConnections.Count > 0)
                {
                    errors.AddRange(brokenConnections);
                    return(BadRequest(new { NodeExtractorErrors = errors }));
                }

                // Check for duplicates.
                foreach (Node node in nodes)
                {
                    int duplicateCount = nodes.Count(n => n.NodeId == node.NodeId);
                    if (duplicateCount > 1)
                    {
                        errors.Add($"Node Extractor: The node Id {node.NodeId} is duplicated {duplicateCount} times, Ids must be unique!");
                        return(BadRequest(new { NodeExtractorErrors = errors }));
                    }
                }

                // Write nodes to database.
                await WriteNodesToDatabase(nodes);

                // Calculate weights.
                edges = NodeExtractor.CalculateWeights(nodes, edges, AppSettings.EdgeCaseWeights);

                // Write edges to database.
                await WriteNodeEdgesToDatabase(edges);

                await DissDatabaseContext.SaveChangesAsync();

                // Stop the timer and return to the client a message indicating run time and warnings.
                DateTime end = DateTime.Now;
                return(Created("", new { processingTime = $"Node Extractor for {nodes.FirstOrDefault()?.BuildingCode.ToUpper()}{nodes.FirstOrDefault()?.Floor} finished in: {Math.Round((end - start).TotalMilliseconds, 2)}ms.", warnings }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }