From ea9821d40d8f421b410f01675c68038a554541fe Mon Sep 17 00:00:00 2001 From: Angelo Ryan Soriano Date: Wed, 8 Jan 2025 16:53:51 -0800 Subject: [PATCH] Made sequence mappings sorted Allows for consistent mappings across different analysis objects. --- .../github/thed2lab/analysis/Sequences.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/github/thed2lab/analysis/Sequences.java b/src/main/java/com/github/thed2lab/analysis/Sequences.java index 85b3ec2..8f3abcc 100644 --- a/src/main/java/com/github/thed2lab/analysis/Sequences.java +++ b/src/main/java/com/github/thed2lab/analysis/Sequences.java @@ -6,6 +6,8 @@ import static com.github.thed2lab.analysis.Constants.AOI_LABEL; import java.util.HashMap; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -44,7 +46,7 @@ public static String generateSequenceFiles(DataEntry fixations, String outputDir FileHandler.writeToText(collapsedSequence, outputDirectory, "collapsedSequence"); FileHandler.writeToText(aoiDescriptions, outputDirectory, "aoiDescriptions"); - return sequence; + return sequence; } /** @@ -57,21 +59,32 @@ static Pair getExpandedSequenceDetails(DataEntry fixations) { final int ASCII_OFFSET = 65; // Capital "A" String aoiDescriptions = ""; String sequence = ""; - HashMap aoiLetters = new HashMap<>(); + HashMap aoiMappings = new HashMap<>(); + SortedSet aoiSet = new TreeSet(); - // Generate sequence + // Iterate through data rows to create sorted set of AOI names. for (int i = 0; i < fixations.rowCount(); i++) { String aoi = fixations.getValue(AOI_LABEL, i); + aoiSet.add(aoi); + } - if (!aoiLetters.containsKey(aoi)) { - aoiLetters.put(aoi, aoiLetters.size() + ASCII_OFFSET); + // Map AOIs to a character + int count = 0; + for (String aoi : aoiSet) { + String aoiName = aoi == "" ? "Undefined Area" : aoi; + int asciiValue = count + ASCII_OFFSET; + char c = (char)asciiValue; + + aoiMappings.put(aoiName, c); + aoiDescriptions += c + ", " + aoiName + "\n"; + count++; + } - String description = aoi == "" ? "Undefined Area" : aoi; - aoiDescriptions += (char)(aoiLetters.size() + ASCII_OFFSET - 1) + ", " + description + "\n"; - } - - int asciiValue = aoiLetters.get(aoi); - char c = (char)asciiValue; + // Generate sequence + for (int i = 0; i < fixations.rowCount(); i++) { + String aoi = fixations.getValue(AOI_LABEL, i); + String aoiName = aoi == "" ? "Undefined Area" : aoi; + char c = aoiMappings.get(aoiName); sequence += c; }