ts 1.0.1 → 1.0.2
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/LICENSE +20 -0
- data/lib/ts.rb +13 -3
- data/test/test_ts.rb +3 -0
- data/ts.gemspec +1 -0
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ff34df04c16e070099bd33b7dc8c555e71da1ed7
         | 
| 4 | 
            +
              data.tar.gz: 490cf55edfe90f090d8f90856bce8bf73fb72620
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2a9300080f2d311dae22a4420e783747ee00b9fc4015b9b36041c314f01fff564eb4788ac0e64369b3f71880eeb4e46deae5ec59e020ed6d034b342ba4ed552e
         | 
| 7 | 
            +
              data.tar.gz: 500647b618d9cbe60051925781980f60ca7053d6683111f3a8ce19254e6bfcc77542cef265ed998f5985f15ee623b37e43757c025d61fa6f59ae692c2279e25d
         | 
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            Copyright (C) 2013 Dan Simpson
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 4 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 5 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 6 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 7 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 8 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 9 | 
            +
            the following conditions:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 12 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 15 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 16 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 17 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 18 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 19 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 20 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/lib/ts.rb
    CHANGED
    
    | @@ -6,7 +6,7 @@ | |
| 6 6 | 
             
            #
         | 
| 7 7 | 
             
            class TS
         | 
| 8 8 |  | 
| 9 | 
            -
              Version = "1.0. | 
| 9 | 
            +
              Version = "1.0.2"
         | 
| 10 10 |  | 
| 11 11 | 
             
              include Enumerable
         | 
| 12 12 |  | 
| @@ -88,6 +88,16 @@ class TS | |
| 88 88 | 
             
                }
         | 
| 89 89 | 
             
              end
         | 
| 90 90 |  | 
| 91 | 
            +
              # get the mean value
         | 
| 92 | 
            +
              def mean
         | 
| 93 | 
            +
                stats[:mean]
         | 
| 94 | 
            +
              end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
              # get the standard deviation of the values
         | 
| 97 | 
            +
              def stddev
         | 
| 98 | 
            +
                stats[:stddev]
         | 
| 99 | 
            +
              end
         | 
| 100 | 
            +
             | 
| 91 101 | 
             
              # slice a timeseries by timestamps
         | 
| 92 102 | 
             
              # +t1+ start time
         | 
| 93 103 | 
             
              # +t2+ end time
         | 
| @@ -181,7 +191,7 @@ class TS | |
| 181 191 | 
             
                  sum + (n - t_mean) ** 2
         | 
| 182 192 | 
             
                }
         | 
| 183 193 |  | 
| 184 | 
            -
                r = slope * ( | 
| 194 | 
            +
                r = slope * (_stddev(times) / _stddev(values))
         | 
| 185 195 |  | 
| 186 196 | 
             
                @regression = {
         | 
| 187 197 | 
             
                  :r2 => r * r,
         | 
| @@ -228,7 +238,7 @@ class TS | |
| 228 238 | 
             
              end
         | 
| 229 239 |  | 
| 230 240 | 
             
              # calculate the std deviation of the 1d data set
         | 
| 231 | 
            -
              def  | 
| 241 | 
            +
              def _stddev data
         | 
| 232 242 | 
             
                sum  = 0.0
         | 
| 233 243 | 
             
                sum2 = 0.0
         | 
| 234 244 | 
             
                data.each { |v|
         | 
    
        data/test/test_ts.rb
    CHANGED
    
    | @@ -25,6 +25,9 @@ class TSTest < Test::Unit::TestCase | |
| 25 25 | 
             
                assert_equal (1000 * (1000 + 1)) / 2, @ts.stats[:sum]
         | 
| 26 26 | 
             
                assert_in_delta 288, @ts.stats[:stddev], 1.0
         | 
| 27 27 | 
             
                assert_in_delta 500, @ts.stats[:mean], 1.0
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                assert_in_delta 288, @ts.stddev, 1.0
         | 
| 30 | 
            +
                assert_in_delta 500, @ts.mean, 1.0
         | 
| 28 31 | 
             
              end
         | 
| 29 32 |  | 
| 30 33 | 
             
              def test_slice
         | 
    
        data/ts.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ts
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Dan Simpson
         | 
| @@ -17,13 +17,15 @@ extensions: [] | |
| 17 17 | 
             
            extra_rdoc_files: []
         | 
| 18 18 | 
             
            files:
         | 
| 19 19 | 
             
            - .gitignore
         | 
| 20 | 
            +
            - LICENSE
         | 
| 20 21 | 
             
            - README.md
         | 
| 21 22 | 
             
            - Rakefile
         | 
| 22 23 | 
             
            - lib/ts.rb
         | 
| 23 24 | 
             
            - test/test_ts.rb
         | 
| 24 25 | 
             
            - ts.gemspec
         | 
| 25 26 | 
             
            homepage: https://github.com/dansimpson/ts.rb
         | 
| 26 | 
            -
            licenses: | 
| 27 | 
            +
            licenses:
         | 
| 28 | 
            +
            - MIT
         | 
| 27 29 | 
             
            metadata: {}
         | 
| 28 30 | 
             
            post_install_message: 
         | 
| 29 31 | 
             
            rdoc_options: []
         |