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

Changed filtering order back and updated some tests #59

Merged
merged 4 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions src/main/java/com/github/thed2lab/analysis/Analysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public boolean run() {
System.out.println("Analyzing " + pName);

// Build DataEntrys
DataEntry allGaze = DataFilter.applyScreenSize(FileHandler.buildDataEntry(f), SCREEN_WIDTH, SCREEN_HEIGHT);
DataEntry validGaze = DataFilter.filterByValidity(allGaze, SCREEN_WIDTH, SCREEN_HEIGHT);
DataEntry allGaze = FileHandler.buildDataEntry(f);
DataEntry validGaze = DataFilter.filterByValidity(allGaze);
DataEntry fixations = DataFilter.filterByFixations(allGaze);
DataEntry validFixations = DataFilter.filterByValidity(fixations, SCREEN_HEIGHT, SCREEN_WIDTH);
DataEntry validFixations = DataFilter.filterByValidity(fixations);

// Write DataEntrys to file
validGaze.writeToCSV(pDirectory, pName + "_valid_all_gaze");
Expand Down Expand Up @@ -167,18 +167,18 @@ static List<List<String>> generateResults(DataEntry allGaze, DataEntry aoiGaze,

/**
* Helper methods that generates the descriptive gaze measures.
* @param allGaze all gaze data for the whole screen, with screen size applied.
* @param areaGaze the gaze data that ocurred within a target portion of screen, i.e., either the whole screen or an AOI, with screen
* size applied.
* @param allGaze all gaze data for the whole screen.
* @param areaGaze the gaze data that ocurred within a target portion of screen, i.e., either the whole screen or an AOI.
* @param areaFixations the gaze data that ocurred within a target portion of screen, i.e., either the whole screen or an AOI,
* and filtered by fixation with screen size applied.
* @return a {@code List<List<String>} where the first inner-list is the measure names, and second inner-list is the calculated values.
*/
private static List<List<String>> generateResultsHelper(DataEntry allGaze, DataEntry areaGaze, DataEntry areaFixations) {
// an argument could be made to filter before entering this function; there is a code smell due to blink rate and saccadeV changing
DataEntry validAllGaze = DataFilter.filterByValidity(allGaze, SCREEN_WIDTH, SCREEN_HEIGHT);
DataEntry validAreaGaze = DataFilter.filterByValidity(areaGaze, SCREEN_WIDTH, SCREEN_HEIGHT);
DataEntry validAreaFixations = DataFilter.filterByValidity(areaFixations, SCREEN_WIDTH, SCREEN_HEIGHT);

DataEntry validAllGaze = DataFilter.applyScreenSize(DataFilter.filterByValidity(allGaze), SCREEN_WIDTH, SCREEN_HEIGHT);
DataEntry validAreaGaze = DataFilter.applyScreenSize(DataFilter.filterByValidity(areaGaze), SCREEN_WIDTH, SCREEN_HEIGHT);
DataEntry validAreaFixations = DataFilter.applyScreenSize(DataFilter.filterByValidity(areaFixations), SCREEN_WIDTH, SCREEN_HEIGHT);

LinkedHashMap<String,String> resultsMap = new LinkedHashMap<String, String>();
resultsMap.putAll(Fixations.analyze(validAreaFixations));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void generateAOIs(DataEntry allGazeData, DataEntry fixationData, S
return;
}

DataEntry filteredFixations = DataFilter.filterByValidity(fixationData, SCREEN_WIDTH, SCREEN_HEIGHT);
DataEntry filteredFixations = DataFilter.filterByValidity(fixationData);
Map<String, DataEntry> aoiFixMap = splitAoiData(filteredFixations);

// For any AOIs not in aoiFixationMetrics, add an empty DataEntry
Expand All @@ -39,7 +39,7 @@ public static void generateAOIs(DataEntry allGazeData, DataEntry fixationData, S

for (String aoiKey : aoiGazeMap.keySet()) {
DataEntry aoiData = aoiGazeMap.get(aoiKey);
aoiData.writeToCSV(outputDirectory + "/AOIs", aoiKey + "_all_gaze");
aoiData.writeToCSV(outputDirectory + "/AOIs", aoiKey.replace(" ", "_") + "_all_gaze");
}

List<List<String>> aoiMetrics = getMetrics(allGazeData, filteredFixations, aoiGazeMap, aoiFixMap);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/thed2lab/analysis/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ static double getRawEventBaselineValue(DataEntry baselineData, String event) {
double eventValue = 0;

baselineData = fixationEvents.contains(event) ? DataFilter.filterByFixations(baselineData) : baselineData; // Determine if we need to filter by fixations
baselineData = DataFilter.filterByValidity(baselineData, SCREEN_WIDTH, SCREEN_HEIGHT); // Filter by validity
baselineData = DataFilter.filterByValidity(baselineData); // Filter by validity

for (int i = 0; i < baselineData.rowCount(); i++) {
eventValue += Double.parseDouble(baselineData.getValue(event, i));
Expand All @@ -317,7 +317,7 @@ static double getRawEventBaselineValue(DataEntry baselineData, String event) {

static double getAveragePupilDilationBaseline(DataEntry baselineData) {
double eventValue = 0;
baselineData = DataFilter.filterByValidity(baselineData, SCREEN_WIDTH, SCREEN_HEIGHT); // Filter by validity
baselineData = DataFilter.filterByValidity(baselineData); // Filter by validity

for (int i = 0; i < baselineData.rowCount(); i++) {
double left = Double.parseDouble(baselineData.getValue(LEFT_PUPIL_DIAMETER, i));
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/com/github/thed2lab/analysis/FixationsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ public void testFixationsAnalyze_missingFixationDurationHeader_throwsNullPointer

@Test
public void testFixationsAnalyze_realData_returnHeadersAndValues() {
final String FIXATION_PATH = "./src/test/resources/filtered_by_fixation.csv";
Map<String, String> expectedResults = new HashMap<String, String>();
expectedResults.put("total_number_of_fixations", "24");
expectedResults.put("sum_of_all_fixation_duration_s", "5.63392");
expectedResults.put("mean_fixation_duration_s", "0.234746667");
expectedResults.put("median_fixation_duration_s", "0.16748");
expectedResults.put("stdev_of_fixation_durations_s", "0.154818618");
expectedResults.put("min_fixation_duration_s", "0.03382");
expectedResults.put("max_fixation_duration_s", "0.66125");
final String FIXATION_PATH = "./src/test/resources/valid_fixations.csv";
Map<String, Double> expectedResults = new HashMap<String, Double>();
expectedResults.put("total_number_of_fixations", 20.);
expectedResults.put("sum_of_all_fixation_duration_s", 4.76282);
expectedResults.put("mean_fixation_duration_s", 0.238141);
expectedResults.put("median_fixation_duration_s", 0.16748);
expectedResults.put("stdev_of_fixation_durations_s", 0.152435548482);
expectedResults.put("min_fixation_duration_s", 0.08044);
expectedResults.put("max_fixation_duration_s", 0.66125);
DataEntry actual_data = FileHandler.buildDataEntry(new File(FIXATION_PATH));
Map<String, String> actualResults = Collections.unmodifiableMap(Fixations.analyze(actual_data));

assertEquals("Different number of fixation results", expectedResults.size(), actualResults.size());

for(String key: expectedResults.keySet()) {
if(Math.abs(Double.valueOf(expectedResults.get(key)) - Double.valueOf(actualResults.get(key))) > PRECISION) {
if(Math.abs(expectedResults.get(key) - Double.valueOf(actualResults.get(key))) > PRECISION) {
fail(String.format(
"Different values for %s\n\tExpected: %s\n\tActual: %s",
"Different values for %s\n\tExpected: %f\n\tActual: %s",
key,
expectedResults.get(key),
actualResults.get(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ public void testGetPeakVelocity_normalUseCase_returnVelocityValue() {

@Test
public void testSaccadeVelocityAnalyze_nonContinuousWholeScreen() {
final String GAZE_PATH = "./src/test/resources/filtered_by_validity.csv";
final String FIXATION_PATH = "./src/test/resources/valid_fixations.csv";
final String GAZE_PATH = "./src/test/resources/valid_gaze_screenApplied.csv";
final String FIXATION_PATH = "./src/test/resources/valid_fixation_screenApplied.csv";
final double EXPECTED_AVG_PEAK = 179.96919273273;
final String KEY = "average_peak_saccade_velocity";
DataEntry gazeData = DataFilter.applyScreenSize(FileHandler.buildDataEntry(new File(GAZE_PATH)), SCREEN_WIDTH, SCREEN_HEIGHT);
DataEntry fixationData = DataFilter.applyScreenSize(FileHandler.buildDataEntry(new File(FIXATION_PATH)), SCREEN_WIDTH, SCREEN_HEIGHT);

DataEntry gazeData = FileHandler.buildDataEntry(new File(GAZE_PATH));
DataEntry fixationData = FileHandler.buildDataEntry(new File(FIXATION_PATH));
double actualAvgPeak = Double.parseDouble(SaccadeVelocity.analyze(gazeData, fixationData).get(KEY));
assertEquals(EXPECTED_AVG_PEAK, actualAvgPeak, PRECISION);
}
Expand Down
46 changes: 23 additions & 23 deletions src/test/java/com/github/thed2lab/analysis/SaccadesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -203,35 +203,35 @@ public void testGetFixationToSaccadeRatio_normalUseCase_returnRatio() {

@Test
public void testSaccadeAnalyze_validFixations_returnHeadersAndValues() {
final String DATA_PATH = "./src/test/resources/valid_fixations.csv";
Map<String, String> expectedResults = new HashMap<String, String>();
expectedResults.put("total_number_of_saccades", "16");

expectedResults.put("sum_of_all_saccade_lengths", "1.4804786014");
expectedResults.put("mean_saccade_length", "0.0925299126");
expectedResults.put("median_saccade_length", "0.0761603796");
expectedResults.put("stdev_of_saccade_lengths", "0.0572082421");
expectedResults.put("min_saccade_length", "0.0167247123");
expectedResults.put("max_saccade_length", "0.2016258416");

expectedResults.put("sum_of_all_saccade_durations", "0.19091");
expectedResults.put("mean_saccade_duration", "0.0119318750");
expectedResults.put("median_saccade_duration", "0.0067100000");
expectedResults.put("stdev_of_saccade_durations", "0.0094964149");
expectedResults.put("min_saccade_duration", "0.0059800000");
expectedResults.put("max_saccade_duration", "0.0302800000");

expectedResults.put("scanpath_duration", "4.95373");
expectedResults. put("fixation_to_saccade_ratio", "24.9479859620");
final String DATA_PATH = "./src/test/resources/valid_fixation_screenApplied.csv";
Map<String, Double> expectedResults = new LinkedHashMap<String, Double>();
expectedResults.put("total_number_of_saccades", 16.);

expectedResults.put("sum_of_all_saccade_lengths", 2530.8660814283);
expectedResults.put("mean_saccade_length", 158.1791300893);
expectedResults.put("median_saccade_length", 119.3467488446);
expectedResults.put("stdev_of_saccade_lengths", 106.3517507880);
expectedResults.put("min_saccade_length", 20.7083517065);
expectedResults.put("max_saccade_length", 349.4148372122);

expectedResults.put("sum_of_all_saccade_durations", 0.19091);
expectedResults.put("mean_saccade_duration", 0.011931875);
expectedResults.put("median_saccade_duration", 0.00671);
expectedResults.put("stdev_of_saccade_durations", 0.0094964149);
expectedResults.put("min_saccade_duration", 0.00598);
expectedResults.put("max_saccade_duration", 0.03028);

expectedResults.put("scanpath_duration", 4.95373);
expectedResults. put("fixation_to_saccade_ratio", 24.9479859620);

DataEntry dEntry = FileHandler.buildDataEntry(new File(DATA_PATH));
Map<String, String> actualResults = Saccades.analyze(dEntry);

assertEquals("Unexpected output size.", expectedResults.size(), actualResults.size());

for (String key : expectedResults.keySet()) {
if (Math.abs(Double.valueOf(expectedResults.get(key)) - Double.valueOf(actualResults.get(key))) > PRECISION) {
fail(String.format("Different values for %s\n\tExpected: %s\n\tActual: %s",
if (Math.abs(expectedResults.get(key) - Double.valueOf(actualResults.get(key))) > PRECISION) {
fail(String.format("Different values for %s\n\tExpected: %f\n\tActual: %s",
key,
expectedResults.get(key),
actualResults.get(key)
Expand Down
Loading
Loading