pvoutput 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8eb79d223db909c8c4ecc34f018b3a8d952b5ebb
4
- data.tar.gz: 975583f464c918aca3e9d61fe1992a3012d5e404
3
+ metadata.gz: aabffd834f87c5ca43ed5d0c04c952fe4969b99c
4
+ data.tar.gz: d52c7cb268ad9608ce3c6503dd2e3b5cb38ff244
5
5
  SHA512:
6
- metadata.gz: db4f626c4f3851d09020c247beccd74e634d0b77a9ebb4d0c3b59f740047efe26d07a9d00cfebcf8fa5995d4113ba42c5f272e4347fe408d1faab82586430127
7
- data.tar.gz: f0c80ce60a15525463babc44727a3dc2732216831787f1d3efcab134160a290ee55354a18a1fa108bb6b5536b29db8e9bf41df25d1c21e1d631cf7f4c0346b64
6
+ metadata.gz: 25b9b1b49b10ca564cb9d23233a16505a17d7703d40a01ca0c48d25f1f0cd8f5328aeff11273aa777b358d20bf453ceaf0f5b91bee36063f7ef46fb820c1d411
7
+ data.tar.gz: 0a8fa6e7d7841d52a0657489d5ac5b9aedcd4b2105201f63fd5cebef3dfcc92b8664a52b19a8cc129dcf3a7213b26754c77817dfa0eca6596d6987289e814a33
data/.rubocop.yml CHANGED
@@ -9,9 +9,12 @@ Style/Documentation:
9
9
  Style/Lambda:
10
10
  Enabled: false
11
11
 
12
- Style/TrailingComma:
12
+ Style/TrailingCommaInLiteral:
13
13
  EnforcedStyleForMultiline: comma
14
14
 
15
+ Metrics/MethodLength:
16
+ Max: 20
17
+
15
18
  Metrics/LineLength:
16
19
  Max: 120
17
20
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ # 0.3.0 (20160229)
4
+
5
+ * Add donation mode (@jwillemsen)
6
+ * Add batch_output support (@jwillemsen)
7
+
3
8
  # 0.2.0 (20160227)
4
9
 
5
10
  * Fix typo in temperature (@jwillemsen)
data/README.md CHANGED
@@ -35,7 +35,13 @@ First step is to create a PVOutput client using your PVOutput assigned system_id
35
35
  pvoutput = PVOutput::Client.new(system_id, api_key)
36
36
  ```
37
37
 
38
- Now you can report your status to PVOutput using
38
+ At the moment you [donate](http://pvoutput.org/donate.jsp) to PVOutput you can enable the donation mode by creating a PVOutput client using
39
+
40
+ ```ruby
41
+ pvoutput = PVOutput::Client.new(system_id, api_key, true)
42
+ ```
43
+
44
+ Now you can report your real time status to PVOutput using
39
45
 
40
46
  ```ruby
41
47
  pvoutput.add_status(
@@ -47,7 +53,7 @@ The add_status operation accepts the following options
47
53
 
48
54
  | Option | PVOutput Parameter |
49
55
  | ---------------- | ------------------ |
50
- | energy_generated |v1 |
56
+ | energy_generated | v1 |
51
57
  | power_generated | v2 |
52
58
  | energy_consumed | v3 |
53
59
  | power_consumed | v4 |
@@ -67,6 +73,80 @@ client.add_status(
67
73
  )
68
74
  ```
69
75
 
76
+ You can report your daily output to PVOutput using
77
+
78
+ ```ruby
79
+ pvoutput.add_output(
80
+ options
81
+ )
82
+ ```
83
+
84
+ The add_output operation accepts the following options
85
+
86
+ | Option | PVOutput Parameter |
87
+ | --------------------- | ------------------ |
88
+ | output_date | d |
89
+ | energy_generated | g |
90
+ | peak_power | pp |
91
+ | peak_time | pt |
92
+ | condition | cd |
93
+ | min_temp | tm |
94
+ | max_temp | tx |
95
+ | comments | cm |
96
+ | import_peak | ip |
97
+ | import_off_peak | io |
98
+ | import_shoulder | is |
99
+ | import_high_shoulder | ih |
100
+ | consumption | c |
101
+
102
+ As example
103
+
104
+ ```ruby
105
+ client.add_output(
106
+ :output_date => '20160228'
107
+ :energy_generated => 15000,
108
+ :max_temp => 30
109
+ )
110
+ ```
111
+
112
+ You can report also a batch of daily output values to PVOutput using
113
+
114
+ ```ruby
115
+ pvoutput.add_batch_output(
116
+ options
117
+ )
118
+ ```
119
+
120
+ The add_batch_output operation accepts a hash with the date as key and within that the following options
121
+
122
+ | Option | PVOutput Parameter |
123
+ | --------------------- | ------------------ |
124
+ | energy_generated | g |
125
+ | peak_power | pp |
126
+ | peak_time | pt |
127
+ | condition | cd |
128
+ | min_temp | tm |
129
+ | max_temp | tx |
130
+ | comments | cm |
131
+ | import_peak | ip |
132
+ | import_off_peak | io |
133
+ | import_shoulder | is |
134
+ | import_high_shoulder | ih |
135
+ | consumption | c |
136
+
137
+ As example
138
+
139
+ ```ruby
140
+ client.add_output(
141
+ :'20150101' => {
142
+ :energy_generated => 1239, },
143
+ :'20150102' => {
144
+ :energy_generated => 1523 },
145
+ :'20150103' => {
146
+ :energy_generated => 2190 },
147
+ )
148
+ ```
149
+
70
150
  ## Development
71
151
 
72
152
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -6,14 +6,18 @@ module PVOutput
6
6
  base_uri 'pvoutput.org'
7
7
  # debug_output $stdout
8
8
 
9
- def initialize(system_id, api_key)
9
+ def initialize(system_id, api_key, donation_mode = false)
10
10
  @system_id = system_id.to_s
11
11
  @api_key = api_key.to_s
12
+ # The batch operations have default limit of 30 sets of data in one request, when you
13
+ # are using the donation mode the limit is 100 sets
14
+ @batch_size = 30
15
+ @batch_size = 100 if donation_mode
12
16
 
13
17
  self.class.headers 'X-Pvoutput-Apikey' => @api_key, 'X-Pvoutput-SystemId' => @system_id
14
18
  end
15
19
 
16
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
20
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
17
21
  def add_status(options)
18
22
  time = options[:when] || Time.now
19
23
 
@@ -33,11 +37,11 @@ module PVOutput
33
37
 
34
38
  response = self.class.post('/service/r2/addstatus.jsp', :body => params)
35
39
 
36
- fail('Bad Post') unless response.code == 200
40
+ raise('Bad Post') unless response.code == 200
37
41
  end
38
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
42
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
39
43
 
40
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
44
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
41
45
  def add_output(options)
42
46
  params = {
43
47
  }
@@ -50,11 +54,41 @@ module PVOutput
50
54
  params[:tm] = options[:min_temp] if options[:min_temp]
51
55
  params[:tx] = options[:max_temp] if options[:max_temp]
52
56
  params[:cm] = options[:comments] if options[:comments]
57
+ params[:ip] = options[:import_peak] if options[:import_peak]
58
+ params[:io] = options[:import_off_peak] if options[:import_off_peak]
59
+ params[:is] = options[:import_shoulder] if options[:import_shoulder]
60
+ params[:ih] = options[:import_high_shoulder] if options[:import_high_shoulder]
61
+ params[:c] = options[:consumption] if options[:consumption]
53
62
 
54
63
  response = self.class.post('/service/r2/addoutput.jsp', :body => params)
55
64
 
56
- fail('Bad Post') unless response.code == 200
65
+ raise('Bad Post') unless response.code == 200
57
66
  end
58
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
67
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
68
+
69
+ # rubocop:disable Metrics/AbcSize
70
+ def add_batch_output(options)
71
+ keys = %i(energy_generated energy_export energy_used)
72
+ keys += %i(peak_power peak_time condition min_temp)
73
+ keys += %i(max_temp comments import_peak import_off_peak)
74
+ keys += %i(import_shoulder)
75
+
76
+ options.to_a.each_slice(@batch_size) do |slice|
77
+ data = ''
78
+ slice.each do |entry|
79
+ date, values = entry
80
+ data += "#{date}," + keys.map { |key| values[key] }.join(',') + ';'
81
+ end
82
+
83
+ params = {
84
+ :data => data.chop,
85
+ }
86
+
87
+ response = self.class.post('/service/r2/addbatchoutput.jsp', :body => params)
88
+
89
+ raise('Bad Post') unless response.code == 200
90
+ end
91
+ end
92
+ # rubocop:enable Metrics/AbcSize
59
93
  end
60
94
  end
@@ -1,3 +1,3 @@
1
1
  module PVOutput
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pvoutput
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ferlito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-26 00:00:00.000000000 Z
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty