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

ACAS-760: Warn users if Number values which contain numerics will be saved as Text #1154

Merged
merged 2 commits into from
Apr 29, 2024
Merged
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
17 changes: 15 additions & 2 deletions modules/GenericDataParser/src/server/generic_data_parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -1705,12 +1705,25 @@ organizeCalculatedResults <- function(calculatedResults, inputFormat, formatPara
# Turn result values to numeric values
longResults$"numericValue" <- as.numeric(gsub(",","",gsub(matchExpression,"",longResults$"numericValue")))

# Get just the values that the user set to be Number data types to check for unparsable numbers
numericLongResults <- longResults[longResults$Class=="Number",]

# For any Number data types where the numericValue is NA and the stringValue is not NA, check if the stringValue contains numbers
# Warn the user that these values contain numerics but could not be parsed as Number and will be saved as Text
numbersToBeSavedAsString <- numericLongResults[which(is.na(numericLongResults$numericValue) & !is.na(numericLongResults$stringValue)),]
# Get the string values that contain numbers
stringValuesWithNumbers <- numbersToBeSavedAsString$"stringValue"[grepl("[0-9]",numbersToBeSavedAsString$"stringValue")]
# Warn the user if there are any
if(length(stringValuesWithNumbers) > 0) {
warnUser(paste0("The following Number values contain numerals but could not be parsed as Number so will be saved as Text: '", paste(unique(stringValuesWithNumbers), collapse = "', '"), "'. To avoid this warning either remove all numerals from the text, or use a correctly formatted Number. For example, 1, 1.2, 1.23e-10, >1, <1"))
}

# Check the Number values are finite
numericValues <- longResults$"numericValue"[which(longResults$Class=="Number")]
numericValues <- numericLongResults$"numericValue"
nonNaNumericValues <- na.omit(numericValues)
infiniteNumbersIndexes <- which(!is.finite(nonNaNumericValues))
if(length(infiniteNumbersIndexes) > 0) {
unParsedNonNaNumericValues <- longResults$UnparsedValue[which(longResults$Class=="Number")]
unParsedNonNaNumericValues <- numericLongResults$UnparsedValue[which(numericLongResults$Class=="Number")]
naNumericValueIndexes <- which(is.na(numericValues))
if(length(naNumericValueIndexes) > 0) {
unParsedNonNaNumericValues[-naNumericValueIndexes]
Expand Down
Loading