commit a1ade51f6b7f2f4930b2b1b770c4786628f34b4b Author: Luiz Picolo Date: Tue Jun 2 23:02:01 2020 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94a4c73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +db/development.sqlite3 +db/test.sqlite3 +public/node_modules \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..8630463 --- /dev/null +++ b/Gemfile @@ -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' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..9fe2291 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..5bea21d --- /dev/null +++ b/Rakefile @@ -0,0 +1,3 @@ +require 'sinatra/activerecord' +require 'sinatra/activerecord/rake' +require './app' \ No newline at end of file diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..eb757f4 --- /dev/null +++ b/app.rb @@ -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 \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..b2c07e2 --- /dev/null +++ b/config/database.yml @@ -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 \ No newline at end of file diff --git a/db/migrate/20200529011930_create_rate_table.rb b/db/migrate/20200529011930_create_rate_table.rb new file mode 100644 index 0000000..9ce9d08 --- /dev/null +++ b/db/migrate/20200529011930_create_rate_table.rb @@ -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 \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..ead45f8 --- /dev/null +++ b/db/schema.rb @@ -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 diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..294ebc2 --- /dev/null +++ b/init.rb @@ -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, +}) + + diff --git a/models/rate.rb b/models/rate.rb new file mode 100644 index 0000000..b08d993 --- /dev/null +++ b/models/rate.rb @@ -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 \ No newline at end of file diff --git a/public/package-lock.json b/public/package-lock.json new file mode 100644 index 0000000..c18082e --- /dev/null +++ b/public/package-lock.json @@ -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==" + } + } +} diff --git a/public/package.json b/public/package.json new file mode 100644 index 0000000..4c56a89 --- /dev/null +++ b/public/package.json @@ -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" + } +} diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000..ac713c9 --- /dev/null +++ b/public/style.css @@ -0,0 +1,5 @@ +body { + font-family: 'Raleway', sans-serif; + width: 990px; + margin: 30px auto; +} \ No newline at end of file diff --git a/views/home.erb b/views/home.erb new file mode 100644 index 0000000..19f6fa9 --- /dev/null +++ b/views/home.erb @@ -0,0 +1 @@ +<%= line_chart @data %> \ No newline at end of file diff --git a/views/layout.erb b/views/layout.erb new file mode 100644 index 0000000..e875e7e --- /dev/null +++ b/views/layout.erb @@ -0,0 +1,18 @@ + + + + + + + + + + + + Taxa de Velocidade + + +

Taxa de Velocidade

+ <%= yield %> + + \ No newline at end of file