Skip to content

Commit

Permalink
[CHORE] Different behavior on prod and locally. Wild guess
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina authored and Luke-Sikina committed Oct 1, 2024
1 parent 61f08b4 commit d6d95dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -64,13 +66,15 @@ 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();
case String s -> Double.valueOf(s).floatValue();
case BigDecimal d -> d.floatValue();
case BigInteger i -> i.floatValue();
default -> 0f;
};
} catch (JSONException ex) {
log.warn("Invalid json array for values: ", ex);
return 0F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void shouldGetMetaForMultipleConcepts() {
"unique_identifier", "false",
"stigmatized", "false",
"bdc_open_access", "true",
"values", "[0, 5]",
"values", "[0.57,6.77]",
"description", "# 12 OZ CUPS OF CAFFEINATED COLA/DAY",
"free_text", "false"
),
Expand Down Expand Up @@ -262,4 +262,14 @@ void shouldGetContConceptWithSciNotation() {
Assertions.assertEquals((float) min, concept.min());
Assertions.assertEquals((float) max, concept.max());
}

@Test
void shouldGetContConceptWithDecimalNotation() {
Optional<Concept> 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());
}
}
4 changes: 2 additions & 2 deletions src/test/resources/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ 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]
60 241 values ["5e-21", "7e+33"]
52 235 values [0.57,6.77]
60 241 values ["5E-21", "7E+33"]
125 268 values TRUE
126 269 description Whole genome sequencing
127 269 values TRUE
Expand Down

0 comments on commit d6d95dc

Please sign in to comment.