Initial commit

This commit is contained in:
Luiz F Picolo 2020-06-02 23:02:01 -04:00
commit a1ade51f6b
15 changed files with 294 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
db/development.sqlite3
db/test.sqlite3
public/node_modules

14
Gemfile Normal file
View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'activerecord'
gem 'speedtest'
gem 'sinatra'
gem 'sinatra-activerecord'
gem 'chartkick'
gem 'rerun'
gem 'sqlite3'
gem 'rake'

77
Gemfile.lock Normal file
View File

@ -0,0 +1,77 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (6.0.3.1)
activesupport (= 6.0.3.1)
activerecord (6.0.3.1)
activemodel (= 6.0.3.1)
activesupport (= 6.0.3.1)
activesupport (6.0.3.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
chartkick (3.3.1)
concurrent-ruby (1.1.6)
ffi (1.12.2)
groupdate (5.0.0)
activesupport (>= 5)
httparty (0.18.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
listen (3.2.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2020.0512)
minitest (5.14.1)
multi_xml (0.6.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
rack (2.2.2)
rack-protection (2.0.8.1)
rack
rake (13.0.1)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
rerun (0.13.0)
listen (~> 3.0)
ruby2_keywords (0.0.2)
sinatra (2.0.8.1)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.8.1)
tilt (~> 2.0)
sinatra-activerecord (2.0.18)
activerecord (>= 4.1)
sinatra (>= 1.0)
speedtest (0.2.3)
httparty (~> 0.13)
sqlite3 (1.4.2)
thread_safe (0.3.6)
tilt (2.0.10)
tzinfo (1.2.7)
thread_safe (~> 0.1)
zeitwerk (2.3.0)
PLATFORMS
ruby
DEPENDENCIES
activerecord
chartkick
groupdate
rake
rerun
sinatra
sinatra-activerecord
speedtest
sqlite3
BUNDLED WITH
2.1.4

3
Rakefile Normal file
View File

@ -0,0 +1,3 @@
require 'sinatra/activerecord'
require 'sinatra/activerecord/rake'
require './app'

23
app.rb Normal file
View File

@ -0,0 +1,23 @@
require 'sinatra'
require 'sinatra/activerecord'
require 'chartkick'
require './models/rate'
set :database_file, 'config/database.yml'
Time.now.utc.localtime("-04:00")
get '/' do
@data = [
{
'name': 'Taxa de Download',
'data': Rate.get_download
},
{
'name': 'Taxa de Upload',
'data': Rate.get_upload
},
]
erb :home
end

17
config/database.yml Normal file
View File

@ -0,0 +1,17 @@
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

View File

@ -0,0 +1,10 @@
class CreateRateTable < ActiveRecord::Migration[6.0]
def change
create_table :rates do |t|
t.decimal :download
t.decimal :upload
t.datetime :created_at
t.datetime :updated_at
end
end
end

22
db/schema.rb Normal file
View File

@ -0,0 +1,22 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_05_29_011930) do
create_table "rates", force: :cascade do |t|
t.decimal "download"
t.decimal "upload"
t.datetime "created_at"
t.datetime "updated_at"
end
end

13
init.rb Normal file
View File

@ -0,0 +1,13 @@
require 'speedtest'
require 'sinatra/activerecord'
require './models/rate'
test = Speedtest::Test.new(debug: false)
result = test.run
Rate.create({
download: result.pretty_download_rate,
upload: result.pretty_upload_rate,
})

9
models/rate.rb Normal file
View File

@ -0,0 +1,9 @@
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
end

64
public/package-lock.json generated Normal file
View File

@ -0,0 +1,64 @@
{
"name": "public",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"chart.js": {
"version": "2.9.3",
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-2.9.3.tgz",
"integrity": "sha512-+2jlOobSk52c1VU6fzkh3UwqHMdSlgH1xFv9FKMqHiNCpXsGPQa/+81AFa+i3jZ253Mq9aAycPwDjnn1XbRNNw==",
"requires": {
"chartjs-color": "^2.1.0",
"moment": "^2.10.2"
}
},
"chartjs-color": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/chartjs-color/-/chartjs-color-2.4.1.tgz",
"integrity": "sha512-haqOg1+Yebys/Ts/9bLo/BqUcONQOdr/hoEr2LLTRl6C5LXctUdHxsCYfvQVg5JIxITrfCNUDr4ntqmQk9+/0w==",
"requires": {
"chartjs-color-string": "^0.6.0",
"color-convert": "^1.9.3"
}
},
"chartjs-color-string": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/chartjs-color-string/-/chartjs-color-string-0.6.0.tgz",
"integrity": "sha512-TIB5OKn1hPJvO7JcteW4WY/63v6KwEdt6udfnDE9iCAZgy+V4SrbSxoIbTw/xkUIapjEI4ExGtD0+6D3KyFd7A==",
"requires": {
"color-name": "^1.0.0"
}
},
"chartkick": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/chartkick/-/chartkick-3.2.0.tgz",
"integrity": "sha512-EkscIyDBdtUJVIuA2kIIjMq+YkNf4jDWr1fYjDUMZ9IakIJFoJ+9Hl+PW/POutElu8iYbebCEHWsrsXu09o4hw=="
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"requires": {
"color-name": "1.1.3"
},
"dependencies": {
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
}
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"moment": {
"version": "2.26.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.26.0.tgz",
"integrity": "sha512-oIixUO+OamkUkwjhAVE18rAMfRJNsNe/Stid/gwHSOfHrOtw9EhAY2AHvdKZ/k/MggcYELFCJz/Sn2pL8b8JMw=="
}
}
}

15
public/package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "public",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"chart.js": "^2.9.3",
"chartkick": "^3.2.0"
}
}

5
public/style.css Normal file
View File

@ -0,0 +1,5 @@
body {
font-family: 'Raleway', sans-serif;
width: 990px;
margin: 30px auto;
}

1
views/home.erb Normal file
View File

@ -0,0 +1 @@
<%= line_chart @data %>

18
views/layout.erb Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://www.google.com/jsapi"></script>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="node_modules/chart.js/dist/Chart.min.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400,500,600,700" rel="stylesheet">
<script src="node_modules/chart.js/dist/Chart.bundle.js"></script>
<script src="node_modules/chartkick/dist/chartkick.min.js"></script>
<title>Taxa de Velocidade</title>
</head>
<body>
<h1>Taxa de Velocidade</h1>
<%= yield %>
</body>
</html>