Added Everage, Max and Min Download and Upload
This commit is contained in:
parent
9280d49441
commit
e850e86794
14
app.rb
14
app.rb
@ -8,16 +8,22 @@ set :database_file, 'config/database.yml'
|
|||||||
Time.now.utc.localtime("-04:00")
|
Time.now.utc.localtime("-04:00")
|
||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
@down_everage = Rate.average_download
|
@down_everage = Rate.average(:download)
|
||||||
@up_everage = Rate.average_upload
|
@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 = [
|
@data = [
|
||||||
{
|
{
|
||||||
'name': 'Download Rate',
|
'name': 'Download Rate',
|
||||||
'data': Rate.get_download
|
'data': Rate.transfer('download')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'Upload Rate',
|
'name': 'Upload Rate',
|
||||||
'data': Rate.get_upload
|
'data': Rate.transfer('upload')
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -5,20 +5,25 @@ Time.zone = "America/Campo_Grande"
|
|||||||
ActiveRecord::Base.default_timezone = :local
|
ActiveRecord::Base.default_timezone = :local
|
||||||
|
|
||||||
class Rate < ActiveRecord::Base
|
class Rate < ActiveRecord::Base
|
||||||
def self.get_download
|
def self.transfer(type_transfer)
|
||||||
where(created_at: Date.today.all_day).collect { |p| [p.created_at.strftime('%d/%m %H:%M'), p.download] }
|
self.find_rate.collect {
|
||||||
|
|p| [p.created_at.strftime('%d/%m %H:%M'), p.public_send(type_transfer)]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_upload
|
def self.average(type_transfer)
|
||||||
where(created_at: Date.today.all_day).collect { |p| [p.created_at.strftime('%d/%m %H:%M'), p.upload] }
|
everage = self.find_rate.average(type_transfer)
|
||||||
|
everage.ceil(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.average_download
|
def self.extremes(type, value)
|
||||||
average(:download).ceil(2)
|
everage = self.find_rate.public_send(type, value)
|
||||||
|
everage.ceil(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.average_upload
|
|
||||||
average(:upload).ceil(2)
|
def self.find_rate
|
||||||
|
where(created_at: Date.today.all_day)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.save
|
def self.save
|
||||||
|
@ -8,7 +8,15 @@ h1 {
|
|||||||
text-align: center !important;
|
text-align: center !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.everage {
|
section h1 {
|
||||||
text-align: center;
|
font-size: 16px;
|
||||||
margin-bottom: 13px;
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
section {
|
||||||
|
margin: 0 0 0 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
margin-top: 15px;
|
||||||
}
|
}
|
@ -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" %>
|
<%= bar_chart @data, xtitle: "Datetime", ytitle: "Rate", id: "users-chart", height: "700px" %>
|
@ -12,11 +12,6 @@
|
|||||||
<title>Data Transfer Test</title>
|
<title>Data Transfer Test</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Data Transfer Test</h1>
|
|
||||||
<div class="everage">
|
|
||||||
<b>Download:</b> <%= @down_everage %>
|
|
||||||
<b>Upload:</b> <%= @up_everage %>
|
|
||||||
</div>
|
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user