From e481e601e9188c381adda7699a077cdee6dd65ab Mon Sep 17 00:00:00 2001 From: Luke Sikina Date: Tue, 1 Oct 2024 15:46:40 -0400 Subject: [PATCH] [CHORE] Different behavior on prod and locally. Wild guess --- .../dictionary/concept/ConceptResultSetUtil.java | 13 ++++++------- .../dictionary/concept/ConceptRepositoryTest.java | 10 ++++++++++ src/test/resources/seed.sql | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtil.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtil.java index e3fa4eb..1568f5c 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtil.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtil.java @@ -64,13 +64,12 @@ private Float parseFromIndex(String valuesArr, int index) { if (arr.length() != 2) { return 0F; } - String raw = arr.getString(index); - if (raw.contains("e")) { - // scientific notation - return Double.valueOf(raw).floatValue(); - } else { - return Float.parseFloat(raw); - } + Object raw = arr.get(index); + return switch (raw) { + case Double d -> d.floatValue(); + case Integer i -> i.floatValue(); + default -> 0f; + }; } catch (JSONException ex) { log.warn("Invalid json array for values: ", ex); return 0F; diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptRepositoryTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptRepositoryTest.java index 14f4451..73b7a46 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptRepositoryTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptRepositoryTest.java @@ -262,4 +262,14 @@ void shouldGetContConceptWithSciNotation() { Assertions.assertEquals((float) min, concept.min()); Assertions.assertEquals((float) max, concept.max()); } + + @Test + void shouldGetContConceptWithDecimalNotation() { + Optional actual = subject.getConcept("phs000007", "\\phs000007\\pht000033\\phv00008849\\D080\\"); + + Assertions.assertTrue(actual.isPresent()); + ContinuousConcept concept = (ContinuousConcept) actual.get(); + Assertions.assertEquals(0.57f, concept.min()); + Assertions.assertEquals(6.77f, concept.max()); + } } \ No newline at end of file diff --git a/src/test/resources/seed.sql b/src/test/resources/seed.sql index 581074b..e4042a9 100644 --- a/src/test/resources/seed.sql +++ b/src/test/resources/seed.sql @@ -506,7 +506,7 @@ COPY public.concept_node_meta (concept_node_meta_id, concept_node_id, key, value 124 268 description Whole exome sequencing 40 229 values [0, 3] 46 232 values [0, 1] -52 235 values [0, 5] +52 235 values [0.57,6.77] 60 241 values ["5e-21", "7e+33"] 125 268 values TRUE 126 269 description Whole genome sequencing