Skip to content

Commit

Permalink
calendars
Browse files Browse the repository at this point in the history
  • Loading branch information
palatej committed Mar 6, 2024
1 parent 5ff31f9 commit 44ebb8e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions R/modellingcontext.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ modelling_context<-function(calendars=NULL, variables=NULL){
#' @export
#' @rdname jd3_utilities
.p2r_calendars<-function(p){
n<-length(p)
n<-length(p$calendars)
lcal <- NULL
if (n > 0){
lcal<-lapply(1:n, function(i){return(.p2r_calendardef(p$calendars[[i]]$value))})
Expand All @@ -402,27 +402,24 @@ modelling_context<-function(calendars=NULL, variables=NULL){
.r2p_calendars<-function(r){
p<-jd3.Calendars$new()
ns<-names(r)
length<-length(ns)
n<-length(ns)
# To take into account empty calendars
length_cal <- sapply(r, length)

p<-lapply((1:n)[length_cal!=0], function(i){
p$calendars<-lapply((1:n)[length_cal!=0], function(i){
entry<-jd3.Calendars$CalendarsEntry$new()
entry$key<-ns[i]
entry$value<-.r2p_calendardef(r$calendars[[i]])
entry$value<-.r2p_calendardef(r[[i]])
return(entry)
})
if (length(lcal) > 0) {
p$calendars<-lcal
}
return (p)
}

#' @export
#' @rdname jd3_utilities
.p2jd_calendars<-function(p){
bytes<-p$serialize(NULL)
jcal <- .jcall("jdplus/toolkit/base/r/util/Modelling", "Ljdplus/toolkit/base/api/timeseries/regression/ModellingContext;",
jcal <- .jcall("jdplus/toolkit/base/r/util/Modelling", "Ljdplus/toolkit/base/api/timeseries/calendars/CalendarManager;",
"calendarsOf",
bytes)
return (jcal)
Expand All @@ -432,15 +429,15 @@ modelling_context<-function(calendars=NULL, variables=NULL){
#' @rdname jd3_utilities
.jd2p_calendars<-function(jd){
bytes<-.jcall("jdplus/toolkit/base/r/util/Modelling", "[B", "toBuffer", jd)
p<-RProtoBuf::read(jd3.ModellingContext, bytes)
p<-RProtoBuf::read(jd3.Calendars, bytes)
return (p)
}


#' @export
#' @rdname jd3_utilities
.jd2r_calendars<-function(jcals){
p<-.jd2p_context(jcals)
p<-.jd2p_calendars(jcals)
return (.p2r_calendars(p))
}

Expand Down

0 comments on commit 44ebb8e

Please sign in to comment.