chartable 0.0.0.2 → 0.0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chartable/active_record_extension.rb +8 -2
- data/lib/chartable/queries/daily.rb +4 -12
- data/lib/chartable/queries/monthly.rb +4 -9
- data/lib/chartable/queries/quarterly.rb +4 -17
- data/lib/chartable/queries/weekly.rb +8 -6
- data/lib/chartable/queries/yearly.rb +4 -6
- data/lib/chartable/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e69c2973a90eafdeb2ff247ad5653aff3f3b7e5c6d8149d122c92c8f117fc95f
|
4
|
+
data.tar.gz: dcc4ac8c3356dbc9f31fb779445c2c532e49acac783d112ad1cb91d79b0dd158
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c974ab80c5a3c70cc15657a94e60102acb9dc4f3f438a27a7104d389ff1680596276220f406a97fa78a328f118b1e114ad48c7ad2f9bec409c8452273fbd2a2
|
7
|
+
data.tar.gz: 79c08ed35789e123fe4d908d9065eb5c9ca9a59e5cee63efdd913477bc612097b7a794cf36d1a49b0434b69ddbbbe1bb45537ced9a9984b56f5edddb74cf4153
|
@@ -9,10 +9,16 @@ module Chartable
|
|
9
9
|
# It returns analytics hash created from the given criteria
|
10
10
|
#
|
11
11
|
# @return [Hash]
|
12
|
-
def analytics(period, from: nil, to: nil, on: 'created_at')
|
12
|
+
def analytics(period, from: nil, to: nil, on: 'created_at', order: 'asc')
|
13
|
+
query_order = if order.to_s.downcase == 'desc'
|
14
|
+
'desc'
|
15
|
+
else
|
16
|
+
'asc'
|
17
|
+
end
|
18
|
+
|
13
19
|
period_query = Chartable::PeriodQuery.build(period)
|
14
20
|
scope = Chartable::RangeQuery.call(self, on: on, from: from, to: to)
|
15
|
-
period_query.call(scope, on: on)
|
21
|
+
period_query.call(scope, on: on, order: query_order)
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
@@ -5,19 +5,11 @@ module Chartable
|
|
5
5
|
# Example output: `{"October 09, 2018" => 1, "October 10, 2018" => 1}`
|
6
6
|
#
|
7
7
|
# @return [Hash]
|
8
|
-
def self.call(scope, on:)
|
9
|
-
if ActiveRecord::Base.connection.class.to_s.match(/
|
10
|
-
scope.group("
|
11
|
-
data = key.split(" ")
|
12
|
-
month_number = data.shift
|
13
|
-
month_name = Date::MONTHNAMES[month_number.to_i]
|
14
|
-
data.unshift(month_name)
|
15
|
-
data.join(" ")
|
16
|
-
end
|
17
|
-
elsif ActiveRecord::Base.connection.class.to_s.match(/postgresql/i)
|
18
|
-
scope.group("to_char(#{on},'FMMonth DD, YYYY')").size
|
8
|
+
def self.call(scope, on:, order:)
|
9
|
+
if ActiveRecord::Base.connection.class.to_s.match(/postgresql/i)
|
10
|
+
scope.group(Arel.sql("to_char(#{on},'FMMonth DD, YYYY')")).order(Arel.sql("to_char(#{on},'FMMonth DD, YYYY') #{order}")).size
|
19
11
|
else
|
20
|
-
scope.group("DATE_FORMAT(#{on}, '%M %d, %Y')").size
|
12
|
+
scope.group(Arel.sql("DATE_FORMAT(#{on}, '%M %d, %Y')")).order(Arel.sql("DATE_FORMAT(#{on}, '%M %d, %Y') #{order}")).size
|
21
13
|
end
|
22
14
|
end
|
23
15
|
end
|
@@ -6,16 +6,11 @@ module Chartable
|
|
6
6
|
# SQLite does not support DATE_FORMAT function so a little hack is needed
|
7
7
|
#
|
8
8
|
# @return [Hash]
|
9
|
-
def self.call(scope, on:)
|
10
|
-
if ActiveRecord::Base.connection.class.to_s.match(/
|
11
|
-
scope.group("
|
12
|
-
month_number = key.match(/^[0-9]{2}(?= )/).to_s
|
13
|
-
key.gsub(month_number, Date::MONTHNAMES[month_number.to_i])
|
14
|
-
end
|
15
|
-
elsif ActiveRecord::Base.connection.class.to_s.match(/postgresql/i)
|
16
|
-
scope.group("to_char(#{on},'FMMonth YYYY')").size
|
9
|
+
def self.call(scope, on:, order:)
|
10
|
+
if ActiveRecord::Base.connection.class.to_s.match(/postgresql/i)
|
11
|
+
scope.group(Arel.sql("#{on}, to_char(#{on},'FMMonth YYYY')")).order(Arel.sql("#{on} #{order}")).size
|
17
12
|
else
|
18
|
-
scope.group("DATE_FORMAT(#{on},'%M %Y')").size
|
13
|
+
scope.group(Arel.sql("#{on}, DATE_FORMAT(#{on},'%M %Y')")).order(Arel.sql("#{on} #{order}")).size
|
19
14
|
end
|
20
15
|
end
|
21
16
|
end
|
@@ -5,24 +5,11 @@ module Chartable
|
|
5
5
|
# Example output: `{"Q1 2018" => 1, "Q2 2018" => 1}`
|
6
6
|
#
|
7
7
|
# @return [Hash]
|
8
|
-
def self.call(scope, on:)
|
9
|
-
if ActiveRecord::Base.connection.class.to_s.match(/
|
10
|
-
scope.group("
|
11
|
-
month_number = key.match(/^[0-9]{2}(?= )/).to_s
|
12
|
-
quarter = case month_number.to_i
|
13
|
-
when 1..3 then 1
|
14
|
-
when 4..6 then 2
|
15
|
-
when 7..9 then 3
|
16
|
-
else
|
17
|
-
4
|
18
|
-
end
|
19
|
-
|
20
|
-
key.gsub(month_number, "Q#{quarter}")
|
21
|
-
end
|
22
|
-
elsif ActiveRecord::Base.connection.class.to_s.match(/postgresql/i)
|
23
|
-
scope.group("concat('Q', to_char(#{on},'Q YYYY'))").size
|
8
|
+
def self.call(scope, on:, order:)
|
9
|
+
if ActiveRecord::Base.connection.class.to_s.match(/postgresql/i)
|
10
|
+
scope.group(Arel.sql("concat('Q', to_char(#{on},'Q YYYY'))")).order(Arel.sql("concat('Q', to_char(#{on},'Q YYYY')) #{order}")).size
|
24
11
|
else
|
25
|
-
scope.group("CONCAT('Q', QUARTER(#{on}), DATE_FORMAT(#{on},' %Y'))").size
|
12
|
+
scope.group(Arel.sql("CONCAT('Q', QUARTER(#{on}), DATE_FORMAT(#{on},' %Y'))")).order(Arel.sql("CONCAT('Q', QUARTER(#{on}), DATE_FORMAT(#{on},' %Y')) #{order}")).size
|
26
13
|
end
|
27
14
|
end
|
28
15
|
end
|
@@ -5,13 +5,15 @@ module Chartable
|
|
5
5
|
# Example output: `{"01/28/2018 - 02/03/2018" => 1, "02/11/2018 - 02/17/2018" => 1}`
|
6
6
|
#
|
7
7
|
# @return [Hash]
|
8
|
-
def self.call(scope, on:)
|
9
|
-
if ActiveRecord::Base.connection.class.to_s.match(/
|
10
|
-
scope
|
11
|
-
|
12
|
-
|
8
|
+
def self.call(scope, on:, order:)
|
9
|
+
if ActiveRecord::Base.connection.class.to_s.match(/postgresql/i)
|
10
|
+
scope
|
11
|
+
.group(Arel.sql("concat(to_char(date_trunc('week', #{on}) + '-1 day', 'MM/DD/YYYY'), ' - ', to_char(date_trunc('week', #{on}) + '5 days', 'MM/DD/YYYY'))"))
|
12
|
+
.order(Arel.sql("concat(to_char(date_trunc('week', #{on}) + '-1 day', 'MM/DD/YYYY'), ' - ', to_char(date_trunc('week', #{on}) + '5 days', 'MM/DD/YYYY')) #{order}")).size
|
13
13
|
else
|
14
|
-
scope
|
14
|
+
scope
|
15
|
+
.group(Arel.sql("CONCAT(DATE_FORMAT(DATE(DATE_ADD(#{on}, INTERVAL(1-DAYOFWEEK(#{on})) DAY)), '%m/%d/%Y'), ' - ', DATE_FORMAT(DATE(DATE_ADD(#{on}, INTERVAL(7-DAYOFWEEK(#{on})) DAY)),'%m/%d/%Y'))"))
|
16
|
+
.order(Arel.sql("CONCAT(DATE_FORMAT(DATE(DATE_ADD(#{on}, INTERVAL(1-DAYOFWEEK(#{on})) DAY)), '%m/%d/%Y'), ' - ', DATE_FORMAT(DATE(DATE_ADD(#{on}, INTERVAL(7-DAYOFWEEK(#{on})) DAY)),'%m/%d/%Y')) #{order}")).size
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -5,13 +5,11 @@ module Chartable
|
|
5
5
|
# Example output: `{ 2017 => 1, 2018 => 1 }`
|
6
6
|
#
|
7
7
|
# @return [Hash]
|
8
|
-
def self.call(scope, on:)
|
9
|
-
if ActiveRecord::Base.connection.class.to_s.match(/
|
10
|
-
scope.group("cast(
|
11
|
-
elsif ActiveRecord::Base.connection.class.to_s.match(/postgresql/i)
|
12
|
-
scope.group("cast(to_char(#{on},'YYYY') as integer)").size
|
8
|
+
def self.call(scope, on:, order:)
|
9
|
+
if ActiveRecord::Base.connection.class.to_s.match(/postgresql/i)
|
10
|
+
scope.group(Arel.sql("cast(to_char(#{on},'YYYY') as integer)")).order(Arel.sql("cast(to_char(#{on},'YYYY') as integer) #{order}")).size
|
13
11
|
else
|
14
|
-
scope.group("YEAR(#{on})").size
|
12
|
+
scope.group(Arel.sql("YEAR(#{on})")).order(Arel.sql("YEAR(#{on}) #{order}")).size
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
data/lib/chartable/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chartable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0.
|
4
|
+
version: 0.0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paweł Dąbrowski
|
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
158
|
requirements:
|
159
159
|
- - ">="
|
160
160
|
- !ruby/object:Gem::Version
|
161
|
-
version: 2.
|
161
|
+
version: 2.1.0
|
162
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - ">="
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
168
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.7.
|
169
|
+
rubygems_version: 2.7.6
|
170
170
|
signing_key:
|
171
171
|
specification_version: 4
|
172
172
|
summary: A lightweight and database-level library to transform any Active Record query
|