BandwidthAccumulator class

Accumulates byte values over time for streaming scenarios.

Useful for tracking bandwidth usage, download progress, and network monitoring.

Example:

final accumulator = BandwidthAccumulator();

accumulator.add(ByteConverter.fromKiloBytes(100));
accumulator.add(ByteConverter.fromKiloBytes(250));

print(accumulator.total);    // ByteConverter representing 350 KB
print(accumulator.average);  // ByteConverter representing 175 KB
print(accumulator.peak);     // ByteConverter representing 250 KB
print(accumulator.count);    // 2

Constructors

BandwidthAccumulator({bool trackTimestamps = false})
Creates a new bandwidth accumulator.

Properties

average → ByteConverter
Average bytes per sample.
no setter
averageRate → DataRate?
Calculates the average rate between consecutive samples.
no setter
count → int
Number of samples collected.
no setter
elapsed → Duration
Duration since the first sample was added.
no setter
hashCode → int
The hash code for this object.
no setterinherited
isEmpty → bool
Whether any samples have been collected.
no setter
isNotEmpty → bool
Whether samples have been collected.
no setter
min → ByteConverter
Minimum sample value.
no setter
peak → ByteConverter
Peak (maximum) sample value.
no setter
rate → DataRate?
Calculates the data rate based on total bytes and elapsed time.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
samples → List<ByteConverter>
All collected samples.
no setter
standardDeviation → double
Standard deviation of sample values.
no setter
total → ByteConverter
Total accumulated bytes.
no setter
trackTimestamps → bool
Whether to track timestamps for rate calculations.
final
variance → double
Variance of sample values.
no setter

Methods

add(ByteConverter sample) → void
Adds a byte sample to the accumulator.
addAt(ByteConverter sample, DateTime timestamp) → void
Adds a byte sample with a specific timestamp.
lastSamples(int n) → List<ByteConverter>
Gets the last N samples.
movingAverage(int windowSize) → ByteConverter
Calculates a moving average over the last windowSize samples.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Resets the accumulator, clearing all samples.
toString() → String
A string representation of this object.
inherited
toSummary() → Map<String, dynamic>
Returns a summary map of the accumulator state.

Operators

operator ==(Object other) → bool
The equality operator.
inherited