Skip to content

Working with Data#

Making Data Requests#

The following services are required to retrieve parameter data

  • ISignalBus
  • IDataRequestSignalFactory

Hint

These services are obtained from Autofac by injecting into the View Model constructor as parameters, e.g.

public ViewModelConstructor(ISignalBus signalBus, IDataRequestSignalFactory dataRequestSignalFactory)
{
    // Use now, or store for use later...
}

A data request is made via a data request signal (obtained from IDataRequestSignalFactory).

In order to match results to requests made by the display, a sourceId needs to be specified; an appropriate value is this.ScopeIdentity.Guid as this uniquely identifies the display.

Hint

An optional requestId can be specified to distinguish between multiple requests of the same data request signal type.

The signal bus is used to initiate the data request by calling ISignalBus.Send().

The result is asynchronously sent back via the signal bus and therefore an appropriate handler needs to be registered in the View Model constructor using ISignal.Subscribe<resultSignalType>passing a suitable handler.

Note

The result signal type much match the request signal type, see list here

Hint

It is highly recommended to specify a filter checking that resultSignal.SourceId matches this.ScopeIdentity.Guid, avoiding the need to check in the handler.

Warning

Remember to match the SourceId property of result signal, not SignalId property.

Attention

The signal handler is ran by default on the Task pool.

If modifying the UI, dispatch to the UI thread as appropriate via SynchronizationContext.

Data Request and Results Reply Sequence#

Data Request Properties#

  • Data vs Samples requests
    • Requests for Samples retrieve the actual stored values
    • Requests for Data retrieve stored values re-sampled at a specified interval
  • Single vs Composite session requests
    • Single session requests return results for a single composite session
    • Composite session requests return results for all composite sessions within a composite session container (primary and secondary)
  • Request properties
    • Source Id/Request Id
      • Used to match a result to a request as explained above.
    • Composite Session key (or Container Session Container key for composite requests)
      • Usually obtained from ActiveCompositeSessionContainer or from arguments passed to notification methods
    • Parameter (or Parameter Container for composite requests)
    • Extent of data request
      • Requests for Samples
        • Start Time and Sample Count, or
        • Time Range
      • Requests for Data
        • Time Range and Sample Count (interval is calculated)
    • Sample Direction
      • Retrieve forwards (Next) or backwards (Previous) through the stored values
    • Sample Mode (only applicable for requests for Data)
      • How the stored values are re-sampled (First Value, Minimum, Maximum, Mean etc)
    • Sample Count (see Extent above)
      • Maximum number of samples to fetch (requests for Samples)
      • Used to calculate sample interval (requests for Data)
    • Lap, Statistics Level, Statistics Option
      • What statistics to calculate and over what time range

Data request and result signals#

Handle the matching result signal type for each request signal type used

  • DataRequestSignal
    • Re-sampled values for a single composite session
    • Handle DataResultSignal to process result
  • SampleRequestSignal
    • Actual values for a single composite session
    • Handle SampleResultSignal to process result
  • CompositeDataRequestSignal
    • Re-sampled values for composite session container (compare set)
    • Handle CompositeDataResultSignal to process result
  • CompositeSampleRequestSignal
    • Actual values for composite session container (compare set)
    • Handle CompositeSampleResultSignal to process result
  • DataStatisticsRequestSignal
    • Statistic values
    • Handle DataStatisticsResultSignal to process result

Data Results#

Results are accessed via the matching results signal

  • IResult
    • ParameterValues property, see below
      • Result of data request obtained from SQL Race
      • Remember to call Lock()/Unlock() if retaining a reference
    • IRequest property (original request)
  • ICompositeResult
    • Results property (IDictionary<CompositeSessionKey, IResult>)
      • IResult for each composite session
    • ICompositeRequest property (original request)
  • IStatisticsResult
    • No results property (bug, see below)
    • IRequest property (original request)

Attention

Currently data statistics requests are broken because the statistics result does not actually expose the retrieved data

ParameterValues properties#

Values retrieved by SQL Race are passed back in a ParameterValues instance

  • SampleCount
    • Actual number of values returned from data request
  • TimeStamp
    • The timestamp of each value
  • DataStatus
    • The status of each value (e.g. Missing if no meaningful value)
  • Data
    • Each value (for sample requests and for mean data requests)
  • DataFirst
    • Each first value (for first data requests)
  • DataMin
    • Each minimum value (for minimum data requests)
  • DataMax
    • Each maximum value (for maximum data requests)

Attention

Due to the use of array pooling, the length of the arrays may be greater then the retrieved data quantity

Always refer to SampleCount and not array length

Data request guidelines#

  • Only attempt a data request when CanRetrieveData is true
  • Handle the following situations and make data requests to ensure the custom display is up to date (observing CanRetrieveData as per above)
    • Page switch and display visibility changes (stacked displays)
      • Override OnCanRenderDisplayChanged()
    • Sessions loaded/unloaded
      • Override OnCompositeSessionLoaded() and OnCompositeSessionUnLoaded()
    • Session association changes
      • Override OnCompositeSessionContainerChanged()
    • Copy/Paste displays
      • Override OnInitialised()
    • Parameters added/removed
      • Override OnParameterAdded() and OnParameterRemoved()