From 6df032bee9ec5739f19e9ff5d88f6dc549f151ae Mon Sep 17 00:00:00 2001 From: Luke Sikina Date: Wed, 27 Mar 2024 11:05:30 -0400 Subject: [PATCH] [ALS-6173] small hpds optimization --- .../dbmi/avillach/hpds/data/phenotype/PhenoCube.java | 7 ++++--- .../avillach/hpds/processing/TimelineProcessor.java | 10 +++------- .../processing/timeseries/TimeseriesProcessor.java | 9 ++++++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/phenotype/PhenoCube.java b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/phenotype/PhenoCube.java index 97bdcab5..bb8c64ea 100644 --- a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/phenotype/PhenoCube.java +++ b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/phenotype/PhenoCube.java @@ -217,14 +217,15 @@ public void setLoadingMap(List> newMap) { this.loadingMap= newMap ; } - public List> getValuesForKeys(Set patientIds) { + public List> getValuesForKeys(List sortedPatientIds) { List> values = new ArrayList<>(); int x = 0; - for(Integer id : patientIds) { + for(Integer id : sortedPatientIds) { while(x < sortedByKey.length && sortedByKey[x].key= sortedByKey.length) { return values; } + while(sortedByKey[x].key==id) { values.add(sortedByKey[x]); x++; } diff --git a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/TimelineProcessor.java b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/TimelineProcessor.java index 8a3f4809..8ad9dc7f 100644 --- a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/TimelineProcessor.java +++ b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/TimelineProcessor.java @@ -2,13 +2,8 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; +import java.util.*; import java.util.Map.Entry; -import java.util.Set; import java.util.stream.Collectors; import edu.harvard.hms.dbmi.avillach.hpds.data.phenotype.KeyAndValue; @@ -46,7 +41,8 @@ public void runQuery(Query query, AsyncResult asyncResult) throws NotEnoughMemor query.setRequiredFields(new ArrayList<>()); // list patients involved - Set patientIds = abstractProcessor.getPatientSubsetForQuery(query); + List patientIds = new ArrayList<>(abstractProcessor.getPatientSubsetForQuery(query)); + patientIds.sort(Integer::compareTo); // get start time for the timeline long startTime = Long.MAX_VALUE; diff --git a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/timeseries/TimeseriesProcessor.java b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/timeseries/TimeseriesProcessor.java index c0a6b9b0..ca272087 100644 --- a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/timeseries/TimeseriesProcessor.java +++ b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/timeseries/TimeseriesProcessor.java @@ -98,11 +98,14 @@ private void exportTimeData(Query query, AsyncResult result, TreeSet id pathList.addAll(query.getRequiredFields()); pathList.addAll(query.getCategoryFilters().keySet()); pathList.addAll(query.getNumericFilters().keySet()); - - addDataForConcepts(pathList, exportedConceptPaths, idList, result); + + ArrayList ids = new ArrayList<>(idList); + ids.sort(Integer::compareTo); + + addDataForConcepts(pathList, exportedConceptPaths, ids, result); } - private void addDataForConcepts(Collection pathList, Set exportedConceptPaths, TreeSet idList, AsyncResult result) throws IOException { + private void addDataForConcepts(Collection pathList, Set exportedConceptPaths, List idList, AsyncResult result) throws IOException { for (String conceptPath : pathList) { //skip concepts we may already have encountered if(exportedConceptPaths.contains(conceptPath)) {