2021-10-08 00:39:06 +00:00
|
|
|
require 'speedtest'
|
|
|
|
require 'sinatra/activerecord'
|
|
|
|
|
2021-10-09 00:48:07 +00:00
|
|
|
Time.zone = "America/Campo_Grande"
|
|
|
|
ActiveRecord::Base.default_timezone = :local
|
|
|
|
|
2020-06-03 03:02:01 +00:00
|
|
|
class Rate < ActiveRecord::Base
|
2021-10-09 14:43:29 +00:00
|
|
|
def self.transfer(type_transfer)
|
|
|
|
self.find_rate.collect {
|
|
|
|
|p| [p.created_at.strftime('%d/%m %H:%M'), p.public_send(type_transfer)]
|
|
|
|
}
|
2020-06-03 03:02:01 +00:00
|
|
|
end
|
|
|
|
|
2021-10-09 14:43:29 +00:00
|
|
|
def self.average(type_transfer)
|
|
|
|
everage = self.find_rate.average(type_transfer)
|
|
|
|
everage.ceil(2)
|
2020-06-03 03:02:01 +00:00
|
|
|
end
|
2021-10-08 00:39:06 +00:00
|
|
|
|
2021-10-09 14:43:29 +00:00
|
|
|
def self.extremes(type, value)
|
|
|
|
everage = self.find_rate.public_send(type, value)
|
|
|
|
everage.ceil(2)
|
2021-10-09 03:18:03 +00:00
|
|
|
end
|
|
|
|
|
2021-10-09 14:43:29 +00:00
|
|
|
|
|
|
|
def self.find_rate
|
|
|
|
where(created_at: Date.today.all_day)
|
2021-10-09 03:18:03 +00:00
|
|
|
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
|