changeset 182:11a9ce2fa331

Add ability to read segment boundaries from a file; test for it; bump version no; make test script bail out if path has spaces (can't cope with that, sheesh)
author Chris Cannam
date Fri, 09 Jan 2015 11:48:12 +0000
parents c5619f2a63b1
children 50d9a9a46f47
files runner/main.cpp tests/include.sh tests/test-summaries/test-summaries.sh tests/test-summaries/transforms/segmentlist tests/test.sh version.h
diffstat 5 files changed, 96 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/runner/main.cpp	Thu Oct 16 13:42:21 2014 +0100
+++ b/runner/main.cpp	Fri Jan 09 11:48:12 2015 +0000
@@ -453,6 +453,60 @@
     return expanded;
 }
 
+bool
+readSegmentBoundaries(QString url, 
+                      Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries &boundaries)
+{
+    FileSource source(url);
+    if (!source.isAvailable()) {
+        cerr << "File or URL \"" << url << "\" could not be retrieved" << endl;
+        return false;
+    }
+    source.waitForData();
+
+    QString filename = source.getLocalFilename();
+    QFile file(filename);
+    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+        cerr << "File \"" << filename << "\" could not be read" << endl;
+        return false;
+    }
+
+    QTextStream in(&file);
+    int lineNo = 0;
+    
+    while (!in.atEnd()) {
+
+        ++lineNo;
+        
+        QString line = in.readLine();
+        if (line.startsWith("#")) continue;
+
+        QStringList bits = line.split(",", QString::SkipEmptyParts);
+        QString importantBit;
+        if (!bits.empty()) {
+            bits = bits[0].split(" ", QString::SkipEmptyParts);
+        }
+        if (!bits.empty()) {
+            importantBit = bits[0];
+        }
+        if (importantBit == QString()) {
+            cerr << "WARNING: Skipping line " << lineNo << " (no content found)"
+                 << endl;
+            continue;
+        }
+        bool good = false;
+        boundaries.insert(Vamp::RealTime::fromSeconds
+                          (importantBit.toDouble(&good)));
+        if (!good) {
+            cerr << "Unparseable or non-numeric segment boundary at line "
+                 << lineNo << endl;
+            return false;
+        }
+    }
+
+    return true;
+}
+
 int main(int argc, char **argv)
 {
     QCoreApplication application(argc, argv);
@@ -600,6 +654,20 @@
                     }
                 }
             }
+        } else if (arg == "--segments-from") {
+            if (last) {
+                cerr << myname << ": argument expected for \""
+                     << arg << "\" option" << endl;
+                cerr << helpStr << endl;
+                exit(2);
+            } else {
+                QString segmentFilename = args[++i];
+                if (!readSegmentBoundaries(segmentFilename, boundaries)) {
+                    cerr << myname << ": failed to read segment boundaries from file" << endl;
+                    cerr << helpStr << endl;
+                    exit(2);
+                }
+            }
         } else if (arg == "-m" || arg == "--multiplex") {
             multiplex = true;
             continue;
--- a/tests/include.sh	Thu Oct 16 13:42:21 2014 +0100
+++ b/tests/include.sh	Fri Jan 09 11:48:12 2015 +0000
@@ -1,8 +1,20 @@
 
-mypath=`dirname $0`
+set -e
 
-version=1.1
-nextversion=1.2
+mypath=$(dirname $0)
+
+case "$(pwd)/$mypath" in
+    *" "*)
+	echo 1>&2
+	echo "ERROR: Test scripts do not handle paths containing spaces (yes, I know)" 1>&2
+	echo "(Path is: \"$(pwd)/$mypath\")" 1>&2
+	exit 1;;
+    *)
+    ;;
+esac
+
+version=1.2
+nextversion=1.3
 
 testdir=$mypath/..
 r=$testdir/../sonic-annotator
--- a/tests/test-summaries/test-summaries.sh	Thu Oct 16 13:42:21 2014 +0100
+++ b/tests/test-summaries/test-summaries.sh	Fri Jan 09 11:48:12 2015 +0000
@@ -27,6 +27,8 @@
 stransform=$mypath/transforms/detectionfunction.n3 
 sexpected=$mypath/expected/summaries-from-rdf
 
+seglist=$mypath/transforms/segmentlist
+
 $r -t $transform -w csv --csv-stdout $infile > $tmpfile 2>/dev/null || \
     fail "Fails to run transform $transform"
 
@@ -63,6 +65,12 @@
 compare $tmpfile ${expected}-segments.csv || \
     faildiff "Output mismatch for transform $stransform with segments" $tmpfile ${expected}-segments.csv
 
+$r -t $transform -w csv --csv-stdout --summary-only -S median --segments-from $seglist $infile2 > $tmpfile 2>/dev/null || \
+    fail "Fails to run transform $stransform with CSV output and segments from segment list"
+
+compare $tmpfile ${expected}-segments.csv || \
+    faildiff "Output mismatch for transform $stransform with segments from segment list" $tmpfile ${expected}-segments.csv
+
 $r -t $stransform -w rdf --rdf-stdout $infile > $tmpfile 2>/dev/null || \
     fail "Fails to run transform $stransform with RDF output"
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-summaries/transforms/segmentlist	Fri Jan 09 11:48:12 2015 +0000
@@ -0,0 +1,4 @@
+# ignore this
+0
+# 4,"ignore this too"
+,9.9,15.2,"some label that should also be ignored","this line should be read as just nine point nine"
--- a/version.h	Thu Oct 16 13:42:21 2014 +0100
+++ b/version.h	Fri Jan 09 11:48:12 2015 +0000
@@ -1,1 +1,1 @@
-#define RUNNER_VERSION "1.1"
+#define RUNNER_VERSION "1.2"