diff options
| author | Michele Calgaro <michele.calgaro@yahoo.it> | 2025-03-02 18:37:22 +0900 |
|---|---|---|
| committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2025-03-06 12:31:12 +0900 |
| commit | 44ef0bd5fe47a43e47aec5f7981b6c1d728dd9a8 (patch) | |
| tree | 2b29e921a9bccea53444ed9bbed06a25a5fe20cc /estimation-scripts/Sample.rb | |
| parent | d1f24dae035c506d945ca13f2be398aa0a4de8cc (diff) | |
| download | ktorrent-44ef0bd5fe47a43e47aec5f7981b6c1d728dd9a8.tar.gz ktorrent-44ef0bd5fe47a43e47aec5f7981b6c1d728dd9a8.zip | |
Restructure source files into 'src' subfolder
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'estimation-scripts/Sample.rb')
| -rw-r--r-- | estimation-scripts/Sample.rb | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/estimation-scripts/Sample.rb b/estimation-scripts/Sample.rb deleted file mode 100644 index b0c38c2..0000000 --- a/estimation-scripts/Sample.rb +++ /dev/null @@ -1,64 +0,0 @@ - -class Sample - - attr_reader :time, :speed, :bytesDownloaded, :bytesLeft, :peersTotal - - def Sample.averageSpeed(sample1, sample2) - if sample2.time - sample1.time > 0 - return (sample1.bytesLeft - sample2.bytesLeft).to_f / (sample2.time - sample1.time).to_f - else - return sample1.speed - end - end - - def <=>(other) - @time <=> other.time - end - - # parses a single sample from a line. Format is - # - # \<tt>timestamp,speed,bytesDownloaded,bytesLeft,peersTotal</tt> - # - # where - # - timestamp is in seconds since epoch (Integer) - # - speed is bytes/seconds as Integer - # - bytesDownloaded, bytesLeft are bytes as Integer - # - peersTotal is the number of available peers (both seeders and leecher, both - # connected and not connected to us) - - def Sample.parse(line) - - splitted = line.split(",") - - # TODO: do better error checking - return nil if splitted.length != 5 - - time = splitted[0].to_i - speed = splitted[1].to_i - bytesDownloaded = splitted[2].to_i - bytesLeft = splitted[3].to_i - peersTotal = splitted[4].to_i - return Sample.new(time, speed, bytesDownloaded, bytesLeft, peersTotal) - end - - # parses samples from a text file, with one sample per line - def Sample.parseFromFile(filename) - samples = Hash.new - - input = File.open(filename) - input.each_line do |line| - s = Sample.parse(line) - samples[s.time] = s unless s == nil - end - input.close - return samples - end - - def initialize(time, speed, bytesDownloaded, bytesLeft, peersTotal) - @time = time - @speed = speed - @bytesDownloaded = bytesDownloaded - @bytesLeft = bytesLeft - @peersTotal = peersTotal - end -end |
