groupdate 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edfe1e903c4ce720f5dfe74be0088937aa52b69f82dd88732802f49764205314
4
- data.tar.gz: 85a0642b059de80a94ee621c028f117296e1baa09d93232ed6e97680b9d5fb25
3
+ metadata.gz: 624c0ae83a0c0952676b3d3efb79826b2b470d0a5efab6da31523ca8284db8f3
4
+ data.tar.gz: 6c15c17557aee5b8babd8b2939af9325449a4831ed0ee24901c27d37b7352fe3
5
5
  SHA512:
6
- metadata.gz: f2c7f1f9d5cd73b00b89005a17d62897494deb51164ccb75cbf5b6917ce389cd2847c410f271c75118c74b17677d6fabb1ef0c327063c5b7de527ad46604e66d
7
- data.tar.gz: c0a4f216150c83fa1cca7e8f10775b619da2b654b4a85e6f148bead6fe8fe82b1fd45b1741f89b7873e7c9c1ca6494f528b6cfbf41b4dda723b37c88b9d22cc2
6
+ metadata.gz: dfa2c03830675352029e74768bad800acd7ac56edc9dbcdb01f58787f34858120c4f9f1d1436ee4bdb38480922b111d746b75e3f0b7ff59f5bb770e74e01c4c9
7
+ data.tar.gz: f300e95cb3a7098486c910a4e94a8ecd4313fad14988b78fc68495783d99f49fef643f8361a4566f9ad2737238393a88c79efbc7df41cd28251d962916264626
@@ -1,3 +1,8 @@
1
+ ## 4.0.2
2
+
3
+ - Make `current` option work without `last`
4
+ - Fixed default value for `maximum`, `minimum`, and `average`
5
+
1
6
  ## 4.0.1
2
7
 
3
8
  - Fixed incorrect range with `last` option near time change
@@ -2,17 +2,15 @@
2
2
 
3
3
  First, thanks for wanting to contribute. You’re awesome! :heart:
4
4
 
5
- ## Questions
5
+ ## Help
6
6
 
7
- Use [Stack Overflow](https://stackoverflow.com/) with the tag `groupdate`.
7
+ We’re not able to provide support through GitHub Issues. If you’re looking for help with your code, try posting on [Stack Overflow](https://stackoverflow.com/).
8
8
 
9
- ## Feature Requests
9
+ All features should be documented. If you don’t see a feature in the docs, assume it doesn’t exist.
10
10
 
11
- Create an issue. Start the title with `[Idea]`.
11
+ ## Bugs
12
12
 
13
- ## Issues
14
-
15
- Think you’ve discovered an issue?
13
+ Think you’ve discovered a bug?
16
14
 
17
15
  1. Search existing issues to see if it’s been reported.
18
16
  2. Try the `master` branch to make sure it hasn’t been fixed.
@@ -26,6 +24,10 @@ If the above steps don’t help, create an issue. Include:
26
24
  - Detailed steps to reproduce
27
25
  - Complete backtraces for exceptions
28
26
 
27
+ ## New Features
28
+
29
+ If you’d like to discuss a new feature, create an issue and start the title with `[Idea]`.
30
+
29
31
  ## Pull Requests
30
32
 
31
33
  Fork the project and create a pull request. A few tips:
data/README.md CHANGED
@@ -252,7 +252,7 @@ Groupdate.time_zone = false
252
252
 
253
253
  ### 4.0
254
254
 
255
- Groupdate 4.0 brings a number of improvements. Here are a few to be aware of:
255
+ Groupdate 4.0 brings a number of improvements. Here are a few to be aware of:
256
256
 
257
257
  - `group_by` methods return an `ActiveRecord::Relation` instead of a `Groupdate::Series`
258
258
  - Invalid options now throw an `ArgumentError`
@@ -261,7 +261,7 @@ Groupdate 4.0 brings a number of improvements. Here are a few to be aware of:
261
261
 
262
262
  ### 3.0
263
263
 
264
- Groupdate 3.0 brings a number of improvements. Here are a few to be aware of:
264
+ Groupdate 3.0 brings a number of improvements. Here are a few to be aware of:
265
265
 
266
266
  - `Date` objects are now returned for day, week, month, quarter, and year by default. Use `dates: false` for the previous behavior, or change this globally with `Groupdate.dates = false`.
267
267
  - Array and hash methods no longer return the entire series by default. Use `series: true` for the previous behavior.
@@ -269,7 +269,7 @@ Groupdate 3.0 brings a number of improvements. Here are a few to be aware of:
269
269
 
270
270
  ### 2.0
271
271
 
272
- Groupdate 2.0 brings a number of improvements. Here are two things to be aware of:
272
+ Groupdate 2.0 brings a number of improvements. Here are two things to be aware of:
273
273
 
274
274
  - the entire series is returned by default
275
275
  - `ActiveSupport::TimeWithZone` keys are now returned for every database adapter - adapters previously returned `Time` or `String` keys
@@ -15,6 +15,14 @@ module Groupdate
15
15
  self.week_start = :sun
16
16
  self.day_start = 0
17
17
  self.dates = true
18
+
19
+ # api for gems like ActiveMedian
20
+ def self.process_result(relation, result, **options)
21
+ if relation.groupdate_values
22
+ result = Groupdate::Magic::Relation.process_result(relation, result, **options)
23
+ end
24
+ result
25
+ end
18
26
  end
19
27
 
20
28
  require "groupdate/enumerable"
@@ -63,7 +63,7 @@ module Groupdate
63
63
  @options = options
64
64
  end
65
65
 
66
- def perform(relation, result)
66
+ def perform(relation, result, default_value:)
67
67
  multiple_groups = relation.group_values.size > 1
68
68
 
69
69
  check_time_zone_support(result, multiple_groups)
@@ -71,7 +71,7 @@ module Groupdate
71
71
 
72
72
  series_builder.generate(
73
73
  result,
74
- default_value: options.key?(:default_value) ? options[:default_value] : 0,
74
+ default_value: options.key?(:default_value) ? options[:default_value] : default_value,
75
75
  multiple_groups: multiple_groups,
76
76
  group_index: group_index
77
77
  )
@@ -122,9 +122,10 @@ module Groupdate
122
122
  relation
123
123
  end
124
124
 
125
- def self.process_result(relation, result)
125
+ # allow any options to keep flexible for future
126
+ def self.process_result(relation, result, **options)
126
127
  relation.groupdate_values.reverse.each do |gv|
127
- result = gv.perform(relation, result)
128
+ result = gv.perform(relation, result, default_value: options[:default_value])
128
129
  end
129
130
  result
130
131
  end
@@ -9,11 +9,8 @@ module Groupdate
9
9
  end
10
10
 
11
11
  def calculate(*args, &block)
12
- if groupdate_values
13
- Groupdate::Magic::Relation.process_result(self, super)
14
- else
15
- super
16
- end
12
+ default_value = [:count, :sum].include?(args[0]) ? 0 : nil
13
+ Groupdate.process_result(self, super, default_value: default_value)
17
14
  end
18
15
  end
19
16
  end
@@ -90,7 +90,6 @@ module Groupdate
90
90
  raise ArgumentError, "Cannot use last option with #{period}"
91
91
  end
92
92
  if step
93
- now = time_zone.now
94
93
  # loop instead of multiply to change start_at - see #151
95
94
  start_at = now
96
95
  (options[:last].to_i - 1).times do
@@ -111,6 +110,10 @@ module Groupdate
111
110
 
112
111
  private
113
112
 
113
+ def now
114
+ @now ||= time_zone.now
115
+ end
116
+
114
117
  def generate_series(data, multiple_groups, group_index)
115
118
  case period
116
119
  when :day_of_week
@@ -136,7 +139,12 @@ module Groupdate
136
139
  else
137
140
  data.keys.sort
138
141
  end
139
- sorted_keys.first..sorted_keys.last
142
+
143
+ tr = sorted_keys.first..sorted_keys.last
144
+ if options[:current] == false && round_time(now) >= tr.last
145
+ tr = tr.first...round_time(now)
146
+ end
147
+ tr
140
148
  end
141
149
 
142
150
  if time_range.first
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "4.0.1"
2
+ VERSION = "4.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groupdate
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2018-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -123,22 +123,15 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  description:
126
- email:
127
- - andrew@chartkick.com
126
+ email: andrew@chartkick.com
128
127
  executables: []
129
128
  extensions: []
130
129
  extra_rdoc_files: []
131
130
  files:
132
- - ".github/ISSUE_TEMPLATE.md"
133
- - ".gitignore"
134
- - ".travis.yml"
135
131
  - CHANGELOG.md
136
132
  - CONTRIBUTING.md
137
- - Gemfile
138
133
  - LICENSE.txt
139
134
  - README.md
140
- - Rakefile
141
- - groupdate.gemspec
142
135
  - lib/groupdate.rb
143
136
  - lib/groupdate/active_record.rb
144
137
  - lib/groupdate/enumerable.rb
@@ -148,16 +141,6 @@ files:
148
141
  - lib/groupdate/relation_builder.rb
149
142
  - lib/groupdate/series_builder.rb
150
143
  - lib/groupdate/version.rb
151
- - test/enumerable_test.rb
152
- - test/gemfiles/activerecord42.gemfile
153
- - test/gemfiles/activerecord50.gemfile
154
- - test/gemfiles/activerecord51.gemfile
155
- - test/gemfiles/redshift.gemfile
156
- - test/mysql_test.rb
157
- - test/postgresql_test.rb
158
- - test/redshift_test.rb
159
- - test/sqlite_test.rb
160
- - test/test_helper.rb
161
144
  homepage: https://github.com/ankane/groupdate
162
145
  licenses:
163
146
  - MIT
@@ -170,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
153
  requirements:
171
154
  - - ">="
172
155
  - !ruby/object:Gem::Version
173
- version: 2.2.0
156
+ version: '2.2'
174
157
  required_rubygems_version: !ruby/object:Gem::Requirement
175
158
  requirements:
176
159
  - - ">="
@@ -178,18 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
161
  version: '0'
179
162
  requirements: []
180
163
  rubyforge_project:
181
- rubygems_version: 2.7.6
164
+ rubygems_version: 2.7.7
182
165
  signing_key:
183
166
  specification_version: 4
184
167
  summary: The simplest way to group temporal data
185
- test_files:
186
- - test/enumerable_test.rb
187
- - test/gemfiles/activerecord42.gemfile
188
- - test/gemfiles/activerecord50.gemfile
189
- - test/gemfiles/activerecord51.gemfile
190
- - test/gemfiles/redshift.gemfile
191
- - test/mysql_test.rb
192
- - test/postgresql_test.rb
193
- - test/redshift_test.rb
194
- - test/sqlite_test.rb
195
- - test/test_helper.rb
168
+ test_files: []
@@ -1,7 +0,0 @@
1
- Hi,
2
-
3
- Before creating an issue, please check out the Contributing Guide:
4
-
5
- https://github.com/ankane/groupdate/blob/master/CONTRIBUTING.md
6
-
7
- Thanks!
data/.gitignore DELETED
@@ -1,19 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- *.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .ruby-version
19
- .ruby-gemset
@@ -1,26 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4.2
4
- - jruby-9.1.9.0
5
- gemfile:
6
- - Gemfile
7
- - test/gemfiles/activerecord51.gemfile
8
- - test/gemfiles/activerecord50.gemfile
9
- - test/gemfiles/activerecord42.gemfile
10
- sudo: false
11
- script: bundle exec rake test
12
- before_install:
13
- - gem install bundler
14
- - mysql -e 'create database groupdate_test;'
15
- - mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
16
- - psql -c 'create database groupdate_test;' -U postgres
17
- notifications:
18
- email:
19
- on_success: never
20
- on_failure: change
21
- matrix:
22
- allow_failures:
23
- - rvm: jruby-9.1.9.0
24
- gemfile: Gemfile
25
- - rvm: jruby-9.1.9.0
26
- gemfile: test/gemfiles/activerecord51.gemfile
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in groupdate.gemspec
4
- gemspec
5
-
6
- gem "activerecord", "~> 5.2.0"
7
-
8
- if defined?(JRUBY_VERSION)
9
- gem "activerecord-jdbcpostgresql-adapter", git: "https://github.com/jruby/activerecord-jdbc-adapter.git"
10
- gem "activerecord-jdbcmysql-adapter", git: "https://github.com/jruby/activerecord-jdbc-adapter.git"
11
- gem "activerecord-jdbcsqlite3-adapter", git: "https://github.com/jruby/activerecord-jdbc-adapter.git"
12
- end
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- task default: :test
5
- Rake::TestTask.new do |t|
6
- t.libs << "test"
7
- t.test_files = FileList["test/**/*_test.rb"].exclude(/redshift/)
8
- t.warning = false
9
- end
@@ -1,38 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "groupdate/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "groupdate"
8
- spec.version = Groupdate::VERSION
9
- spec.authors = ["Andrew Kane"]
10
- spec.email = ["andrew@chartkick.com"]
11
- spec.summary = "The simplest way to group temporal data"
12
- spec.homepage = "https://github.com/ankane/groupdate"
13
- spec.license = "MIT"
14
-
15
- spec.files = `git ls-files`.split($/)
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
19
-
20
- spec.required_ruby_version = ">= 2.2.0"
21
-
22
- spec.add_dependency "activesupport", ">= 4.2"
23
-
24
- spec.add_development_dependency "bundler"
25
- spec.add_development_dependency "rake"
26
- spec.add_development_dependency "minitest"
27
- spec.add_development_dependency "activerecord"
28
-
29
- if RUBY_PLATFORM == "java"
30
- spec.add_development_dependency "activerecord-jdbcpostgresql-adapter"
31
- spec.add_development_dependency "activerecord-jdbcmysql-adapter"
32
- spec.add_development_dependency "activerecord-jdbcsqlite3-adapter"
33
- else
34
- spec.add_development_dependency "pg", "< 1"
35
- spec.add_development_dependency "mysql2", "< 0.5"
36
- spec.add_development_dependency "sqlite3"
37
- end
38
- end
@@ -1,60 +0,0 @@
1
- require_relative "test_helper"
2
- require "ostruct"
3
-
4
- class EnumerableTest < Minitest::Test
5
- include TestGroupdate
6
-
7
- def test_enumerable
8
- user_a = create_user("2014-01-21")
9
- user_b = create_user("2014-03-14")
10
- expected = {
11
- Date.parse("2014-01-01") => [user_a],
12
- Date.parse("2014-03-01") => [user_b]
13
- }
14
- assert_equal expected, [user_a, user_b].group_by_month(&:created_at)
15
- end
16
-
17
- def test_enumerable_series
18
- user_a = create_user("2014-01-21")
19
- user_b = create_user("2014-03-14")
20
- expected = {
21
- Date.parse("2014-01-01") => [user_a],
22
- Date.parse("2014-02-01") => [],
23
- Date.parse("2014-03-01") => [user_b]
24
- }
25
- assert_equal expected, [user_a, user_b].group_by_month(series: true, &:created_at)
26
- end
27
-
28
- def test_no_block
29
- assert_raises(ArgumentError) { [].group_by_day(:created_at) }
30
- end
31
-
32
- def call_method(method, field, options)
33
- Hash[@users.group_by_period(method, options) { |u| u.send(field) }.map { |k, v| [k, v.size] }]
34
- end
35
-
36
- def create_user(created_at, score = 1)
37
- user =
38
- OpenStruct.new(
39
- name: "Andrew",
40
- score: score,
41
- created_at: created_at ? utc.parse(created_at) : nil,
42
- created_on: created_at ? Date.parse(created_at) : nil
43
- )
44
- @users << user
45
- user
46
- end
47
-
48
- def setup
49
- super
50
- @users = []
51
- end
52
-
53
- def teardown
54
- # do nothing
55
- end
56
-
57
- def enumerable_test?
58
- true
59
- end
60
- end