mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-22 02:52:49 +01:00
Sample weekly when querying over 365 days
This commit is contained in:
parent
2b658b3d13
commit
24b5435e6d
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user