year_array 0.1.3 → 0.1.5
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/.gitignore +1 -0
- data/.travis.yml +3 -1
- data/Gemfile.lock +3 -1
- data/README.md +56 -4
- data/lib/year_array/version.rb +1 -1
- data/lib/year_array/yarray.rb +25 -0
- data/lib/year_array.rb +0 -2
- data/year_array.gemspec +2 -9
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c27523e5e7447a43332ad62a3517e894820d2712
|
4
|
+
data.tar.gz: 32b5b4a5adb89ada3f6887396977dfc8452db7f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b81a27c4fcb70ca838631b66db478136fae3feed76ab0bb1e6b0916d1d6ff9cb53e1a87a1289d6abd541609d291628bb3396eadd8b6e9eae6f7c2398a068d425
|
7
|
+
data.tar.gz: e822933a5c707124e1a0c0d895d8951b1e985951c018ada4ab4ae70be647d0ca5f5a788799efe0d30f31525630cb6a20c03fd36c73f695ac72850d9f811a8e78
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
year_array (0.1.
|
4
|
+
year_array (0.1.4)
|
5
5
|
activesupport (~> 4.2)
|
6
6
|
|
7
7
|
GEM
|
@@ -46,6 +46,7 @@ GEM
|
|
46
46
|
rb-inotify (~> 0.9, >= 0.9.7)
|
47
47
|
ruby_dep (~> 1.2)
|
48
48
|
lumberjack (1.0.13)
|
49
|
+
memory_profiler (0.9.10)
|
49
50
|
method_source (0.9.0)
|
50
51
|
minitest (5.11.3)
|
51
52
|
nenv (0.3.0)
|
@@ -94,6 +95,7 @@ DEPENDENCIES
|
|
94
95
|
bundler (~> 1.16)
|
95
96
|
coveralls (~> 0.8)
|
96
97
|
guard-rspec (~> 4.7)
|
98
|
+
memory_profiler (~> 0.9)
|
97
99
|
rake (~> 10.0)
|
98
100
|
rspec (~> 3.0)
|
99
101
|
year_array!
|
data/README.md
CHANGED
@@ -4,9 +4,7 @@
|
|
4
4
|
[](https://coveralls.io/github/iwan/year_array?branch=master)
|
5
5
|
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
TODO: Delete this and the text above, and describe your gem
|
7
|
+
It's basically a wrapper to an array in order to manage, do some calculation and check on 8760 (or 8784) hourly values related to a year.
|
10
8
|
|
11
9
|
## Installation
|
12
10
|
|
@@ -26,7 +24,61 @@ Or install it yourself as:
|
|
26
24
|
|
27
25
|
## Usage
|
28
26
|
|
29
|
-
|
27
|
+
### Initialize
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
arr = Yarray.new(2018)
|
31
|
+
arr.to_s => "start_time: 2018-01-01 00:00:00 +0100, arr: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ..., 0.0]"
|
32
|
+
```
|
33
|
+
will initialize the array to zero.
|
34
|
+
|
35
|
+
Otherwise pass the init value:
|
36
|
+
```ruby
|
37
|
+
arr = Yarray.new(2018, value: 1.0)
|
38
|
+
arr.to_s => "start_time: 2018-01-01 00:00:00 +0100, arr: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ..., 0.0]"
|
39
|
+
```
|
40
|
+
You can also pass an init array:
|
41
|
+
```ruby
|
42
|
+
arr = Yarray.new(2018, arr: [0.0, 1.0, 2, 3])
|
43
|
+
arr.to_s => "start_time: 2018-01-01 00:00:00 +0100, arr: [0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, ..., 0.0]"
|
44
|
+
```
|
45
|
+
The array will be truncated or filled with zero values in order to reach the correct number of hours in year.
|
46
|
+
|
47
|
+
### Functions
|
48
|
+
```ruby
|
49
|
+
ya1 = Yarray.new(2018, value: 1.0)
|
50
|
+
ya2 = Yarray.new(2018, value: 2.0)
|
51
|
+
|
52
|
+
ya1.size # => 8760
|
53
|
+
ya1.year # => 2018
|
54
|
+
|
55
|
+
# Operations on each element of array
|
56
|
+
|
57
|
+
# The result will be stored in a new yarray object (more memory expensive):
|
58
|
+
ya1 + ya2
|
59
|
+
ya1 - ya2
|
60
|
+
ya1 * ya2
|
61
|
+
ya1 / ya2
|
62
|
+
|
63
|
+
# The operation will be computed in the caller ya1:
|
64
|
+
ya1.add(ya2)
|
65
|
+
ya1.subtract(ya2)
|
66
|
+
ya1.multiply(ya2)
|
67
|
+
ya1.divide(ya2)
|
68
|
+
|
69
|
+
|
70
|
+
Yarray.min(ya1, ya2) # return a Yarray object where each value is the minimum between value of ya1 and ya2
|
71
|
+
Yarray.max(ya1, ya2) # return a Yarray object where each value is the maximum between value of ya1 and ya2
|
72
|
+
|
73
|
+
ya1.any_positive?
|
74
|
+
ya1.any_negative?
|
75
|
+
|
76
|
+
ya1.any do |v|
|
77
|
+
v > 100
|
78
|
+
end
|
79
|
+
|
80
|
+
```
|
81
|
+
|
30
82
|
|
31
83
|
## Development
|
32
84
|
|
data/lib/year_array/version.rb
CHANGED
data/lib/year_array/yarray.rb
CHANGED
@@ -19,6 +19,31 @@ module YearArray
|
|
19
19
|
@start_time.year
|
20
20
|
end
|
21
21
|
|
22
|
+
def add(other)
|
23
|
+
raise_error_on_misalignment other
|
24
|
+
@arr.each_with_index{|v, i| @arr[i]=v+other.arr[i]}
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def subtract(other)
|
29
|
+
raise_error_on_misalignment other
|
30
|
+
@arr.each_with_index{|v, i| @arr[i]=v-other.arr[i]}
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def multiply(other)
|
35
|
+
raise_error_on_misalignment other
|
36
|
+
@arr.each_with_index{|v, i| @arr[i]=v*other.arr[i]}
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def divide(other)
|
41
|
+
raise_error_on_misalignment other
|
42
|
+
@arr.each_with_index{|v, i| @arr[i]=v/other.arr[i]}
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
|
22
47
|
def +(other)
|
23
48
|
raise_error_on_misalignment other
|
24
49
|
a = Arr.new(size){ |i| arr[i]+other.arr[i] }
|
data/lib/year_array.rb
CHANGED
@@ -3,12 +3,10 @@ require 'active_support/core_ext/time/calculations'
|
|
3
3
|
require 'active_support/core_ext/numeric/time'
|
4
4
|
require 'active_support/core_ext/hash'
|
5
5
|
|
6
|
-
|
7
6
|
require "year_array/version"
|
8
7
|
require "year_array/exceptions"
|
9
8
|
require "year_array/arr"
|
10
9
|
require "year_array/time_helpers"
|
11
10
|
require "year_array/yarray"
|
12
11
|
|
13
|
-
|
14
12
|
include YearArray
|
data/year_array.gemspec
CHANGED
@@ -9,19 +9,11 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Iwan Buetti"]
|
10
10
|
spec.email = ["iwan.buetti@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = "Just
|
12
|
+
spec.summary = "Just an array wrapper to manage 8760 (or 8784) hourly values related to a year"
|
13
13
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
14
|
spec.homepage = "https://github.com/iwan/year_array"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
-
# "public gem pushes."
|
24
|
-
# end
|
25
17
|
|
26
18
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
19
|
f.match(%r{^(test|spec|features)/})
|
@@ -36,4 +28,5 @@ Gem::Specification.new do |spec|
|
|
36
28
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
37
29
|
spec.add_dependency "activesupport", "~> 4.2"
|
38
30
|
spec.add_development_dependency 'coveralls', "~> 0.8"
|
31
|
+
spec.add_development_dependency 'memory_profiler', "~> 0.9"
|
39
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: year_array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iwan Buetti
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: memory_profiler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
97
111
|
description:
|
98
112
|
email:
|
99
113
|
- iwan.buetti@gmail.com
|
@@ -145,5 +159,6 @@ rubyforge_project:
|
|
145
159
|
rubygems_version: 2.5.2.3
|
146
160
|
signing_key:
|
147
161
|
specification_version: 4
|
148
|
-
summary: Just
|
162
|
+
summary: Just an array wrapper to manage 8760 (or 8784) hourly values related to a
|
163
|
+
year
|
149
164
|
test_files: []
|