simple_time_series 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5f5ca203967d4af50f16d5afa45797faf88de47
4
- data.tar.gz: 1d6b4d7b3446fd5141150054fd9bd65fb8840980
3
+ metadata.gz: 0b73fd7c9b64515cb0d5c39ec11df549bd0f1ae4
4
+ data.tar.gz: 36f02c014942abfc3b83dbd766b1410df5952871
5
5
  SHA512:
6
- metadata.gz: f3472c7f10c78314440774986600b67b1a00d1827abd68afae448602d1b3aec6249fbb87851f0651e2d3e2232effb6bc0e057a2da3fb044469bf531e8e4db2a5
7
- data.tar.gz: c6cedd819610bcb1366e747afa536f8baea398493b5b94db1f707f5e76c040f59570163c1de75175d1b7d3e96957d01dde86d956fd32dc321a9610cad835bc00
6
+ metadata.gz: 8e71952e875add4b1f8a6801a1f16e6e460b1ba71c0ec61d4101c50835599aaf898a0f617f2962a8352b4febbccfa3cb0012620a241d0fdb0531716f0ddae0f4
7
+ data.tar.gz: 3a781828fcffcca857d2139ec7719961e7678c06415f564457bfa1a29dc910baafdcafe1b863243bf7ddbcdd160c047645bb392753b0f7a9f3c4513643bb8496
data/README.md CHANGED
@@ -64,6 +64,15 @@ You can get the same values by calling SimpleTimeSeries#find with two arguments,
64
64
  puts "Tasks done on Wednesday: #{my_data.find('tasks_done', 'Wednesday')}" # prints 14
65
65
  puts "Tasks done on 2014-01-05: #{my_data.find('tasks_done', '2014-01-05')}" # prints 3
66
66
 
67
+ You can also get ranges of values using SimpleTimeSeries#find with three arguments: 1) data_var name; 2) start time_var value; and, 3) end time_var value:
68
+
69
+ my_data.find('pizzas', 'Tuesday', 'Thursday') # returns [1, 0, 0.5]
70
+ my_data.find('pizzas', 'Thursday', '2014-01-07') # returns [0.5, 0, 2]
71
+ my_data.find('miles', 'Saturday', '2014-01-07') # returns 2.3 (a value, not an array, because the start/end dates are the same)
72
+ my_data.find('miles', 'Sunday', '2014-01-07') # returns [2.2, 3.1, 0.0, 4.3, 1.2, 12.2, 2.3]
73
+ my_data.find('miles', 'Jan 2, 2014','2014-01-06') # returns [3.1, 0.0, 4.3, 1.2, 12.2]
74
+ my_data.find('tasks_done', '2014-01-02', 'Friday') # returns [3, 0, 14, 3, 11]
75
+
67
76
  You can view all the values associated with any variable:
68
77
 
69
78
  my_data.miles # prints [2.2, 3.1, 0.0, 4.3, 1.2, 12.2, 2.3]
@@ -206,9 +215,8 @@ This began as a simple code example for a collague who had programmed something
206
215
 
207
216
  ## Todo
208
217
 
209
- 1. Enable cumulative sum on any data_var
210
- 2. Enable range extraction via data_var[start_time, end_time]. This currently works as data_var_subset(start_time, end_time).
211
- 3. Enable setting values for a range via data_var[start_time, end_time]=
218
+ 1. Enable range extraction via data_var[start_time, end_time]. This currently works as data_var_subset(start_time, end_time) and data_var_diff(), data_var_cumsum(), etc. but would be nice to grab subsets using array ranges.
219
+ 2. Enable setting values for a range via data_var[start_time, end_time]=. You can do this with data_var_subset_set(start_time, end_time), but it would be nice to make this work using array ranges.
212
220
 
213
221
  ## Acknowledgements
214
222
 
@@ -9,8 +9,12 @@ class SimpleTimeSeries
9
9
  define_time_methods_and_set_values
10
10
  end
11
11
 
12
- def find(what, date)
13
- send (what + '_on').to_sym, date
12
+ def find(what, date, end_date=nil)
13
+ if end_date
14
+ send (what + '_on').to_sym, date, end_date
15
+ else
16
+ send (what + '_on').to_sym, date
17
+ end
14
18
  end
15
19
 
16
20
  def current(what)
@@ -74,13 +78,19 @@ class SimpleTimeSeries
74
78
  return answer.length == 1 ? answer[0] : answer
75
79
  end
76
80
  end
77
- define_method(var_on) do |date|
81
+ define_method(var_on) do |first, last=nil|
78
82
  time_vars.each do |tv_key, tv_val|
79
83
  # tv_key is something like 'dows' or 'dates'
80
84
  # tv_val is an array of associated values
81
- return eval(var)[tv_val.index(date)] if tv_val.include?(date)
85
+ start_idx = index_of_date_value(first) || 0
86
+ last_idx = index_of_date_value(last) || (first.nil? ? -1 : start_idx)
87
+ if start_idx != last_idx #&& tv_val.include?(last)
88
+ return eval(var)[start_idx..last_idx]
89
+ elsif tv_val.include?(first)
90
+ return eval(var)[start_idx]
91
+ end
82
92
  end
83
- raise "Can't find #{var_on} for #{date}"
93
+ raise "Can't find #{var_on} for #{first}"
84
94
  end
85
95
  end
86
96
  instance_variable_set("@#{var}", vals) if vals
@@ -1,3 +1,3 @@
1
1
  class SimpleTimeSeries
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -48,6 +48,15 @@ describe SimpleTimeSeries do
48
48
  @my_data.find('tasks_done', '2014-01-02').should == 3
49
49
  end
50
50
 
51
+ it "creates a #find method for finding any data values for a range of observations" do
52
+ @my_data.find('pizzas', 'Tuesday', 'Thursday').should == [1, 0, 0.5]
53
+ @my_data.find('pizzas', 'Thursday', '2014-01-07').should == [0.5, 0, 2]
54
+ @my_data.find('miles', 'Saturday', '2014-01-07').should == 2.3
55
+ @my_data.find('miles', 'Sunday', '2014-01-07').should == [2.2, 3.1, 0.0, 4.3, 1.2, 12.2, 2.3]
56
+ @my_data.find('miles', 'Jan 2, 2014','2014-01-06').should == [3.1, 0.0, 4.3, 1.2, 12.2]
57
+ @my_data.find('tasks_done', '2014-01-02', 'Friday').should == [3, 0, 14, 3, 11]
58
+ end
59
+
51
60
  it "creates setter methods for updating a data series" do
52
61
  @my_data.pizzas_on('Tuesday').should == 1
53
62
  @my_data.pizzas = [10, 11, 12, 13, 14, 15, 16]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_time_series
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Lavin