Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made sequence mappings sorted #65

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions src/main/java/com/github/thed2lab/analysis/Sequences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -57,21 +59,32 @@ static Pair<String, String> getExpandedSequenceDetails(DataEntry fixations) {
final int ASCII_OFFSET = 65; // Capital "A"
String aoiDescriptions = "";
String sequence = "";
HashMap<String, Integer> aoiLetters = new HashMap<>();
HashMap<String, Character> aoiMappings = new HashMap<>();
SortedSet<String> aoiSet = new TreeSet<String>();

// 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;
}

Expand Down
Loading