Module running_integer

Module running_integer 

Source
Expand description

§Type

  • RunningInteger
    • RunningInteger maintains running statistics on a set of samples recorded into it.

    • The main.rs program contains a simple example of using this type.

§Example

    use rustics::Rustics;
    use rustics::Histogram;
    use rustics::PrintOpts;
    use rustics::Units;
    use rustics::printer_mut;
    use rustics::stdout_printer;
    use rustics::running_integer::RunningInteger;

    // Create an instance to record packet sizes. Set some print
    // options as an example.  Only float histograms have options,
    // so that field can be None.

    let printer    = Some(stdout_printer());
    let title      = Some("Network Packet Sizes".to_string());
    let units      = Some(Units::new("byte", "bytes"));
    let histo_opts = None;

    let print_opts = PrintOpts { printer, title, units, histo_opts };

    let mut packet_sizes =
        RunningInteger::new("Packet Sizes", &Some(print_opts));

    // Record some hypothetical packet sizes.

    let sample_count = 1000;

    for i in 1..=sample_count {
       packet_sizes.record_i64(i);
       assert!(packet_sizes.count() == i as u64);
    }

    // Print our statistics.

    packet_sizes.print();

    // Print just the histogram.  This example shows how the printer
    // code works.

    let printer = stdout_printer();      // create a shareable printer
    let printer = printer_mut!(printer); // get the printer out of the cell

    packet_sizes.print_histogram(printer);

    // We should have seen "sample_count" events.

    assert!(packet_sizes.count() == sample_count as u64);

    // Compute the expected mean.  We need the sum of
    //     1 + 2 + ... + n
    // which is
    //     n * (n + 1) / 2.

    let float_count = sample_count as f64;
    let float_sum   = float_count * (float_count + 1.0) / 2.0;
    let mean        = float_sum / float_count;

    assert!(packet_sizes.mean() == mean);

    // Let's record more samples, and verify the sample count as we go.

    let next_sample_count = 100;

    for i in 1..=next_sample_count {
       packet_sizes.record_i64(i + sample_count);
       assert!(packet_sizes.count() == (sample_count + i) as u64);
    }

    // Sample Output

    //        Network Packet Sizes
    //            Count               1,000
    //            Minimum                 1 byte
    //            Maximum             1,000 bytes
    //            Log Mode               10
    //            Mode Value            768 bytes
    //            Mean             +5.00500 e+2  bytes
    //            Std Dev          +2.88819 e+2  bytes
    //            Variance         +8.34166 e+4
    //            Skewness         -4.16317 e-11
    //            Kurtosis         -1.19999 e+0
    //          Log Histogram
    //          -----------------------
    //            0:                 1                 1                 2                 4
    //            4:                 8                16                32                64
    //            8:               128               256               488                 0

    // The mode value and histogram both show the most common bucket
    // is the range from 513 to 1,024 bytes, which is consistent with
    // the samples recorded.

Structs§

IntegerExporter
IntegerExport is used by a Hier instance to make summations of multiple RunningInteger instances.
RunningInteger
RunningInteger provides basic statistics on a stream of integer data samples.