Sample weekly when querying over 365 days

This commit is contained in:
Hakan Ensari 2020-04-01 11:21:32 +01:00
parent 2b658b3d13
commit 24b5435e6d
3 changed files with 4 additions and 8 deletions

View File

@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] ## [Unreleased]
### Changed
- Sample weekly when querying over 365 days
## 1.0.0 - 2020-01-02 ## 1.0.0 - 2020-01-02
### Fixed ### Fixed

View File

@ -18,8 +18,7 @@ class Currency < Sequel::Model(Day.currencies)
def between(interval) def between(interval)
case interval.last - interval.first case interval.last - interval.first
when 0..90 then super when 0..90 then super
when 91..365 then super.sample('week') when 91.. then super.sample('week')
else super.sample('month')
end end
end end

View File

@ -21,16 +21,11 @@ describe Currency do
Currency.between(interval).map(:date).uniq.count.must_be :>, 30 Currency.between(interval).map(:date).uniq.count.must_be :>, 30
end end
it 'samples weekly over 90 but below 366 days' do it 'samples weekly over 90 days' do
interval = day..day + 365 interval = day..day + 365
Currency.between(interval).map(:date).uniq.count.must_be :<=, 52 Currency.between(interval).map(:date).uniq.count.must_be :<=, 52
end end
it 'samples monthly over 365 days' do
interval = day..day + 400
Currency.between(interval).map(:date).uniq.count.must_be :<=, 120
end
it 'sorts by date' do it 'sorts by date' do
interval = day..day + 100 interval = day..day + 100
dates = Currency.between(interval).map(:date) dates = Currency.between(interval).map(:date)