time_math2 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -75
- data/lib/time_math/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76771d4aa5435a2100af858a4bd4851ef81d35c9
|
4
|
+
data.tar.gz: 23abf05b1c0b3dd19a6552619cda98e360b73840
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a314061838072dac1c4bec199a7a1128f74732a3a0cc041996674e1b6d91a35b53cdd7f7800a9b187108afd73d03027e4e6776c9c5b53f3393df06b2f13d0231
|
7
|
+
data.tar.gz: 192e2f2f194d52dc4d39868ccae10d83bab53350b63177725c3677c2e607574463420d62eab0c6151741747a1a0fe44de408cc103713319d3de607907ef8bf9e
|
data/README.md
CHANGED
@@ -208,81 +208,6 @@ it means:
|
|
208
208
|
it is preserved by TimeMath (but be careful about jumping around DST,
|
209
209
|
offset would not change).
|
210
210
|
|
211
|
-
|
212
|
-
## Time series generation: "laces"
|
213
|
-
|
214
|
-
I'm a real fan of funny names in gems. Here we have time **boots** for working
|
215
|
-
with time **steps**. So, something continuous will be called **lace**.
|
216
|
-
|
217
|
-
I hope, next examples are pretty self-explanatory.
|
218
|
-
|
219
|
-
```ruby
|
220
|
-
from = Time.parse('2015-03-05 10:08')
|
221
|
-
to = Time.parse('2015-03-09 11:07')
|
222
|
-
|
223
|
-
lace = TimeBoots.month.lace(from, to)
|
224
|
-
# => #<TimeBoots::Lace(2015-03-05 10:08:00 +0200 - 2015-03-09 11:07:00 +0200)>
|
225
|
-
|
226
|
-
# or
|
227
|
-
TimeBoots.lace(:month, from, to)
|
228
|
-
# => #<TimeBoots::Lace(2015-03-05 10:08:00 +0200 - 2015-03-09 11:07:00 +0200)>
|
229
|
-
|
230
|
-
lace.pull
|
231
|
-
# => [2015-03-05 10:08:00 +0200,
|
232
|
-
# 2015-03-06 10:08:00 +0200,
|
233
|
-
# 2015-03-07 10:08:00 +0200,
|
234
|
-
# 2015-03-08 10:08:00 +0200,
|
235
|
-
# 2015-03-09 10:08:00 +0200]
|
236
|
-
```
|
237
|
-
|
238
|
-
So, we have just a series of times, each day, from `from` until `to`.
|
239
|
-
Note, there is a same time of the day (10:08), as it was in `from`.
|
240
|
-
|
241
|
-
The `pull` method has an optional argument, when it is `true`, the
|
242
|
-
method returns `floor`-ed times (e.g. midnights for daily lace):
|
243
|
-
|
244
|
-
```ruby
|
245
|
-
lace.pull(true)
|
246
|
-
# => [2015-03-05 10:08:00 +0200,
|
247
|
-
# 2015-03-06 00:00:00 +0200,
|
248
|
-
# 2015-03-07 00:00:00 +0200,
|
249
|
-
# 2015-03-08 00:00:00 +0200,
|
250
|
-
# 2015-03-09 00:00:00 +0200]
|
251
|
-
```
|
252
|
-
|
253
|
-
Note the first value still at 10:08: we don't want to go before `from`.
|
254
|
-
Lace also can "expand" your period for you (`floor` the beginning and
|
255
|
-
`ceil` the end):
|
256
|
-
|
257
|
-
```ruby
|
258
|
-
lace.expand
|
259
|
-
# => #<TimeBoots::Lace(2015-03-05 00:00:00 +0200-2015-03-10 00:00:00 +0200)>
|
260
|
-
|
261
|
-
# or
|
262
|
-
lace.expand!
|
263
|
-
|
264
|
-
# or start with expanded:
|
265
|
-
TimeBoots.month.lace(from, to, expanded: true)
|
266
|
-
```
|
267
|
-
|
268
|
-
Another useful lace's functionality is generating periods.
|
269
|
-
It can be useful for filtering daily data from database, for example:
|
270
|
-
|
271
|
-
```ruby
|
272
|
-
lace.pull_ranges
|
273
|
-
# => [2015-03-05 10:08:00 +0200...2015-03-06 10:08:00 +0200,
|
274
|
-
# 2015-03-06 10:08:00 +0200...2015-03-07 10:08:00 +0200,
|
275
|
-
# 2015-03-07 10:08:00 +0200...2015-03-08 10:08:00 +0200,
|
276
|
-
# 2015-03-08 10:08:00 +0200...2015-03-09 10:08:00 +0200,
|
277
|
-
# 2015-03-09 10:08:00 +0200...2015-03-09 11:07:00 +0200]
|
278
|
-
|
279
|
-
# Now, you can do something like:
|
280
|
-
|
281
|
-
lace.pull_ranges.map{|range| dataset.where(timestamp: range).count}
|
282
|
-
# ...and have your daily stats with one line of code
|
283
|
-
|
284
|
-
```
|
285
|
-
|
286
211
|
## Got it, what else?
|
287
212
|
|
288
213
|
TimeMath also play well when included into other classes or modules:
|
data/lib/time_math/version.rb
CHANGED