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

[CHORE] Different behavior on prod and locally. Wild guess #46

Merged
merged 1 commit into from
Oct 1, 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
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