simple_time_series 0.1.2 → 0.1.3
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 +4 -4
 - data/README.md +18 -0
 - data/lib/simple_time_series/simple_time_series.rb +12 -0
 - data/lib/simple_time_series/version.rb +1 -1
 - data/spec/lib/simple_time_series_spec.rb +15 -8
 - 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: debfc06f4c0f3325f0d5d8b204b9f32fa0add2e8
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 279ca288cbe91c7a87a05e72394cb5ef5b44d29d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: bdaab97c059ad97c01a1a1ac3d4237327a45de83feeb4f3b3a34b9847867ae951c5614eeb186c0d08a72318a0cecfe99d7557562679060e617963384aa8df7b5
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 87b2262af37d5a400d57aa99d43355bbf5bdc0b299765cfe9c4e1e2f24dc2806c8989e902cffbc8ddf80be5e439625a3c630368c60978e32a0fdbc005dcaa3cb
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -201,6 +201,24 @@ It also calculates cumulative sums for any data_var: 
     | 
|
| 
       201 
201 
     | 
    
         
             
                my_data.tasks_done_cumsum('Sunday','Monday') # returns [2, 5]
         
     | 
| 
       202 
202 
     | 
    
         
             
                my_data.tasks_done_cumsum('Tuesday','Saturday') # returns [5, 19, 22, 33, 33]
         
     | 
| 
       203 
203 
     | 
    
         | 
| 
      
 204 
     | 
    
         
            +
            You can sum data_vars across time observations for all time values or a subset of time values:
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
      
 206 
     | 
    
         
            +
                  my_data.sum_by_date('pizzas','miles','tasks_done', {})
         
     | 
| 
      
 207 
     | 
    
         
            +
                    =>
         
     | 
| 
      
 208 
     | 
    
         
            +
                    [0 + 2.2 + 2, 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
                  my_data.sum_by_date('pizzas','miles','tasks_done', {:start => 'Monday', :end => 'Saturday'})
         
     | 
| 
      
 211 
     | 
    
         
            +
                    =>
         
     | 
| 
      
 212 
     | 
    
         
            +
                    [0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
         
     | 
| 
      
 213 
     | 
    
         
            +
             
     | 
| 
      
 214 
     | 
    
         
            +
                  my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-01', :end => 'Jan 7, 2014'})
         
     | 
| 
      
 215 
     | 
    
         
            +
                    =>
         
     | 
| 
      
 216 
     | 
    
         
            +
                    [0 + 2.2 + 2, 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                  my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-03', :end => 'Jan 6, 2014'})
         
     | 
| 
      
 219 
     | 
    
         
            +
                    =>
         
     | 
| 
      
 220 
     | 
    
         
            +
                    [1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11]
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
       204 
222 
     | 
    
         
             
            You can extract subsets of your data into arrays of arrays with #data_array:
         
     | 
| 
       205 
223 
     | 
    
         | 
| 
       206 
224 
     | 
    
         
             
                  my_data.data_array('tasks_done', {})
         
     | 
| 
         @@ -20,6 +20,18 @@ class SimpleTimeSeries 
     | 
|
| 
       20 
20 
     | 
    
         
             
                find(what, date, end_date).dup.unshift(what)
         
     | 
| 
       21 
21 
     | 
    
         
             
              end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
      
 23 
     | 
    
         
            +
              def sum_by_date(*data_var_names, opts)
         
     | 
| 
      
 24 
     | 
    
         
            +
                arr = []
         
     | 
| 
      
 25 
     | 
    
         
            +
                data_var_names.each do |name|
         
     | 
| 
      
 26 
     | 
    
         
            +
                  if opts[:start] && opts[:end]
         
     | 
| 
      
 27 
     | 
    
         
            +
                    arr << find(name, opts[:start], opts[:end], opts)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  else
         
     | 
| 
      
 29 
     | 
    
         
            +
                    arr << current(name, opts)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
                arr.transpose.map { |arr| arr.reduce(:+) }
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       23 
35 
     | 
    
         
             
              def data_array(*data_var_names, opts)
         
     | 
| 
       24 
36 
     | 
    
         
             
                err_msg = "The last parameter passed to #data_array must be a hash of start/end values.\n"
         
     | 
| 
       25 
37 
     | 
    
         
             
                err_msg += "Example: {:start => 'Tuesday', :end => '2014-01-06'}\n"
         
     | 
| 
         @@ -313,14 +313,21 @@ describe SimpleTimeSeries do 
     | 
|
| 
       313 
313 
     | 
    
         
             
                                       ['pizzas', 0, 1, 0, 0.5, 0, 2] ]
         
     | 
| 
       314 
314 
     | 
    
         
             
                end
         
     | 
| 
       315 
315 
     | 
    
         | 
| 
       316 
     | 
    
         
            -
                 
     | 
| 
       317 
     | 
    
         
            -
             
     | 
| 
       318 
     | 
    
         
            -
             
     | 
| 
       319 
     | 
    
         
            -
                 
     | 
| 
       320 
     | 
    
         
            -
             
     | 
| 
       321 
     | 
    
         
            -
                 
     | 
| 
       322 
     | 
    
         
            -
             
     | 
| 
       323 
     | 
    
         
            -
             
     | 
| 
      
 316 
     | 
    
         
            +
                it "sums a set of data_vars across time observations" do
         
     | 
| 
      
 317 
     | 
    
         
            +
                  @my_data.sum_by_date('pizzas','miles','tasks_done', {}).should ==
         
     | 
| 
      
 318 
     | 
    
         
            +
                    [0 + 2.2 + 2, 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
         
     | 
| 
      
 319 
     | 
    
         
            +
                end
         
     | 
| 
      
 320 
     | 
    
         
            +
             
     | 
| 
      
 321 
     | 
    
         
            +
                it "sums a set of data_vars across time observations for a subset of time values" do
         
     | 
| 
      
 322 
     | 
    
         
            +
                  @my_data.sum_by_date('pizzas','miles','tasks_done', {:start => 'Monday', :end => 'Saturday'}).should ==
         
     | 
| 
      
 323 
     | 
    
         
            +
                    [0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
         
     | 
| 
      
 324 
     | 
    
         
            +
             
     | 
| 
      
 325 
     | 
    
         
            +
                  @my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-01', :end => 'Jan 7, 2014'}).should ==
         
     | 
| 
      
 326 
     | 
    
         
            +
                    [0 + 2.2 + 2, 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
         
     | 
| 
      
 327 
     | 
    
         
            +
             
     | 
| 
      
 328 
     | 
    
         
            +
                  @my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-03', :end => 'Jan 6, 2014'}).should ==
         
     | 
| 
      
 329 
     | 
    
         
            +
                    [1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11]
         
     | 
| 
      
 330 
     | 
    
         
            +
                end
         
     | 
| 
       324 
331 
     | 
    
         | 
| 
       325 
332 
     | 
    
         
             
              end
         
     | 
| 
       326 
333 
     | 
    
         |