Statistics
Statistics provide a way to store and create numeric statistical data in a decoder. They may take any IEEE singed double-precision number. Statistics are very similar to DatafieldFloat objects but the chief distinctions are:
Statistic objects are not always reset between nextDecoder calls (unless the resettable constructor argument is set to true) whereas Datafields always are.
Statistics are collected by the stat collector service only whereas Datafields are collected by other Collectors.
decoder.Statistic object
Statistic(name : String, initialValue: Number, resettable: Boolean)
Create a statistic with the name name by which it may be referred to later. Unlike Datafields, Statistic objects are also created with a supplied initial value initialValue. The final boolean parameter resettable relates to whether the Statistic is reset (back to initialValue) in between being collected by the statistics collector. The Statistic Collector runs each time dec.nextDecoder is called. We describe this later in this document.
var stat = new decoder.Statistic( "stat.name" , 1.0 , false ) |
Statistic.set(value : Number) : Void
Assign the Statistic contents from the JavaScript number value.
var stat = new decoder.Statistic( "stat.name" , 0 , false ) stat.set( 12.34 ) |
Statistic.get() : Number
Retrieve the value of this Statistic as a JavaScript Number.
var stat = new decoder.Statistic( "stat.name" , 0 , false ) stat.set( 12.34 ) var isTrue = stat.get() === 12.34 |
Statistic.incrementBy(value : Number) : Void
Increment the contents of the Statistic by the JavaScript number value. To decrement the Statistic a negative number can be passed to this method.
var stat = new decoder.Statistic( "stat.name" , 0 , false ) stat.incrementBy( 100 ) stat.incrementBy(- 30 ) // stat now represents a value of 70 |
Statistic.increment() : Void
Increment the currently stored value by 1.
var stat = new decoder.Statistic( "stat.name" , 0 , false ) stat.increment() // stat now holds a value of 1 |
Statistic.reset() : Void
This resets the Statistic to hold the "initial value" as passed to the constructor.
var stat = new decoder.Statistic( "stat.name" , 1 , false ) stat.increment( 1 ) // stat now holds a value of 2 stat.reset() // stat now holds a value of 1 again |
decoder.protocol object
protocol.addStatistic(stat : decoder.Stastic) : Void
Register the Statistic stat with the protocol. Only registered Statistics are passed to the statistic collector.
protocol.addDatafield(df : decoder.Datafield) : Void
Register the Datafield df with the protocol. Only registered Datafields are passed to the next layer or collector when calling dec.nextDecoder().
var dfMarketId = new decoder.DatafieldUInt( "script_v8.market_id" ) decoder.protocol.addDatafield(dfMarketId) |
protocol.getDatafield(dfName : String) : decoder.Datafield
This method is used to retrieve a Datafield from another layer below the current decoder with the name dfName. The Datafield can then be modified by the current layer and the changes will be reflected when the Datafield reaches the collector.
This method should only be called in the main script body so that it is run at protocol creation time. If used within callbacks, or a Datafield with the requested is name is not defined, this method will return the JavaScript "null" object.
var dfMarketId = decoder.protocol.getDatafield( "script_v8.market_id" ) function on_data(dec) { // after on_data it can be assumed the Datafield may have been set by the preceding layer. if (dfMarketId instanceof decoder.DatafieldString) { dfMarketId.append( "456" ) console.log(dfMarketId.get()) } } |