From e850e86794d626d555e78d7a42ef6e93bb82848a Mon Sep 17 00:00:00 2001 From: Luiz Picolo Date: Sat, 9 Oct 2021 10:43:29 -0400 Subject: [PATCH] Added Everage, Max and Min Download and Upload --- app.rb | 14 ++++++++++---- models/rate.rb | 21 +++++++++++++-------- public/style.css | 14 +++++++++++--- views/home.erb | 16 ++++++++++++++++ views/layout.erb | 5 ----- 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/app.rb b/app.rb index e0a0d66..b0eb111 100644 --- a/app.rb +++ b/app.rb @@ -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') }, ] diff --git a/models/rate.rb b/models/rate.rb index bd8ae77..64b3004 100644 --- a/models/rate.rb +++ b/models/rate.rb @@ -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 diff --git a/public/style.css b/public/style.css index 2bda1a7..7f7cc6b 100644 --- a/public/style.css +++ b/public/style.css @@ -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; } \ No newline at end of file diff --git a/views/home.erb b/views/home.erb index 3c43cbb..789bdc2 100644 --- a/views/home.erb +++ b/views/home.erb @@ -1 +1,17 @@ +

Data Transfer Test

+
+

Everage:

+ Download: <%= @down_everage %> Mbps + Upload: <%= @up_everage %> Mbps +
+
+

Maximum:

+ Download: <%= @max_download %> Mbps + Upload: <%= @max_upload %> Mbps +
+
+

Minimum:

+ Download: <%= @min_download %> Mbps + Upload: <%= @min_upload %> Mbps +
<%= bar_chart @data, xtitle: "Datetime", ytitle: "Rate", id: "users-chart", height: "700px" %> \ No newline at end of file diff --git a/views/layout.erb b/views/layout.erb index d2f6941..e54e309 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -12,11 +12,6 @@ Data Transfer Test -

Data Transfer Test

-
- Download: <%= @down_everage %> - Upload: <%= @up_everage %> -
<%= yield %> \ No newline at end of file