parseStats: Functions for (un)serializing stats from student records.

parseStatsR Documentation

Functions for (un)serializing stats from student records.

Description

The functions unparseStats and stats2json serialize the statistics as a JSON record. The function parseStats reverses the process.

Usage

parseStats(slist)
unparseStats(slist, flatten=FALSE)
stats2json(slist, flatten=FALSE)

Arguments

slist

A list of statistics. For parseStats this should be the output of fromJSON. For the others, this is just a list of statistic values.

flatten

If true, then vector-valued statistics (i.e., PnodeMargin, will have their values flattened into scalars. If not they will be left as vectors.

Details

The function unparseStats massages the list of statistics so it will be output in clean JSON (in particular, using unboxer to make sure scalars appear as scalars and not vectors). The function stats2json is just toJSON(unparseStats(slist)).

If flatten is true, then vector value statstics will be flattened. For example, if the statistic “Physics_Margin” has three values with labels “High”, “Medium”, and “Low”, then it will be replaced with three statistics with the names “Physics_Margin.High”, “Physics_Margin.Medium”, and “Physics_Margin.Low”.

The function parseStatistics is designed to reverse the process.

Value

The function unparseStats returns a list which is ready to be passed to toJSON. In particular, scalars are marked using unboxer.

The function stats2json returns a string containing the JSON.

The function parseStats returns a list of statistics values. this is suitable for being set to the stats field of the StudentRecord object.

Note

When using flatten=TRUE, avoid periods, ‘.’, in the names of statistics, as this marker is used to recreate the nested structure in parseStats.

Author(s)

Russell Almond

See Also

buildObject gives general information about how the parsing/unparsing protocol works.

Statistic gives a list of available statistics.

StudentRecord talks about the statitic fields of the student records.

Examples


stats <- list(Physics_EAP=0,EnergyTransfer_EAP=.15,
              Physics_Margin=c(High=1/3,Medium=1/3,
                               Low=1/3))
stats2json(stats)

stats1 <- parseStats(ununboxer(unparseStats(stats)))
stopifnot(all.equal(stats,stats1,tolerance=.0002))

stats2json(stats,flatten=TRUE)

stats2 <- parseStats(ununboxer(unparseStats(stats,flatten=TRUE)))
stopifnot(all.equal(stats,stats2,tolerance=.0002))



ralmond/EABN documentation built on Aug. 30, 2023, 12:52 p.m.