Skip to content

Commit d6d95dc

Browse files
Luke SikinaLuke-Sikina
Luke Sikina
authored andcommitted
[CHORE] Different behavior on prod and locally. Wild guess
1 parent 61f08b4 commit d6d95dc

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtil.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.slf4j.LoggerFactory;
99
import org.springframework.stereotype.Component;
1010

11+
import java.math.BigDecimal;
12+
import java.math.BigInteger;
1113
import java.sql.ResultSet;
1214
import java.sql.SQLException;
1315
import java.util.ArrayList;
@@ -64,13 +66,15 @@ private Float parseFromIndex(String valuesArr, int index) {
6466
if (arr.length() != 2) {
6567
return 0F;
6668
}
67-
String raw = arr.getString(index);
68-
if (raw.contains("e")) {
69-
// scientific notation
70-
return Double.valueOf(raw).floatValue();
71-
} else {
72-
return Float.parseFloat(raw);
73-
}
69+
Object raw = arr.get(index);
70+
return switch (raw) {
71+
case Double d -> d.floatValue();
72+
case Integer i -> i.floatValue();
73+
case String s -> Double.valueOf(s).floatValue();
74+
case BigDecimal d -> d.floatValue();
75+
case BigInteger i -> i.floatValue();
76+
default -> 0f;
77+
};
7478
} catch (JSONException ex) {
7579
log.warn("Invalid json array for values: ", ex);
7680
return 0F;

src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptRepositoryTest.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void shouldGetMetaForMultipleConcepts() {
171171
"unique_identifier", "false",
172172
"stigmatized", "false",
173173
"bdc_open_access", "true",
174-
"values", "[0, 5]",
174+
"values", "[0.57,6.77]",
175175
"description", "# 12 OZ CUPS OF CAFFEINATED COLA/DAY",
176176
"free_text", "false"
177177
),
@@ -262,4 +262,14 @@ void shouldGetContConceptWithSciNotation() {
262262
Assertions.assertEquals((float) min, concept.min());
263263
Assertions.assertEquals((float) max, concept.max());
264264
}
265+
266+
@Test
267+
void shouldGetContConceptWithDecimalNotation() {
268+
Optional<Concept> actual = subject.getConcept("phs000007", "\\phs000007\\pht000033\\phv00008849\\D080\\");
269+
270+
Assertions.assertTrue(actual.isPresent());
271+
ContinuousConcept concept = (ContinuousConcept) actual.get();
272+
Assertions.assertEquals(0.57f, concept.min());
273+
Assertions.assertEquals(6.77f, concept.max());
274+
}
265275
}

src/test/resources/seed.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ COPY public.concept_node_meta (concept_node_meta_id, concept_node_id, key, value
506506
124 268 description Whole exome sequencing
507507
40 229 values [0, 3]
508508
46 232 values [0, 1]
509-
52 235 values [0, 5]
510-
60 241 values ["5e-21", "7e+33"]
509+
52 235 values [0.57,6.77]
510+
60 241 values ["5E-21", "7E+33"]
511511
125 268 values TRUE
512512
126 269 description Whole genome sequencing
513513
127 269 values TRUE

0 commit comments

Comments
 (0)