Added Everage, Max and Min Download and Upload

This commit is contained in:
Luiz F Picolo 2021-10-09 10:43:29 -04:00
parent 9280d49441
commit e850e86794
5 changed files with 50 additions and 20 deletions

14
app.rb
View File

@ -8,16 +8,22 @@ set :database_file, 'config/database.yml'
Time.now.utc.localtime("-04:00")
get '/' do
@down_everage = Rate.average_download
@up_everage = Rate.average_upload
@down_everage = Rate.average(:download)
@up_everage = Rate.average(:upload)
@max_download = Rate.extremes(:maximum, :download)
@min_download = Rate.extremes(:minimum, :download)
@max_upload = Rate.extremes(:maximum, :upload)
@min_upload = Rate.extremes(:minimum, :upload)
@data = [
{
'name': 'Download Rate',
'data': Rate.get_download
'data': Rate.transfer('download')
},
{
'name': 'Upload Rate',
'data': Rate.get_upload
'data': Rate.transfer('upload')
},
]

View File

@ -5,20 +5,25 @@ Time.zone = "America/Campo_Grande"
ActiveRecord::Base.default_timezone = :local
class Rate < ActiveRecord::Base
def self.get_download
where(created_at: Date.today.all_day).collect { |p| [p.created_at.strftime('%d/%m %H:%M'), p.download] }
def self.transfer(type_transfer)
self.find_rate.collect {
|p| [p.created_at.strftime('%d/%m %H:%M'), p.public_send(type_transfer)]
}
end
def self.get_upload
where(created_at: Date.today.all_day).collect { |p| [p.created_at.strftime('%d/%m %H:%M'), p.upload] }
def self.average(type_transfer)
everage = self.find_rate.average(type_transfer)
everage.ceil(2)
end
def self.average_download
average(:download).ceil(2)
def self.extremes(type, value)
everage = self.find_rate.public_send(type, value)
everage.ceil(2)
end
def self.average_upload
average(:upload).ceil(2)
def self.find_rate
where(created_at: Date.today.all_day)
end
def self.save

View File

@ -8,7 +8,15 @@ h1 {
text-align: center !important;
}
.everage {
text-align: center;
margin-bottom: 13px;
section h1 {
font-size: 16px;
display: inline;
}
section {
margin: 0 0 0 30px;
}
canvas {
margin-top: 15px;
}

View File

@ -1 +1,17 @@
<h1>Data Transfer Test</h1>
<section>
<h1>Everage: </h1>
<b>Download:</b> <%= @down_everage %> Mbps
<b>Upload:</b> <%= @up_everage %> Mbps
</section>
<section>
<h1>Maximum: </h1>
<b>Download:</b> <%= @max_download %> Mbps
<b>Upload:</b> <%= @max_upload %> Mbps
</section>
<section>
<h1>Minimum: </h1>
<b>Download:</b> <%= @min_download %> Mbps
<b>Upload:</b> <%= @min_upload %> Mbps
</section>
<%= bar_chart @data, xtitle: "Datetime", ytitle: "Rate", id: "users-chart", height: "700px" %>

View File

@ -12,11 +12,6 @@
<title>Data Transfer Test</title>
</head>
<body>
<h1>Data Transfer Test</h1>
<div class="everage">
<b>Download:</b> <%= @down_everage %>
<b>Upload:</b> <%= @up_everage %>
</div>
<%= yield %>
</body>
</html>