Skip to content

Commit

Permalink
DataVizBeatPoint.write();
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonHD committed Jun 4, 2024
1 parent 3b89a4d commit a7f62ae
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
21 changes: 19 additions & 2 deletions javasrc/org/hd/d/statsHouse/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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|<outfilename>.(csv|mid|wav)))");
System.err.println(" -feedHitsSummary -play|<outfilename>.mid <typeN> {feedHitsDataDir}*");
System.err.println(" -feedHitsSummary -play|<outbasename> <typeN> {feedHitsDataDir}*");
GenerationParameters.printOptions();
System.err.println();
System.err.println(" This syntax may be used, one per line, in the command file.");
Expand Down Expand Up @@ -192,7 +193,23 @@ public static void runCommands(final List<List<String>> 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;
}
Expand Down
8 changes: 7 additions & 1 deletion javasrc/org/hd/d/statsHouse/data/DataVizBeatPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ public record DataVizBeatPoint(
* The first line may optionally be labels if dataLabels is not null.
* <p>
* Values in a record may be separated by spaces or commas.
* <p>
* 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.
Expand All @@ -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.
Expand All @@ -96,5 +100,7 @@ public void write(final Writer w, final boolean commaSep) throws IOException
}
w.write('\n');
}

w.flush();
}
}
2 changes: 1 addition & 1 deletion javasrc/org/hd/d/statsHouse/data/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion javasrc/org/hd/d/statsHouse/feedHits/GenerateSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -163,8 +164,13 @@ public static MIDITune summary1(final List<String> dirnames) throws IOException
pbBytes.add(bar);
}

// Set up the data visualisation.
final List<String> dataLabels = List.of("bytes/h", "hits/h");
final List<List<Float>> dataRendered = Collections.emptyList();
final DataVizBeatPoint dv = new DataVizBeatPoint(0, 2, dataLabels, dataRendered);

final List<MIDIDataMelodyTrack> dataMelody = Collections.emptyList();
final TuneSectionPlan tsp = null;
return(new MIDITune(dataMelody, supportTracks, tsp));
return(new MIDITune(dataMelody, supportTracks, tsp, dv));
}
}
2 changes: 1 addition & 1 deletion test/Main-feedHits-save-summary-1.launch
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.hd.d.statsHouse.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="statsHouse"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-feedHitsSummary fh1.mid 1 ../RSS-data/20240519 ../RSS-data/20240527"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-feedHitsSummary fh1 1 ../RSS-data/20240519 ../RSS-data/20240527"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="statsHouse"/>
</launchConfiguration>

0 comments on commit a7f62ae

Please sign in to comment.