data-transfer-test/models/rate.rb

22 lines
500 B
Ruby
Raw Normal View History

2021-10-08 00:39:06 +00:00
require 'speedtest'
require 'sinatra/activerecord'
2020-06-03 03:02:01 +00:00
class Rate < ActiveRecord::Base
def self.get_download
all.collect { |p| [p.created_at.strftime('%d/%m %H:%M'), p.download] }
end
def self.get_upload
all.collect { |p| [p.created_at.strftime('%d/%m %H:%M'), p.upload] }
end
2021-10-08 00:39:06 +00:00
def self.save
test = Speedtest::Test.new(debug: false)
result = test.run
Rate.create({
download: result.pretty_download_rate,
upload: result.pretty_upload_rate,
})
end
2020-06-03 03:02:01 +00:00
end