-
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
WIP #544 #546
WIP #544 #546
Changes from 2 commits
68c928a
f0e7fb1
11a0718
14a5ab7
22c4ca6
98239a2
b5b1deb
6df6c8c
eb80a1f
dab9f43
b6e7eb8
d7ad8b0
f717962
e2d2ded
5f5c62b
e5624f4
45587b6
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 |
---|---|---|
|
@@ -10,9 +10,9 @@ DataColumn <- R6::R6Class( | |
inherit = DotNetWrapper, | ||
cloneable = FALSE, | ||
active = list( | ||
#' @field values Returns the values defined in the column (Read-Only) | ||
#' @field values Returns the values defined in the column | ||
values = function(value) { | ||
private$wrapReadOnlyProperty("ValuesAsArray", value) | ||
private$wrapProperty("ValuesAsArray", value) | ||
}, | ||
#' @field name Returns the name of the column (Read-Only) | ||
name = function(value) { | ||
|
@@ -23,14 +23,31 @@ DataColumn <- R6::R6Class( | |
private$.unit <- private$wrapExtensionMethodCached(WITH_DIMENSION_EXTENSION, "BaseUnitName", "unit", private$.unit, value) | ||
return(private$.unit) | ||
}, | ||
#' @field displayUnit The unit in which the values should be displayed (Read-Only) | ||
#' @field displayUnit The unit in which the values should be displayed | ||
displayUnit = function(value) { | ||
private$wrapExtensionMethod(WITH_DISPLAY_UNIT_EXTENSION, "DisplayUnitName", "displayUnit", value) | ||
if (missing(value)) { | ||
return(private$wrapExtensionMethod(WITH_DISPLAY_UNIT_EXTENSION, "DisplayUnitName", "displayUnit", value)) | ||
} | ||
dimension <- getDimensionByName(self$dimension) | ||
# we use the ignore case parameter set to true so that we do not have to worry about casing when set via scripts | ||
unit <- rClr::clrCall(dimension, "FindUnit", value, TRUE) | ||
if(is.null(unit)){ | ||
stop(messages$errorUnitNotSupported(unit = value, dimension = self$dimension)) | ||
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. Right now, an error will be thrown. This is OK in the DataColun object. In the DataSet one, we could be a bit more user friendly (see comment below) |
||
} | ||
rClr::clrSet(self$ref, "DisplayUnit", unit) | ||
}, | ||
#' @field dimension The dimension of the values (Read-Only) | ||
#' @field dimension The dimension of the values | ||
dimension = function(value) { | ||
private$.dimension <- private$wrapExtensionMethodCached(WITH_DIMENSION_EXTENSION, "DimensionName", "dimension", private$.dimension, value) | ||
return(private$.dimension) | ||
if (missing(value)) { | ||
if (is.null(private$.dimension)) { | ||
private$.dimension <- private$wrapExtensionMethodCached(WITH_DIMENSION_EXTENSION, "DimensionName", "dimension", private$.dimension, value) | ||
} | ||
return(private$.dimension) | ||
} | ||
# updating the dimension | ||
rClr::clrSet(self$ref, "Dimension", getDimensionByName(value)) | ||
private$.dimension <- NULL | ||
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. For efficient usage, we are caching dimension and unit. We need to reset the cache obviously when updating the dimension |
||
private$.unit <- NULL | ||
} | ||
), | ||
public = list( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#' @title DataSet | ||
#' @docType class | ||
#' @description A wrapper around DataRepository exposing convenience methods to use and manipulate dataSets | ||
#' (typically observed data) containing an X column, a Y column and potentially an Error columns | ||
#' @format NULL | ||
DataSet <- R6::R6Class( | ||
"DataSet", | ||
inherit = Printable, | ||
cloneable = FALSE, | ||
active = list( | ||
#' @field name The name of the DataSet | ||
name = function(value) { | ||
if (missing(value)) { | ||
return(self$dataRepository$name) | ||
} | ||
self$dataRepository$name <- value | ||
}, | ||
#' @field xDimension Dimension in which the xValues are defined | ||
xDimension = function(value) { | ||
if (missing(value)) { | ||
return(private$.xValues$dimension) | ||
} | ||
private$setColumnDimension(private$.xValues, value) | ||
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. I have define a method for each |
||
}, | ||
#' @field xUnit Unit in which the xValues are defined | ||
xUnit = function(value) { | ||
if (missing(value)) { | ||
return(private$.xValues$displayUnit) | ||
} | ||
private$setColumnUnit(private$.xValues, value) | ||
}, | ||
#' @field xValues Values stored in the xUnit dimension (not necessarily in the base unit of the dimension) | ||
xValues = function(values) { | ||
if (missing(values)) { | ||
return(private$getColumnValues(private$.xValues)) | ||
} | ||
|
||
private$setColumnValues(private$.xValues, values) | ||
}, | ||
#' @field yDimension Dimension in which the xValues are defined | ||
yDimension = function(value) { | ||
if (missing(value)) { | ||
return(private$.yValues$dimension) | ||
} | ||
private$setColumnDimension(private$.yValues, value) | ||
}, | ||
#' @field yUnit Unit in which the yValues are defined | ||
yUnit = function(value) { | ||
if (missing(value)) { | ||
return(private$.yValues$displayUnit) | ||
} | ||
private$.yValues$displayUnit <- value | ||
}, | ||
#' @field yValues Values stored in the yUnit dimension (not necessarily in the base unit of the dimension) | ||
yValues = function(values) { | ||
if (missing(values)) { | ||
return(private$getColumnValues(private$.yValues)) | ||
} | ||
|
||
private$setColumnValues(private$.yValues, values) | ||
} | ||
), | ||
public = list( | ||
dataRepository = NULL, | ||
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. Public for now so that I can debug stuff. It will be private once the implementation is stable |
||
#' @description | ||
#' Initialize a new instance of the class | ||
#' @param dataRepository Instance of the \code{DataRepository} object to wrap | ||
#' @return A new `DotNetWrapper` object. | ||
initialize = function(dataRepository = NULL) { | ||
self$dataRepository <- dataRepository %||% private$createDataRepository() | ||
private$initializeCache() | ||
}, | ||
#' @description | ||
#' Print the object to the console | ||
#' @param ... Rest arguments. | ||
print = function(...) { | ||
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. |
||
private$printClass() | ||
invisible(self) | ||
} | ||
), | ||
private = list( | ||
.xValues = NULL, | ||
.yValues = NULL, | ||
setColumnValues = function(column, values) { | ||
# values are set in the display unit. We need to make sure we convert them to the base unit | ||
valuesInBaseUnit <- toBaseUnit(quantityOrDimension = column$dimension, values = values, unit = column$displayUnit) | ||
column$values <- valuesInBaseUnit | ||
invisible() | ||
}, | ||
getColumnValues = function(column) { | ||
# we need to convert the values in the display unit | ||
toUnit(quantityOrDimension = column$dimension, values = column$values, targetUnit = column$displayUnit) | ||
}, | ||
setColumnDimension = function(column, value){ | ||
# no need to update anything if we are setting the same values | ||
if(column$dimension == value){ | ||
return() | ||
} | ||
|
||
# save the values in their display unit before updating | ||
values <- private$getColumnValues(column) | ||
|
||
#now we need to update dimension (display unit will be the default one as per .NET implementation) | ||
column$dimension <- value | ||
|
||
private$setColumnValues(column, values) | ||
}, | ||
setColumnUnit = function(column, unit){ | ||
# no need to update anything if we are setting the same values | ||
if(column$displayUnit == unit){ | ||
return() | ||
} | ||
|
||
# save the values in their display unit before updating | ||
values <- private$getColumnValues(column) | ||
|
||
#now we need to update dimension and display unit | ||
column$displayUnit <- unit | ||
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. HERE: If the unit is not supported, we could easily update the dimension by using the method getDimensionForUnit. That way, the user would never have to worry about updating the dimension when updating the unit. 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. @msevestre I would not prefer to automatically change the dimension, as I see it as a sanity check here. Simply changing the unit only affects what actual values the data have, but not the meaning of the data. Changing the dimension actually means that the data means something else. What do you think? |
||
|
||
private$setColumnValues(column, values) | ||
}, | ||
createDataRepository = function() { | ||
# Create an empty data repository with a base grid and column | ||
dataRepository <- DataRepository$new() | ||
# Passing time for dimension for now | ||
xValues <- DataColumn$new(rClr::clrNew("OSPSuite.Core.Domain.Data.BaseGrid", "xValues", getDimensionByName(ospDimensions$Time))) | ||
|
||
# Passing concentration (mass) for dimension for now | ||
yValues <- DataColumn$new(rClr::clrNew("OSPSuite.Core.Domain.Data.DataColumn", "yValues", getDimensionByName(ospDimensions$`Concentration (mass)`), xValues$ref)) | ||
|
||
dataRepository$addColumn(xValues) | ||
dataRepository$addColumn(yValues) | ||
return(dataRepository) | ||
}, | ||
initializeCache = function() { | ||
private$.xValues <- self$dataRepository$baseGrid | ||
# TODO we need to be a bit more careful here | ||
private$.yValues <- self$dataRepository$allButBaseGrid[[1]] | ||
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. There is a more to do. Specifically regarding the error column. |
||
} | ||
) | ||
) |
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.
I updated core to support setting values as well.