Skip to content

Commit

Permalink
Add CSV export of detected changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Son-HNguyen committed Apr 16, 2024
1 parent 3cde46b commit 190ca36
Show file tree
Hide file tree
Showing 9 changed files with 492 additions and 58 deletions.
6 changes: 3 additions & 3 deletions config/citygmlv2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ matcher.tolerance.solids = 0.8
# Allow check for translation of geometries with a distance up to
matcher.translation.distance = 3.0

# Export change logs
matcher.export.path = "output/logs/changes.log"

# Max. wait time in seconds for matcher threads to finish
matcher.concurrent.timeout = 360000

# Batch size for top-level features
matcher.toplevel.batch.size = 10

# Location of export directory
matcher.changes.export.path = "output/changes"

# INTERPRETATION CONFIGURATIONS
# .....................

Expand Down
6 changes: 3 additions & 3 deletions config/citygmlv3.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ matcher.tolerance.solids = 0.8
# Allow check for translation of geometries with a distance up to
matcher.translation.distance = 5

# Export change logs
matcher.export.path = "output/logs/changes.log"

# Max. wait time in seconds for matcher threads to finish
matcher.concurrent.timeout = 360000

# Batch size for top-level features
matcher.toplevel.batch.size = 10

# Location of export directory
matcher.changes.export.path = "output/changes"

# INTERPRETATION CONFIGURATIONS
# .....................

Expand Down
55 changes: 51 additions & 4 deletions src/main/java/jgraf/citygml/CityGMLNeo4jDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import jgraf.neo4j.Neo4jGraphRef;
import jgraf.neo4j.diff.*;
import jgraf.neo4j.factory.*;
import jgraf.utils.BatchUtils;
import jgraf.utils.ClazzUtils;
import jgraf.utils.GraphUtils;
import jgraf.utils.MetricBoundarySurfaceProperty;
import jgraf.utils.*;
import org.apache.commons.geometry.euclidean.threed.ConvexPolygon3D;
import org.apache.commons.geometry.euclidean.threed.line.Line3D;
import org.apache.commons.lang3.function.TriConsumer;
Expand All @@ -35,7 +32,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -958,6 +957,8 @@ private Node getAnchorNode(Transaction tx, Node node, Label anchor) {

protected abstract MetricBoundarySurfaceProperty metricFromBoundarySurfaceProperty(Node node, Precision.DoubleEquivalence lengthPrecision, Precision.DoubleEquivalence anglePrecision);

protected abstract void exportChangesCSV();

public abstract void testImportAndExport(String importFilePath, String exportFilePath);

public void exportRTreeFootprints(String folderPath) {
Expand Down Expand Up @@ -993,12 +994,58 @@ public void storeRTrees() {
@Override
public void summarize() {
super.summarize();

// exportChangesText();
exportChangesCSV();

if (config.NEO4J_RTREE_STORE) {
// Store all RTree layers in the database for later use/import
storeRTrees();
}
}

public void exportChangesText() {
// Check directory
File directory = new File(config.MATCHER_CHANGES_EXPORT_PATH);
if (!directory.exists()) {
directory.mkdirs();
logger.info("Directory for exporting logs of changes does not exist, created {}", directory.getPath());
}
if (!directory.isDirectory()) {
logger.error("Export path is not a directory: {}, nothing exported", directory.getPath());
return;
}
logger.info("Exporting logs of changes to in directory {}", directory.getPath());

File logs = new File(directory, "changes.log");
try (BufferedWriter bw = new BufferedWriter(new FileWriter(logs))) {
List<Class<?>> classes = List.of(
InsertNodeChange.class,
DeleteNodeChange.class,
InsertPropChange.class,
DeletePropChange.class,
UpdatePropChange.class
);
classes.forEach(cl -> {
try (Transaction tx = graphDb.beginTx()) {
tx.findNodes(Label.label(cl.getName())).forEachRemaining(node -> {
try {
bw.append(ChangeUtils.toString(node));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (Exception e) {
logger.error(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
}
});
bw.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
logger.info("Exported changes to {}", logs.getPath());
}

public RTree<Neo4jGraphRef, Geometry>[] getRtrees() {
return rtrees;
}
Expand Down
Loading

0 comments on commit 190ca36

Please sign in to comment.