From 226658e3a9a9187c0a173c9b54c3e79b4add3be3 Mon Sep 17 00:00:00 2001 From: DamonHD Date: Mon, 24 Jun 2024 20:46:27 +0100 Subject: [PATCH] summary2() still WIP. But reasonable refactoring done, ready to do the actual work! --- .../statsHouse/feedHits/GenerateSummary.java | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/javasrc/org/hd/d/statsHouse/feedHits/GenerateSummary.java b/javasrc/org/hd/d/statsHouse/feedHits/GenerateSummary.java index bc1218f..5772d27 100644 --- a/javasrc/org/hd/d/statsHouse/feedHits/GenerateSummary.java +++ b/javasrc/org/hd/d/statsHouse/feedHits/GenerateSummary.java @@ -60,29 +60,48 @@ public static MIDITune summary(final int summaryType, final List dirname }; } + /**Generate the beat labels for summary type 1 (and 2); never null. + * @param fsbs in-order blocks of feed status data; never null + * @return immutable set of labels 00, 01, ... 23, 00, ... 23 to match the status blocks; never null + */ + private static List generateBeatLabelsType1(final FeedStatusBlocks fsbs) + { + // Total number of distinct hours to sonify; 24 summary hours for each block. + final int nTotalHours = fsbs.blocks().size() * 24; + + final List beatLabels = new ArrayList<>(nTotalHours); + + // Create bars from the normalised data. + // Further normalise strength to maximum encountered. + for(int h = 0; h < nTotalHours; ++h) + { + // Add hour-of-day label. + String hh = Integer.toString(h % 24); + if(hh.length() < 2) { hh = "0" + hh; } + beatLabels.add(hh); + } + + return(Collections.unmodifiableList(beatLabels)); + } + /**Generate the percussion track for summary type 1 (and 2); never null. - * Also generates the beat labels, which must be empty. * * @param fsbs in-order blocks of feed status data; never null * @param dataRendered rendered data to append to; never null - * @param beatLabels beat labels to append to; never null * @return */ private static MIDISupportTrack generatePercussionType1(final FeedStatusBlocks fsbs, - final List> dataRendered, - final List dataLabels, - final List beatLabels) + final List> dataRendered, + final List dataLabels) { Objects.requireNonNull(fsbs); Objects.requireNonNull(dataRendered); Objects.requireNonNull(dataLabels); - Objects.requireNonNull(beatLabels); // For now assume that the render info is EMPTY. // May have to append sideways to it in future. if(!dataRendered.isEmpty()) { throw new RuntimeException("unexpected state"); } if(!dataLabels.isEmpty()) { throw new RuntimeException("unexpected state"); } - if(!beatLabels.isEmpty()) { throw new RuntimeException("unexpected state"); } // Add in the columns that this routine will insert data for. dataLabels.addAll(List.of("bytes/h", "hits/h")); @@ -186,11 +205,6 @@ private static MIDISupportTrack generatePercussionType1(final FeedStatusBlocks f normalisedHitsPerHour[hour] ); dataRendered.add(d); - - // Add hour-of-day label. - String hh = Integer.toString(hour % 24); - if(hh.length() < 2) { hh = "0" + hh; } - beatLabels.add(hh); } final MIDIPlayableBar bar = new MIDIPlayableBar(Collections.unmodifiableSortedSet(notes)); @@ -211,20 +225,16 @@ public static MIDITune summary1(final List dirnames) throws IOException // Total number of distinct hours to sonify; 24 summary hours for each block. final int nTotalHours = fsbs.blocks().size() * 24; -// // Hours' data for each bar (must be a factor of 24). -// final int nHoursPerBar = 4; -// // Total number of data bars to generate. -// final int nDataBars = nTotalHours / nHoursPerBar; // Data for the data visualisation. final List> dataRendered = new ArrayList<>(nTotalHours); final List dataLabels = new ArrayList<>(); - final List beatLabels = new ArrayList<>(nTotalHours); final MIDISupportTrack percussion = - generatePercussionType1(fsbs, dataRendered, dataLabels, beatLabels); + generatePercussionType1(fsbs, dataRendered, dataLabels); // Set up the data visualisation. + final List beatLabels = generateBeatLabelsType1(fsbs); final DataVizBeatPoint dv = new DataVizBeatPoint(nTotalHours, dataLabels.size(), dataLabels, dataRendered, beatLabels); final List dataMelody = Collections.emptyList(); @@ -232,7 +242,6 @@ public static MIDITune summary1(final List dirnames) throws IOException return(new MIDITune(dataMelody, List.of(percussion), tsp, dv)); } - /**Summary type 2; by-hour data blocks percussion and some trend melody. * Uses the same (drums) percussion as summary type 1. *

@@ -267,12 +276,12 @@ public static MIDITune summary2(final List dirnames) throws IOException // Data for the data visualisation. final List> dataRendered = new ArrayList<>(nTotalHours); final List dataLabels = new ArrayList<>(); - final List beatLabels = new ArrayList<>(nTotalHours); final MIDISupportTrack percussion = - generatePercussionType1(fsbs, dataRendered, dataLabels, beatLabels); + generatePercussionType1(fsbs, dataRendered, dataLabels); // Set up the data visualisation. + final List beatLabels = generateBeatLabelsType1(fsbs); final DataVizBeatPoint dv = new DataVizBeatPoint(nTotalHours, dataLabels.size(), dataLabels, dataRendered, beatLabels); final List dataMelody = Collections.emptyList();