Skip to content

v0.2.54..v0.2.55 changeset ChangesetDeriveCmd.cpp

Garret Voltz edited this page Aug 14, 2020 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/cmd/ChangesetDeriveCmd.cpp b/hoot-core/src/main/cpp/hoot/core/cmd/ChangesetDeriveCmd.cpp
index df70abf..4e68cdf 100644
--- a/hoot-core/src/main/cpp/hoot/core/cmd/ChangesetDeriveCmd.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/cmd/ChangesetDeriveCmd.cpp
@@ -29,12 +29,20 @@
 #include <hoot/core/algorithms/changeset/ChangesetCreator.h>
 #include <hoot/core/cmd/BoundedCommand.h>
 #include <hoot/core/util/Factory.h>
+#include <hoot/core/io/ChangesetStatsFormat.h>
+#include <hoot/core/util/StringUtils.h>
+
+// Qt
+#include <QFileInfo>
+#include <QElapsedTimer>
 
 namespace hoot
 {
 
 /**
  * Derives a set of changes given one or two map inputs
+ *
+ * @todo command needs some input error handling tests
  */
 class ChangesetDeriveCmd : public BoundedCommand
 {
@@ -51,15 +59,39 @@ public:
 
   virtual int runSimple(QStringList& args) override
   {
+    QElapsedTimer timer;
+    timer.start();
+
     BoundedCommand::runSimple(args);
 
     bool printStats = false;
+    QString outputStatsFile;
     if (args.contains("--stats"))
     {
       printStats = true;
+      const int statsIndex = args.indexOf("--stats");
+      LOG_VARD(statsIndex);
+      // See similar note in ConflateCmd's parsing of --changeset-stats.
+      if (statsIndex != -1 && statsIndex != (args.size() - 1) &&
+          !args[statsIndex + 1].startsWith("--"))
+      {
+        outputStatsFile = args[statsIndex + 1];
+        LOG_VARD(outputStatsFile);
+        QFileInfo statsInfo(outputStatsFile);
+        LOG_VARD(statsInfo.completeSuffix());
+        if (!ChangesetStatsFormat::isValidFileOutputFormat(statsInfo.completeSuffix()))
+        {
+          outputStatsFile = "";
+        }
+        else
+        {
+          args.removeAll(outputStatsFile);
+        }
+      }
       args.removeAll("--stats");
     }
     LOG_VARD(printStats);
+    LOG_VARD(outputStatsFile);
 
     if (args.size() < 3 || args.size() > 4)
     {
@@ -88,7 +120,10 @@ public:
         QString("%1 with output: " + output + " takes three parameters.").arg(getName()));
     }
 
-    ChangesetCreator(printStats, osmApiDbUrl).create(output, input1, input2);
+    ChangesetCreator(printStats, outputStatsFile, osmApiDbUrl).create(output, input1, input2);
+
+    LOG_STATUS(
+      "Changeset generated in " << StringUtils::millisecondsToDhms(timer.elapsed()) << " total.");
 
     return 0;
   }
Clone this wiki locally