-
Notifications
You must be signed in to change notification settings - Fork 13
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
Do not create new quantity objects if utilities-simulation-results if… #463
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,18 +66,19 @@ importPKAnalysesFromCSV <- function(filePath, simulation) { | |
pkAnalysesAsDataFrame <- function(pkAnalyses) { | ||
validateIsOfType(pkAnalyses, SimulationPKAnalyses) | ||
pkParameterResultsFilePath <- tempfile() | ||
dataFrame <- tryCatch({ | ||
exportPKAnalysesToCSV(pkAnalyses, pkParameterResultsFilePath) | ||
pkResultsDataFrame <- read.csv(pkParameterResultsFilePath, encoding = "UTF-8", check.names = FALSE) | ||
colnames(pkResultsDataFrame) <- c("IndividualId", "QuantityPath", "Parameter", "Value", "Unit") | ||
pkResultsDataFrame$QuantityPath <- as.factor(pkResultsDataFrame$QuantityPath) | ||
pkResultsDataFrame$Parameter <- as.factor(pkResultsDataFrame$Parameter) | ||
pkResultsDataFrame$Unit <- as.factor(pkResultsDataFrame$Unit) | ||
return(pkResultsDataFrame) | ||
}, | ||
finally = { | ||
file.remove(pkParameterResultsFilePath) | ||
} | ||
dataFrame <- tryCatch( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only styler changes. |
||
{ | ||
exportPKAnalysesToCSV(pkAnalyses, pkParameterResultsFilePath) | ||
pkResultsDataFrame <- read.csv(pkParameterResultsFilePath, encoding = "UTF-8", check.names = FALSE) | ||
colnames(pkResultsDataFrame) <- c("IndividualId", "QuantityPath", "Parameter", "Value", "Unit") | ||
pkResultsDataFrame$QuantityPath <- as.factor(pkResultsDataFrame$QuantityPath) | ||
pkResultsDataFrame$Parameter <- as.factor(pkResultsDataFrame$Parameter) | ||
pkResultsDataFrame$Unit <- as.factor(pkResultsDataFrame$Unit) | ||
return(pkResultsDataFrame) | ||
}, | ||
finally = { | ||
file.remove(pkParameterResultsFilePath) | ||
} | ||
) | ||
return(dataFrame) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,16 +34,21 @@ getOutputValues <- function(simulationResults, | |
quantitiesOrPaths <- quantitiesOrPaths %||% simulationResults$allQuantityPaths | ||
quantitiesOrPaths <- c(quantitiesOrPaths) | ||
|
||
# If quantities are passed, get their paths. | ||
paths <- quantitiesOrPaths | ||
if (isOfType(paths, Quantity)) { | ||
paths <- unlist(lapply(paths, function(x) x$path)) | ||
if (length(quantitiesOrPaths) == 0) { | ||
msevestre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return(list(data = NULL, metaData = NULL)) | ||
} | ||
paths <- unique(paths) | ||
|
||
if (length(paths) == 0) { | ||
return(list(data = NULL, metaData = NULL)) | ||
# If quantities are passed, get their paths. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that we have a list of paths and a list of corresponding quantities. If quantities are provided, get their paths, and vice versa. |
||
if (isOfType(quantitiesOrPaths, Quantity)) { | ||
quantities <- uniqueEntities(quantitiesOrPaths) | ||
paths <- unlist(lapply(quantities, function(x) x$path)) | ||
} else { | ||
paths <- unique(quantitiesOrPaths) | ||
quantities <- lapply(paths, function(path) { | ||
getQuantity(path, simulationResults$simulation, stopIfNotFound) | ||
}) | ||
} | ||
names(quantities) <- paths | ||
|
||
# If no specific individual ids are passed, iterate through all individuals | ||
individualIds <- ifNotNull(individualIds, unique(individualIds), simulationResults$allIndividualIds) | ||
|
@@ -53,13 +58,8 @@ getOutputValues <- function(simulationResults, | |
valueLength <- length(timeValues) | ||
covariateNames <- ifNotNull(population, population$allCovariateNames, NULL) | ||
|
||
values <- list() | ||
metaData <- list( | ||
Time = list(unit = "min", dimension = "Time") | ||
) | ||
|
||
individualPropertiesCache <- vector("list", length(individualIds)) | ||
# create a cache of all indivdual values that are constant independent from the path | ||
# create a cache of all individual values that are constant independent from the path | ||
for (individualIndex in seq_along(individualIds)) { | ||
individualId <- individualIds[individualIndex] | ||
individualProperties <- list(IndividualId = rep(individualId, valueLength)) | ||
|
@@ -78,11 +78,17 @@ getOutputValues <- function(simulationResults, | |
allIndividualProperties <- do.call(rbind.data.frame, c(individualPropertiesCache, stringsAsFactors = FALSE)) | ||
|
||
|
||
for (path in paths) { | ||
quantity <- getQuantity(path, simulationResults$simulation, stopIfNotFound = stopIfNotFound) | ||
metaData[[path]] <- list(unit = quantity$unit, dimension = quantity$dimension) | ||
values[[path]] <- simulationResults$getValuesByPath(path, individualIds, stopIfNotFound) | ||
} | ||
values <- lapply(paths, function(path){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use lapply instead of iterating. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it it? you are lapply twice now instead of one loop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK changed to iteration. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PavelBal I like the usage of lapply better (easier to read) But I am not sure that this it is all around better because of double iteration. |
||
simulationResults$getValuesByPath(path, individualIds, stopIfNotFound) | ||
}) | ||
names(values) <- paths | ||
|
||
metaData <- lapply(paths, function(path){ | ||
quantity <- quantities[[path]] | ||
list(unit = quantity$unit, dimension = quantity$dimension) | ||
}) | ||
names(metaData) <- paths | ||
metaData[["Time"]] <- list(unit = "min", dimension = "Time") | ||
|
||
data <- data.frame(allIndividualProperties, values, stringsAsFactors = FALSE, check.names = FALSE) | ||
return(list(data = data, metaData = metaData)) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msevestre look at this, I added a wrapper for cached fields.