From a7f62ae2238e507b8fe71074dbcb3130ba6ede34 Mon Sep 17 00:00:00 2001 From: DamonHD Date: Tue, 4 Jun 2024 19:28:05 +0100 Subject: [PATCH] DataVizBeatPoint.write(); --- javasrc/org/hd/d/statsHouse/Main.java | 21 +++++++++++++++++-- .../d/statsHouse/data/DataVizBeatPoint.java | 8 ++++++- .../org/hd/d/statsHouse/data/FileUtils.java | 2 +- .../statsHouse/feedHits/GenerateSummary.java | 8 ++++++- test/Main-feedHits-save-summary-1.launch | 2 +- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/javasrc/org/hd/d/statsHouse/Main.java b/javasrc/org/hd/d/statsHouse/Main.java index 4a20f5d..e9288fa 100644 --- a/javasrc/org/hd/d/statsHouse/Main.java +++ b/javasrc/org/hd/d/statsHouse/Main.java @@ -45,6 +45,7 @@ import javax.sound.sampled.AudioSystem; import org.hd.d.statsHouse.data.DataBounds; +import org.hd.d.statsHouse.data.DataVizBeatPoint; import org.hd.d.statsHouse.data.EOUDataCSV; import org.hd.d.statsHouse.data.FileUtils; import org.hd.d.statsHouse.feedHits.GenerateSummary; @@ -69,7 +70,7 @@ private static void printOptions() System.err.println(" Read independent command lines from specified file or stdin if '-'"); System.err.println(" Do not process further command-line arguments."); System.err.println(" infilename.csv (-play|.(csv|mid|wav)))"); - System.err.println(" -feedHitsSummary -play|.mid {feedHitsDataDir}*"); + System.err.println(" -feedHitsSummary -play| {feedHitsDataDir}*"); GenerationParameters.printOptions(); System.err.println(); System.err.println(" This syntax may be used, one per line, in the command file."); @@ -192,7 +193,23 @@ public static void runCommands(final List> cmdlines, final boolean if("-play".equals(outputFileName)) { playIt(s); } else - { saveIt(s, outputFileName); } + { + saveIt(s, outputFileName + ".mid"); + // Save the data for visualisation if any, else remove any such file. + final DataVizBeatPoint dv = mt.dataRendered(); + final String dvName = outputFileName + ".dat"; + if(null == dv) + { (new File(dvName)).delete(); } + else + { + try(ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); + final OutputStreamWriter w = new OutputStreamWriter(baos)) + { + dv.write(w, false); + FileUtils.replacePublishedFile(dvName, baos.toByteArray(), true); + } + } + } continue; } diff --git a/javasrc/org/hd/d/statsHouse/data/DataVizBeatPoint.java b/javasrc/org/hd/d/statsHouse/data/DataVizBeatPoint.java index 493210f..71afc84 100644 --- a/javasrc/org/hd/d/statsHouse/data/DataVizBeatPoint.java +++ b/javasrc/org/hd/d/statsHouse/data/DataVizBeatPoint.java @@ -62,10 +62,14 @@ public record DataVizBeatPoint( * The first line may optionally be labels if dataLabels is not null. *

* Values in a record may be separated by spaces or commas. + *

+ * Finishes with a flush() to avoid surprises! */ public void write(final Writer w, final boolean commaSep) throws IOException { Objects.requireNonNull(w); + + // Write data column labels, if any. if(null != dataLabels) { // Write column headings. @@ -78,8 +82,8 @@ public void write(final Writer w, final boolean commaSep) throws IOException else { label = label.replace(',', PlaceholderChar).replace(' ', PlaceholderChar); } if(c > 0) { w.write(commaSep ? ',' : ' '); } w.append(label); - w.write('\n'); } + w.write('\n'); } // Write beat vector data rows. @@ -96,5 +100,7 @@ public void write(final Writer w, final boolean commaSep) throws IOException } w.write('\n'); } + + w.flush(); } } diff --git a/javasrc/org/hd/d/statsHouse/data/FileUtils.java b/javasrc/org/hd/d/statsHouse/data/FileUtils.java index 3704c35..3c0a26f 100644 --- a/javasrc/org/hd/d/statsHouse/data/FileUtils.java +++ b/javasrc/org/hd/d/statsHouse/data/FileUtils.java @@ -92,7 +92,7 @@ public static boolean replacePublishedFile(final String name, final byte data[], { if((name == null) || (name.length() == 0)) { throw new IOException("inappropriate file name"); } - if((data == null) || (data.length == 0)) + if((data == null) /* || (data.length == 0) */ ) { throw new IOException("inappropriate file content"); } final File extant = new File(name); diff --git a/javasrc/org/hd/d/statsHouse/feedHits/GenerateSummary.java b/javasrc/org/hd/d/statsHouse/feedHits/GenerateSummary.java index 248f565..6644844 100644 --- a/javasrc/org/hd/d/statsHouse/feedHits/GenerateSummary.java +++ b/javasrc/org/hd/d/statsHouse/feedHits/GenerateSummary.java @@ -24,6 +24,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.hd.d.statsHouse.data.DataVizBeatPoint; import org.hd.d.statsHouse.feedHits.data.FeedStatus; import org.hd.d.statsHouse.feedHits.data.FeedStatusBlock; import org.hd.d.statsHouse.feedHits.data.FeedStatusBlocks; @@ -163,8 +164,13 @@ public static MIDITune summary1(final List dirnames) throws IOException pbBytes.add(bar); } + // Set up the data visualisation. + final List dataLabels = List.of("bytes/h", "hits/h"); + final List> dataRendered = Collections.emptyList(); + final DataVizBeatPoint dv = new DataVizBeatPoint(0, 2, dataLabels, dataRendered); + final List dataMelody = Collections.emptyList(); final TuneSectionPlan tsp = null; - return(new MIDITune(dataMelody, supportTracks, tsp)); + return(new MIDITune(dataMelody, supportTracks, tsp, dv)); } } diff --git a/test/Main-feedHits-save-summary-1.launch b/test/Main-feedHits-save-summary-1.launch index 7fcf055..4dd9bc9 100644 --- a/test/Main-feedHits-save-summary-1.launch +++ b/test/Main-feedHits-save-summary-1.launch @@ -17,6 +17,6 @@ - +