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

WIP #486 expose data repository #487

Merged
merged 11 commits into from
Mar 24, 2021
Merged

Conversation

msevestre
Copy link
Member

@msevestre msevestre commented Mar 18, 2021

This is just a WIP. I would like to understand what we need exactly
So far

library(ospsuite)

obsData <- loadObservedData("tests/data/obs_data.pkml")

> obsData$baseGrid
  Time: [min]

> obsData$columns
[[1]]
  Time: [min]

[[2]]
  Measurement: [kg/l]

[[3]]
  Error: [kg/l]

> obsData$columns[[2]]$values
[1] 1.01e-09 8.30e-10 7.30e-10 2.80e-10 1.20e-10 3.05e-11 5.93e-12

> col<-obsData$columns[[2]]
> col$dimension
[1] "Concentration (mass)"
> col$displayUnit
[1] "mg/l"
> col$unit
[1] "kg/l"
> col$name
[1] "Measurement"
> col$values
[1] 1.01e-09 8.30e-10 7.30e-10 2.80e-10 1.20e-10 3.05e-11 5.93e-12

@msevestre msevestre requested review from PavelBal and Yuri05 March 18, 2021 23:49
Copy link
Member Author

@msevestre msevestre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP

DataColumn$new(private$wrapReadOnlyProperty("BaseGrid", value))
},
#' @field columns Returns all columns (including baseGrid defined in the data)
columns = function(value){
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PavelBal @Yuri05 I will cache this so that we always return the same instances of DataColumn wrapper

cloneable = FALSE,
active = list(
#' @field baseGrid Returns the base column for the population (typically time column)
baseGrid = function(value) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in core, we have basegrid, columns, and allButBaseGrid.
I will implement the same methods (baseGrid is typically time, columns are all columns in the dataRepo, allButBaseGrids are all except basegrid)

Should we have a property called Time that returned baseGrid? or property called Measurement that returns col2 and a property called error that returns col3? not sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a property called Time that returned baseGrid? or property called Measurement that returns col2 and a property called error that returns col3?

I would say no and no. Basegrid might be different from "Time", we could have several measurements and several errors, so I wouldn't provide shortcuts for the specific use case "ObservedDataRepo = {Time, Measurement, Error}"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could have several measurements and several errors,

Reallly, do we have it somewhere (and how)? @Yuri05

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory results from a simulation etc.. are DataRepositories
So yes we can have one time and multiple measurements. Each measurements can in theory have multiple errors. I think we are using this for the PI results.
Practically probably not

Copy link
Member

@PavelBal PavelBal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msevestre I propose some changes to the naming.

R/data-repository.R Show resolved Hide resolved
cloneable = FALSE,
active = list(
#' @field baseGrid Returns the base column for the population (typically time column)
baseGrid = function(value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could have several measurements and several errors,

Reallly, do we have it somewhere (and how)? @Yuri05

R/data-repository.R Outdated Show resolved Hide resolved
R/utilities-observed-data.R Outdated Show resolved Hide resolved
R/utilities-observed-data.R Outdated Show resolved Hide resolved
},
#' @field metaData Returns a named list of meta data defined for the data repository.
#' where the name is the name of the metaData and the value is the meta data value.
metaData = function(value){
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PavelBal @Yuri05
Meta data is a named list of {name, value}

> metaData
$Source
[1] "C:\\temp\\RanorexTestData\\ObservedData.xlsx"

$Sheet
[1] "Tabelle1"

$DoubleValue
[1] 5

$StringValues
[1] "hello"

$IntegerValue
[1] 4

if (is.null(private$.metaData)) {
netExtendedProperties <- private$wrapReadOnlyProperty("ExtendedProperties", value)
netMetaData <- rClr::clrGet(netExtendedProperties, "All")
names <- unlist(lapply(netMetaData, function(data) rClr::clrGet(data, "Name")))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PavelBal Any way to do this 3 lines in one? Seems to be a bit stupid. At any rate, the array will be very small anyways so I don't mind iterating twice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't think of anything.

@@ -18,6 +18,4 @@ initPackage <- function() {
apiConfig$pkParametersFilePath <- filePathFor("OSPSuite.PKParameters.xml")

rClr::clrCallStatic("OSPSuite.R.Api", "InitializeOnce", apiConfig$ref)
dimensionTask <- getNetTask("DimensionTask")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yuri05 THis was creating some issues. And then I wondered. Do we actually need to load if from .NET
isn't it enough to have it a constant as it is now?

@@ -48,6 +48,10 @@ ifNotNull <- function(condition, outputIfNotNull, outputIfNull = NULL) {
#' See https://github.com/Open-Systems-Pharmacology/OSPSuite-R/issues/476 for details
#' @import stringr
encodeUnit <- function(unit) {

#TODO maybe we don't even need to load from .NET
# dimensionTask <- getNetTask("DimensionTask")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yuri05 If we want to load from .NET we would need to do it here the first time is is being used. But why do we need this in the first place since ospsuiteEnv$muSymbol is already set
see ospsuite-env.R

Specifies the symbol used for µ. This will be set by the .NET layer

ospsuiteEnv$muSymbol <- "µ"

if (is.null(private$.metaData)) {
netExtendedProperties <- private$wrapReadOnlyProperty("ExtendedProperties", value)
netMetaData <- rClr::clrGet(netExtendedProperties, "All")
names <- unlist(lapply(netMetaData, function(data) rClr::clrGet(data, "Name")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unlist(x, use.names = FALSE) is much faster than unlist(x).

No idea what the actual benefit would be here, but why not add it..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -18,6 +18,4 @@ initPackage <- function() {
apiConfig$pkParametersFilePath <- filePathFor("OSPSuite.PKParameters.xml")

rClr::clrCallStatic("OSPSuite.R.Api", "InitializeOnce", apiConfig$ref)
dimensionTask <- getNetTask("DimensionTask")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove "DimensionTask"? I was counting on it for the utilities-dimensions.

Btw. I only was creating it the first time it was requested:

In ospsuite-env (esqlabsEnv in my code):

# NetTask "DimensionTask" cached for performance benefits. Created the first time it is requested.
esqlabsEnv$DimensionTask <- NULL

Then a function somewhere:

#' Return an instance of the .NET Task "DimensionTask".
#'
#' @return An instance of the Task
getDimensionTask <- function() {
  dimTask <- esqlabsEnv$DimensionTask
  if (is.null(dimTask)) {
    dimTask <- getNetTask("DimensionTask")
    esqlabsEnv$DimensionTask <- dimTask
  }
  return(dimTask)
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remove it. Instatntiating object in the init creates weird error messages during build.

Can you quantify cached for performance benefits..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are looking at sthg else. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I am going to add it to core because it's probably a good optimization since this is used quite often

@@ -48,6 +48,10 @@ ifNotNull <- function(condition, outputIfNotNull, outputIfNull = NULL) {
#' See https://github.com/Open-Systems-Pharmacology/OSPSuite-R/issues/476 for details
#' @import stringr
encodeUnit <- function(unit) {

#TODO maybe we don't even need to load from .NET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you have it here... See my suggestion above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean

@msevestre msevestre merged commit 04c0fce into develop Mar 24, 2021
@msevestre msevestre deleted the 486-expose-data-repository branch March 24, 2021 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants