Regno Standard - ParamSamplesDoc 


Data - ParamSamplesDoc

The ParamSamplesDoc document is a data document that contains the properties and values for a collection of data samples for a single data channel.

The ParamSamplesDoc document is used to store raw sample values for user specified intervals. The document contains the field documentInterval that is used to specify the time range that the raw data samples values have sampled from.

Field Data Type Required Default Description
configDocId String Yes - The unique identifier (id) of the ConfigDoc document that this document is associated with.
id String Yes - Regno unique document identifier.
type Fixed String No ParamSamplesDoc Type of the document, resolved from fixed document types.
dataType Fixed String No Double Data type of the values in the document, used for serialization and deserialization. Valid Options are: Double, Long, Byte, Short, Float, Integer
sampleTimes Byte[] No - An array of compressed 64-bit Long values. Each value represents the timestamp value of the sample at the associated array index. The timestamp represents the number of nanoseconds since the reference time of midnight, 1st January 1970.
times Int64[] No - An array of long values. Each value represents the sample value at the associated array index. The type of the value is DataType
sampleValues Byte[] No - An array of compressed values. Each value represents the sample value at the associated array index. The type of the value is DataType
sampleCount Int64 Yes - A Long that holds the value for the number of samples in a document.
paramDefDocId String Yes - The unique identifier (id) of the ParamDefinitionDoc that holds the properties for the parameter associated with the data values stored in this document.
startTime Int64 Yes - A 64-bit Long timestamp specifying the start time of the data that this document holds. The timestamp represents the number of nanoseconds since the reference time of midnight, 1st January 1970.
endTime Int64 Yes - A 64-bit Long timestamp specifying the end time of the data that this document holds. The timestamp represents the number of nanoseconds since the reference time of midnight, 1st January 1970.
min Double Yes - A 64-bit Double value specifying the minimum value of the data that this document holds.
max Double Yes - A 64-bit Double value specifying the maximum value of the data that this document holds.

Sample JSON

Below is a sample JSON representation of the ParamSamplesDoc structure:

ParamSamplesDoc Sample JSON
{
  "configDocId": "-",
  "dataType": {
    "$type": "Fixed String"
  },
  "endTime": {
    "$type": "Int64"
  },
  "id": "-",
  "max": 0,
  "min": 0,
  "paramDefDocId": "-",
  "sampleCount": {
    "$type": "Int64"
  },
  "sampleTimes": [
    {
      "$type": "Byte"
    }
  ],
  "sampleValues": [
    {
      "$type": "Byte"
    }
  ],
  "startTime": {
    "$type": "Int64"
  },
  "times": [
    {
      "$type": "Int64"
    }
  ],
  "type": {
    "$type": "Fixed String"
  }
}

Data Decompression Guide

The sampleTimes and sampleValues fields in the ParamSamplesDoc contain compressed byte arrays that need to be decompressed before use. The Regno Standard uses GZip compression to efficiently store large arrays of sample data.

Decompression Process:

  1. GZip Decompression: First, decompress the byte array using standard GZip decompression
  2. Type Conversion: Convert the decompressed bytes back to the appropriate data type based on the dataType field

Implementation Examples:

C# Implementation
using System;
using System.IO;
using System.IO.Compression;

public static class RegnoDecompression
{
    // For sampleTimes (always long arrays)
    public static long[] DecompressSampleTimes(byte[] compressedBytes)
    {
        if (compressedBytes == null || compressedBytes.Length == 0)
            return new long[0];
            
        using (var compressedStream = new MemoryStream(compressedBytes))
        using (var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
        using (var resultStream = new MemoryStream())
        {
            zipStream.CopyTo(resultStream);
            var decompressedBytes = resultStream.ToArray();
            
            var result = new long[decompressedBytes.Length / sizeof(long)];
            Buffer.BlockCopy(decompressedBytes, 0, result, 0, decompressedBytes.Length);
            return result;
        }
    }

    // For sampleValues - generic method based on dataType
    public static T[] DecompressSampleValues<T>(byte[] compressedBytes) where T : struct
    {
        if (compressedBytes == null || compressedBytes.Length == 0)
            return new T[0];
            
        using (var compressedStream = new MemoryStream(compressedBytes))
        using (var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
        using (var resultStream = new MemoryStream())
        {
            zipStream.CopyTo(resultStream);
            var decompressedBytes = resultStream.ToArray();
            
            var elementSize = System.Runtime.InteropServices.Marshal.SizeOf<T>();
            var result = new T[decompressedBytes.Length / elementSize];
            Buffer.BlockCopy(decompressedBytes, 0, result, 0, decompressedBytes.Length);
            return result;
        }
    }
    
    // Usage examples:
    // var times = DecompressSampleTimes(paramSamplesDoc.SampleTimes);
    // var values = DecompressSampleValues<double>(paramSamplesDoc.SampleValues);
}
JavaScript Implementation
Python Implementation

Key Points:

  • sampleTimes are always 64-bit long values representing nanoseconds since Unix epoch
  • sampleValues data type is specified by the dataType field (Double, Long, Byte, Short, Float, Integer)
  • Both arrays have the same length, with each index representing corresponding time and value pairs
  • The sampleCount field indicates the total number of samples in the arrays