-
Notifications
You must be signed in to change notification settings - Fork 12
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 all 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,27 +10,49 @@ 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) { | ||
private$wrapReadOnlyProperty("Name", value) | ||
}, | ||
#' @field unit The base unit in which the values are defined (Read-Only) | ||
unit = function(value) { | ||
if (!missing(value)) { | ||
value <- enc2utf8(value) | ||
} | ||
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)) | ||
} | ||
value <- enc2utf8(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) | ||
} | ||
value <- enc2utf8(value) | ||
# 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( | ||
|
@@ -41,7 +63,7 @@ DataColumn <- R6::R6Class( | |
if (self$unit == "") { | ||
private$printLine(self$name) | ||
} else { | ||
private$printLine(self$name, paste0("[", self$unit, "]")) | ||
private$printLine(self$name, paste0("base unit: [", self$unit, "]")) | ||
} | ||
invisible(self) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,18 @@ DataRepository <- R6::R6Class( | |
inherit = DotNetWrapper, | ||
cloneable = FALSE, | ||
active = list( | ||
#' @field name The name of the object. | ||
name = function(value) { | ||
private$wrapProperty("Name", value) | ||
}, | ||
#' @field baseGrid Returns the base column for the data repository (typically time column). | ||
baseGrid = function(value) { | ||
if (missing(value)) { | ||
if (is.null(private$.baseGrid)) { | ||
private$.baseGrid <- DataColumn$new(private$wrapReadOnlyProperty("BaseGrid", value)) | ||
private$.baseGrid <- DataColumn$new(private$wrapProperty("BaseGrid", value)) | ||
} | ||
return(private$.baseGrid) | ||
} | ||
|
||
private$throwPropertyIsReadonly("baseGrid") | ||
}, | ||
#' @field columns Returns all columns (including baseGrid) defined in the data repository. | ||
columns = function(value) { | ||
|
@@ -56,12 +58,59 @@ DataRepository <- R6::R6Class( | |
} | ||
), | ||
public = list( | ||
#' @description | ||
#' Adds a column to the data repository | ||
#' @param column Column to add | ||
addColumn = function(column) { | ||
validateIsOfType(column, DataColumn) | ||
rClr::clrCall(self$ref, "Add", column$ref) | ||
# we need to reset the cache when adding a new column | ||
private$.columns <- NULL | ||
private$.baseGrid <- NULL | ||
}, | ||
#' @description | ||
#' Initialize a new instance of the class | ||
#' @param ref Optional underlying DataRepository. If it is not provided, a new instance will be created | ||
#' @return A new `DataRepository` object. | ||
initialize = function(ref = NULL) { | ||
super$initialize(ref %||% rClr::clrNew("OSPSuite.Core.Domain.Data.DataRepository")) | ||
}, | ||
#' @description | ||
#' Print the object to the console | ||
#' @param ... Rest arguments. | ||
print = function(...) { | ||
private$printClass() | ||
invisible(self) | ||
}, | ||
#' @description | ||
#' Adds a new entry to meta data list or changes its value if the name is already present. | ||
#' | ||
#' @param name Name of new meta data list entry | ||
#' @param value Value of new meta data list entry | ||
addMetaData = function(name, 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. @PavelBal Add and remove meta data as separate function in data repo. 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 was this comment That I don't want to have. Let's create two methods instead |
||
if (length(name) != 1) { | ||
stop(messages$errorMultipleMetaDataEntries()) | ||
} | ||
validateIsString(name) | ||
validateIsString(value) | ||
dataRepositoryTask <- getNetTask("DataRepositoryTask") | ||
rClr::clrCall(dataRepositoryTask, "AddMetaData", self$ref, name, 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. is there a way to coherce a parameter to string in R. If yes, then we can remove the need for value to be a string 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.
|
||
# we need to reset the cache when adding a new meta data | ||
private$.metaData <- NULL | ||
}, | ||
#' @description | ||
#' Removes the meta data entry in the list if one is defined with this name | ||
#' | ||
#' @param name Name of meta data entry to delete | ||
removeMetaData = function(name) { | ||
if (length(name) != 1) { | ||
stop(messages$errorMultipleMetaDataEntries()) | ||
} | ||
validateIsString(name) | ||
dataRepositoryTask <- getNetTask("DataRepositoryTask") | ||
rClr::clrCall(dataRepositoryTask, "RemoveMetaData", self$ref, name) | ||
# we need to reset the cache when adding a new meta data | ||
private$.metaData <- NULL | ||
} | ||
), | ||
private = list( | ||
|
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.