fetchSM | R Documentation |
The function fetchSM
retrieves the student model from a
PnetWarehouse
or if not there, attempts to
recreate it from a serialized version. The function unpackSM
does this unpacking.
fetchSM(sr, warehouse)
unpackSM(sr, warehouse)
sr |
An object of class |
warehouse |
A |
The StudentRecord
object has two fields related to
student models: sm
and smser
. The former contains the
actual student model or NULL
if it has not yet been initialized
or restored from the database. The latter contains a character string
which contains a serialized version of the student model. In
particular, it is this serialized student model which is stored in the
database, not the actual student model.
The function fetchSM
is used to set the sm
field. It
checks the following places in order:
It looks in the warehouse
for a student net for the
given uid
for the record.
It calls unpackSM
to unpack the serialized record.
The function unpackSM
is wrapper for the function
WarehouseUnpack
.
The function fetchSM
returns the modified
StudentRecord
.
The function unpackSM
returns the student model (a
Pnet
).
Russell Almond
StudentRecord
PnetWarehouse
,
WarehouseUnpack
library(PNetica)
##Start with manifest
sess <- RNetica::NeticaSession()
RNetica::startSession(sess)
## BNWarehouse is the PNetica Net Warehouse.
## This provides an example network manifest.
config.dir <- file.path(library(help="Peanut")$path, "auxdata")
netman1 <- read.csv(file.path(config.dir,"Mini-PP-Nets.csv"),
row.names=1, stringsAsFactors=FALSE)
net.dir <- file.path(library(help="PNetica")$path, "testnets")
Nethouse <- PNetica::BNWarehouse(manifest=netman1,session=sess,key="Name",
address=net.dir)
dsr <- StudentRecord("*DEFAULT*",app="ecd://epls.coe.fsu.edu/P4Test",
context="*Baseline*")
sm(dsr) <- WarehouseSupply(Nethouse,"miniPP_CM")
PnetCompile(sm(dsr))
## dsr <- updateStats(eng,dsr)
statmat <- read.csv(file.path(config.dir,"Mini-PP-Statistics.csv"),
stringsAsFactors=FALSE)
rownames(statmat) <- statmat$Name
statlist <- sapply(statmat$Name,function (st)
Statistic(statmat[st,"Fun"],statmat[st,"Node"],st))
names(statlist) <- statmat$Name
dsr@stats <- lapply(statlist,
function (stat) calcStat(stat,sm(dsr)))
names(dsr@stats) <- names(statlist)
## dsr <- baselineHist(eng,dsr)
dsr@hist <- lapply(c("Physics"),
function (nd)
EABN:::uphist(sm(dsr),nd,NULL,"*Baseline*"))
names(dsr@hist) <- "Physics"
pnodenames <- names(PnetPnodes(sm(dsr)))
## Serialization and unserialization
dsr.ser <- as.json(dsr)
dsr1 <- parseStudentRecord(jsonlite::fromJSON(dsr.ser))
stopifnot(is.null(sm(dsr1)))
## at this point, SM has not yet been restored.
## It is there in the serial field
net1 <- unpackSM(dsr1,Nethouse)
stopifnot(all.equal(pnodenames,names(PnetPnodes(net1))))
dsr1 <- fetchSM(dsr1,Nethouse)
stopifnot(all.equal(pnodenames,names(PnetPnodes(sm(dsr1)))))
## Try this again, but first delete net from warehouse,
## So we are sure we are building it from serialized version.
WarehouseFree(Nethouse,PnetName(sm(dsr)))
dsr1 <- parseStudentRecord(jsonlite::fromJSON(dsr.ser))
stopifnot(is.null(sm(dsr1)))
## at this point, SM has not yet been restored.
## It is there in the serial field
net1 <- unpackSM(dsr1,Nethouse)
stopifnot(all.equal(pnodenames,names(PnetPnodes(net1))))
dsr1 <- fetchSM(dsr1,Nethouse)
stopifnot(all.equal(pnodenames,names(PnetPnodes(sm(dsr1)))))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.