poormans_trends 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/poormans_trends/application.js +92 -0
- data/app/assets/stylesheets/poormans_trends/application.scss +29 -0
- data/app/controllers/poormans_trends/application_controller.rb +4 -0
- data/app/controllers/poormans_trends/home_controller.rb +8 -0
- data/app/helpers/poormans_trends/application_helper.rb +4 -0
- data/app/helpers/poormans_trends/home_helper.rb +30 -0
- data/app/views/layouts/poormans_trends/application.html.slim +21 -0
- data/app/views/poormans_trends/home/_dashboard.html.slim +19 -0
- data/app/views/poormans_trends/home/index.html.slim +19 -0
- data/config/locales/en.yml +35 -0
- data/config/routes.rb +3 -0
- data/lib/poormans_trends/engine.rb +11 -0
- data/lib/poormans_trends/version.rb +3 -0
- data/lib/poormans_trends.rb +4 -0
- data/lib/tasks/poormans_trends_tasks.rake +4 -0
- data/test/controllers/poormans_trends/home_controller_test.rb +11 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +35 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/helpers/poormans_trends/home_helper_test.rb +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/poormans_trends_test.rb +7 -0
- data/test/test_helper.rb +17 -0
- metadata +221 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3474957efd74cc1aea640c2fada87796c2e288c
|
4
|
+
data.tar.gz: 9ef01b66d660c731a8db0dea6332b0ef17bbbfe5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9cfa08beb72252accee4baaf063bcbb7e411969afacb3d870f590a1cce8b3b38dddcda79c6d70b8e1972492466635e407656dc3eb764e3755ecc9e37a2fa27bc
|
7
|
+
data.tar.gz: 42a31614d984c236d8b2f898ab8949696a2417c6ed169222a891810b435e6de410f736955f8c202edc88d97ae38f4fce8bcc06941cfb4968388a1ff885200579
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'PoormansTrends'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,92 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require highcharts
|
15
|
+
//= require highcharts/highcharts-more
|
16
|
+
//= require_tree .
|
17
|
+
|
18
|
+
$(function() {
|
19
|
+
var chartlineWidth = 6;
|
20
|
+
$('.chart[data-chart]').each(function(index, ele) {
|
21
|
+
ele = $(ele);
|
22
|
+
ele.highcharts({
|
23
|
+
credits: { enabled: false },
|
24
|
+
chart: {
|
25
|
+
type: 'area',
|
26
|
+
height: 100,
|
27
|
+
},
|
28
|
+
tooltip: {
|
29
|
+
backgroundColor: null,
|
30
|
+
borderWidth: 0,
|
31
|
+
shadow: false,
|
32
|
+
useHTML: true,
|
33
|
+
hideDelay: 0,
|
34
|
+
padding: 0
|
35
|
+
},
|
36
|
+
title: { text: "" },
|
37
|
+
xAxis: {
|
38
|
+
type: "datetime",
|
39
|
+
labels: {
|
40
|
+
enabled: false
|
41
|
+
},
|
42
|
+
title: {
|
43
|
+
text: null
|
44
|
+
},
|
45
|
+
startOnTick: false,
|
46
|
+
endOnTick: false,
|
47
|
+
tickPositions: []
|
48
|
+
},
|
49
|
+
yAxis: {
|
50
|
+
endOnTick: false,
|
51
|
+
startOnTick: false,
|
52
|
+
labels: {
|
53
|
+
enabled: true
|
54
|
+
},
|
55
|
+
title: {
|
56
|
+
text: null
|
57
|
+
}
|
58
|
+
},
|
59
|
+
legend: {
|
60
|
+
enabled: false
|
61
|
+
},
|
62
|
+
plotOptions: {
|
63
|
+
series: {
|
64
|
+
animation: false,
|
65
|
+
lineWidth: chartlineWidth,
|
66
|
+
shadow: false,
|
67
|
+
states: {
|
68
|
+
hover: {
|
69
|
+
lineWidth: chartlineWidth
|
70
|
+
}
|
71
|
+
},
|
72
|
+
marker: {
|
73
|
+
states: {
|
74
|
+
hover: false,
|
75
|
+
hover: {
|
76
|
+
radius: chartlineWidth
|
77
|
+
}
|
78
|
+
},
|
79
|
+
radius: 1
|
80
|
+
},
|
81
|
+
fillOpacity: 0.3
|
82
|
+
},
|
83
|
+
area: {
|
84
|
+
states: {
|
85
|
+
hover: false,
|
86
|
+
}
|
87
|
+
}
|
88
|
+
},
|
89
|
+
series: ele.data('chart')
|
90
|
+
});
|
91
|
+
});
|
92
|
+
})
|
@@ -0,0 +1,29 @@
|
|
1
|
+
@import 'bootstrap-sprockets';
|
2
|
+
@import 'bootstrap';
|
3
|
+
|
4
|
+
@import 'font-awesome-sprockets';
|
5
|
+
@import 'font-awesome';
|
6
|
+
|
7
|
+
.trendarrow {
|
8
|
+
@extend .fa;
|
9
|
+
font-size: $font-size-h1;
|
10
|
+
}
|
11
|
+
|
12
|
+
.trend {
|
13
|
+
h1 { margin-top: 0; }
|
14
|
+
}
|
15
|
+
|
16
|
+
.up-trend .pct {
|
17
|
+
color: $brand-success;
|
18
|
+
.trendarrow {
|
19
|
+
@extend .fa-chevron-up;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
.down-trend .pct {
|
24
|
+
color: $brand-danger;
|
25
|
+
.trendarrow {
|
26
|
+
@extend .fa-chevron-down;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PoormansTrends
|
2
|
+
module HomeHelper
|
3
|
+
def tables_with_col(colname, conn = ActiveRecord::Base.connection)
|
4
|
+
conn.tables.select {|t| conn.columns(t).find {|x| x.name == colname } }
|
5
|
+
end
|
6
|
+
|
7
|
+
def tables_to_classes(table_names)
|
8
|
+
table_names.collect {|t|
|
9
|
+
Class.new(ActiveRecord::Base) do
|
10
|
+
self.table_name = t
|
11
|
+
end
|
12
|
+
}.sort {|a,b| b.count <=> a.count}
|
13
|
+
end
|
14
|
+
|
15
|
+
def data_for(klass, colname, start_at, end_at = 1.day.ago)
|
16
|
+
timezone_offset = nil
|
17
|
+
db = klass.where("#{colname} >= ?", start_at).group("#{colname}::date").count.inject({}) do |sum,(k,v)|
|
18
|
+
timezone_offset ||= k.to_time.beginning_of_day - Time.zone.parse(k.to_s).beginning_of_day
|
19
|
+
sum.merge(k.to_time.to_i * 1000 => v)
|
20
|
+
end
|
21
|
+
array = []
|
22
|
+
while start_at <= end_at
|
23
|
+
t = (start_at.to_i + timezone_offset.to_i) * 1000
|
24
|
+
array.push([t, db[t] || 0])
|
25
|
+
start_at += 24.hours
|
26
|
+
end
|
27
|
+
array
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
doctype 5
|
2
|
+
html lang='en'
|
3
|
+
head
|
4
|
+
meta charset='utf-8'
|
5
|
+
meta http-equiv='X-UA-Compatible' content='IE=Edge,chrome=1'
|
6
|
+
meta name='description' content=''
|
7
|
+
meta name='viewport' content='width=device-width, initial-scale=1.0'
|
8
|
+
|
9
|
+
/![if lt IE 9]
|
10
|
+
= javascript_include_tag '//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js'
|
11
|
+
= javascript_include_tag 'poormans_trends/application', 'data-turbolinks-track' => true
|
12
|
+
= stylesheet_link_tag 'poormans_trends/application', media: 'all', 'data-turbolinks-track' => true
|
13
|
+
|
14
|
+
= csrf_meta_tags
|
15
|
+
|
16
|
+
body
|
17
|
+
.content
|
18
|
+
.container
|
19
|
+
.row
|
20
|
+
.col-sm-12
|
21
|
+
= yield
|
@@ -0,0 +1,19 @@
|
|
1
|
+
- full_time = duration.ago.beginning_of_day
|
2
|
+
- half_time = (duration.seconds/2).seconds.ago.beginning_of_day
|
3
|
+
.row
|
4
|
+
- tables_to_classes(table_names).each do |klass|
|
5
|
+
- next if klass.count == 0
|
6
|
+
.col-sm-6 style="margin-bottom:3em;"
|
7
|
+
- recent_count = klass.where("#{column} >= ?", half_time).count
|
8
|
+
- older_count = klass.where("#{column} >= ? AND #{column} < ?", full_time, half_time).count
|
9
|
+
h4 style="text-align:center"= pluralize(klass.count, "Total #{klass.table_name.singularize.titleize}")
|
10
|
+
div.trend class=(recent_count > older_count ? 'up-trend' : 'down-trend')
|
11
|
+
.pct.pull-right
|
12
|
+
h1= "#{'%0.0f' % ((recent_count - older_count) / older_count.to_f * 100)}%"
|
13
|
+
.text-center from #{older_count}
|
14
|
+
.pct.pull-right
|
15
|
+
h1.trendarrow
|
16
|
+
h1
|
17
|
+
' #{number_to_human(recent_count, units: :human_unit) rescue nil}
|
18
|
+
| #{column.sub(/_at$/, '').downcase} in the last #{duration.inspect}
|
19
|
+
div.chart style="opacity: 0.5;" data-chart=[{name: "Count", color: '#a3a3a8', data: data_for(klass, column, full_time)}, {name: "Count", color: '#6499cf', data: data_for(klass, column, half_time)}].to_json
|
@@ -0,0 +1,19 @@
|
|
1
|
+
.page-header
|
2
|
+
h1 Poorman’s Trends
|
3
|
+
hr
|
4
|
+
.clearfix
|
5
|
+
.pull-left
|
6
|
+
' Over the past
|
7
|
+
= link_to "14 days", params.merge(days_ago: "14")
|
8
|
+
' ·
|
9
|
+
= link_to "30 days", params.merge(days_ago: "30")
|
10
|
+
' ·
|
11
|
+
= link_to "60 days", params.merge(days_ago: "60")
|
12
|
+
|
13
|
+
.pull-right.text-right
|
14
|
+
= link_to_unless params[:column] == "created_at", "created_at".humanize, params.merge(column: "created_at")
|
15
|
+
' ·
|
16
|
+
= link_to_unless params[:column] == "updated_at", "updated_at".humanize, params.merge(column: "updated_at")
|
17
|
+
|
18
|
+
= render 'dashboard', column: [params[:column], 'created_at'].find(&:present?), duration: [[params[:days_ago], '14'].find(&:present?).to_i, 120].min.days, table_names: tables_with_col([params[:column], 'created_at'].find(&:present?))
|
19
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
human_unit:
|
24
|
+
unit:
|
25
|
+
one: ""
|
26
|
+
other: ""
|
27
|
+
thousand:
|
28
|
+
one: "K"
|
29
|
+
other: "K"
|
30
|
+
million:
|
31
|
+
one: "MM"
|
32
|
+
other: "MM"
|
33
|
+
billion:
|
34
|
+
one: "B"
|
35
|
+
other: "B"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|