parseStudentRecord | R Documentation |
The as.json
function takes an
StudentRecord
(among other objects) and turns it
into JSON. The function parseStudentRecord
takes the list produced
as the output to fromJSON
and turns it back
into an StudentRecord
object.
parseStudentRecord(rec)
## S4 method for signature 'StudentRecord,list'
as.jlist(obj, ml, serialize=TRUE)
rec |
A list which comes from running
|
obj |
The object being serialized; usually |
ml |
A list of fields of the object. |
serialize |
A logical flag. If true,
|
See the description for as.json
for more
description of the general JSON conversion prototocl.
The StudentRecord
contains a
Pnet
field in the student model. This takes
some post-processing to to properly restore.
The as.jlist
method for the StudentRecord
serializes the sm
field using the
PnetSerialize
method. This produces a slob
(string large object) which is stored in the smser
field of the
StudentRecord
.
The parseStudentRecord
function restores the smser
field, but not the sm
field. This must be done in the context
of the StudentRecordSet
, or equivalently the
PnetWarehouse
, which is currently managing
the networks. To finish the process, call fetchSM
to
restore the student model network.
The function parseStudentRecord
returns a student record object
with the student model not yet initialized.
The as.jlist
method returns a list which can be passed to
toJSON
to produce legible JSON from the R
object.
Russell Almond
StudentRecord
, as.json
,
getOneRec
, getManyRecs
fetchSM
, PnetSerialize
## Requires PNetica
library(PNetica) ## Must load to setup Netica DLL
app <- "ecd://epls.coe.fsu.edu/EITest"
sess <- RNetica::NeticaSession()
RNetica::startSession(sess)
config.dir <- file.path(library(help="Peanut")$path, "auxdata")
net.dir <- file.path(library(help="PNetica")$path,"testnets")
netman <- read.csv(file.path(config.dir, "Mini-PP-Nets.csv"),
row.names=1, stringsAsFactors=FALSE)
stattab <- read.csv(file.path(config.dir, "Mini-PP-Statistics.csv"),
as.is=TRUE)
Nethouse <- PNetica::BNWarehouse(netman,session=sess,
address=net.dir)
cl <- new("CaptureListener")
listeners <- list("cl"=cl)
ls <- ListenerSet(sender= paste("EAEngine[",app,"]"),
db=MongoDB(noMongo=TRUE), listeners=listeners)
eng <- newBNEngineNDB(app=app,warehouse=Nethouse,
listenerSet=ls,manifest=netman,
profModel="miniPP_CM",
histNodes="Physics",
statmat=stattab,
activeTest="EAActive.txt")
## Standard initialization methods.
loadManifest(eng,netman)
eng$setHistNodes("Physics")
configStats(eng,stattab)
setupDefaultSR(eng)
recset <- eng$studentRecords()
sr0 <- getRecordForUser(eng,"S1")
eap0 <- stat(sr0,"Physics_EAP")
sr0.ser <- as.json(sr0)
sr0a <- parseStudentRecord(jsonlite::fromJSON(sr0.ser))
sr0a <- fetchSM(sr0a,recset$warehouse())
## This should relink to the same student model
stopifnot(sm(sr0a)==sm(sr0),abs(eap0-stat(sr0a,"Physics_EAP")) <.0001)
## Next add some evidence and test again.
e1 <- EvidenceSet(uid="S1",app="Test",context="PPcompEM",
obs=list("CompensatoryObs"="Right"))
e1 <- logEvidence(eng,sr0,e1)
sr1 <- accumulateEvidence(eng,sr0,e1)
eap1 <- stat(sr1,"Physics_EAP")
sr1.ser <- as.json(sr1)
## Force delete student model to make sure that it is properly
## recovered.
WarehouseFree(Nethouse,PnetName(sm(sr1)))
stopifnot(!is.active(sm(sr1))) # No longer active.
sr1a <- parseStudentRecord(jsonlite::fromJSON(sr1.ser))
sr1a <- fetchSM(sr1a,recset$warehouse())
eap1a <- stat(sr1a,"Physics_EAP")
stopifnot(all(evidence(sr1)==evidence(sr1a)),
abs(eap1-eap1a) <.001)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.