aurora_file_processor 0.1.0
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 +7 -0
- data/bin/aurora_file_processor +5 -0
- data/lib/aurora_file_processor.rb +211 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6dc40acd65096580852f989a41645d63809be35b
|
4
|
+
data.tar.gz: 7f1df16f5abdf45fc01b73799d62c3045b49faec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc4f7df7d9f168c929b22260f5982cf17cc5c2a96e0baa83959e226b1148ef960b78cd42f7faadab7cce75fce694bfe345c667628f2e95dc81ca633646e09bfb
|
7
|
+
data.tar.gz: 5b9383fdbb69e64299148a04f5d1ecaf53a7127b5cbcd4f5a0ad6240f4cb675ab2011fa5b3894d18747079d86f48702aa3509450085de9398cd1bb3fd1b06bd6
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# A module to store constants relating to electrical production and CO2 emission analysis
|
2
|
+
module Constants
|
3
|
+
# g CO2 emitted per kWh produced. (Source: carbonfund.org (ca. 2012))
|
4
|
+
CO2_USGRID = 592.5
|
5
|
+
# TWh energy, US eletrical grid, 2012 (Source: Wiki)
|
6
|
+
ENERGY_USGRID = 4143
|
7
|
+
# A hash that stores 6 common types of renewable energy generation as the keys and service lifecycle carbon emissions
|
8
|
+
# per kWh generated as the values (source: Wiki)
|
9
|
+
ENERGY_TYPES = {
|
10
|
+
PV_Solar: 46,
|
11
|
+
Thermal_Solar: 22,
|
12
|
+
Onshore_Wind: 12,
|
13
|
+
Geothermal: 45,
|
14
|
+
Hydroelectric: 4,
|
15
|
+
Biomass: 18,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
# String class: adds two methods
|
20
|
+
#
|
21
|
+
# Author: Renee Hendrickson
|
22
|
+
# Credit: thanksgiving_dinner.rb answer key
|
23
|
+
#
|
24
|
+
class String
|
25
|
+
# A method that upcases the first letter of each word
|
26
|
+
def titlecase
|
27
|
+
self.gsub(/\b\w/){|f| f.upcase}
|
28
|
+
end
|
29
|
+
|
30
|
+
# A method to replace underscores in variable names with spaces for human reading
|
31
|
+
def humanize
|
32
|
+
self.gsub('_',' ').titlecase
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# This class processes energy and power files unique to the Aurora Power-One inverter.
|
37
|
+
#
|
38
|
+
# Author: Chris Ashfield
|
39
|
+
# License: MIT
|
40
|
+
#
|
41
|
+
# More info about the Aurora device can be found here:
|
42
|
+
# http://www.power-one.com/renewable-energy/products/solar/string-inverters/aurora-uno-single-phase/pvi-30363842-north-america/series
|
43
|
+
#
|
44
|
+
class AuroraFileProcessor
|
45
|
+
include Constants
|
46
|
+
|
47
|
+
# Total energy output in Wh
|
48
|
+
attr_reader :energy_amount
|
49
|
+
# Total inverter operating time represented by file
|
50
|
+
attr_reader :energy_run_time
|
51
|
+
# an array containing both files inputted on the command line
|
52
|
+
attr_reader :filename
|
53
|
+
# Maximum power (in W) recorded in the power file
|
54
|
+
attr_reader :max_power
|
55
|
+
# Minimum power (in W) recorded in the power file
|
56
|
+
attr_reader :min_power
|
57
|
+
# Average power (W) calculated by dividing energy by runtime (energy file used only)
|
58
|
+
attr_reader :ave_power
|
59
|
+
# The differential carbon impact of utilizing a renewable energy system versus the
|
60
|
+
# average of the entire US electrical grid
|
61
|
+
attr_reader :carbon_savings
|
62
|
+
# The specific type of renewable energy system. Defaults to PV Solar.
|
63
|
+
attr_reader :system_type
|
64
|
+
|
65
|
+
# The initialization method takes two arguments that were entered on the command line.
|
66
|
+
# There must be exactly one energy file and one power file. They can be named anything
|
67
|
+
# (note: without spaces) and be entered in any order.
|
68
|
+
#
|
69
|
+
# === Attributes
|
70
|
+
#
|
71
|
+
# * +filename1+ The first file read from the command line arguments
|
72
|
+
# * +filename2+ The second file read from the command line arguments
|
73
|
+
#
|
74
|
+
def initialize filename1, filename2
|
75
|
+
@filename = [filename1, filename2]
|
76
|
+
# boolean vasriables to help track which file is read first
|
77
|
+
@parsed_energy = false
|
78
|
+
@parsed_power = false
|
79
|
+
# keeps track of the number of files read in
|
80
|
+
@file_count = 0
|
81
|
+
end
|
82
|
+
|
83
|
+
# A helper method to read in the file and map it to an array of strings
|
84
|
+
#
|
85
|
+
def read_file
|
86
|
+
@readin = []
|
87
|
+
file = File.open(@filename[@file_count], 'r')
|
88
|
+
@readin = file.each.to_a
|
89
|
+
# chop off the escaped characters (in this case: \r\n)
|
90
|
+
@readin.map! {|s| s.chomp}
|
91
|
+
# increment the file count
|
92
|
+
@file_count += 1
|
93
|
+
file.close
|
94
|
+
# determine which file was read in
|
95
|
+
# the files either have a "W" (for power) or "Wh" as the first line
|
96
|
+
if @readin[0] =~ /Wh/
|
97
|
+
parse_energy
|
98
|
+
else @readin[0] =~ /W/
|
99
|
+
parse_power
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# A helper method to map the values (now in an array from either file type) to a hash
|
104
|
+
#
|
105
|
+
def parse_hash
|
106
|
+
hash = {}
|
107
|
+
# Remove the first five lines of the file
|
108
|
+
temp_array = @readin[5, @readin.length]
|
109
|
+
# Split the input at the semicolon: the left hand side is a timestamp and the right hand side
|
110
|
+
# is the value (either power in W, or energy in Wh depending on the file type).
|
111
|
+
# This is committed to a hash with time as the key and the W/Wh as the value.
|
112
|
+
temp_array.each do |s|
|
113
|
+
k,v = s.split(/;/)
|
114
|
+
# the Aurora reports time as seconds since 1/1/0000 and Ruby reports time utilizing an epoch
|
115
|
+
# that began on 1/1/1970. The time stamp is adjusted for the time in seconds between these
|
116
|
+
# two dates.
|
117
|
+
hash[Time.at(k.to_i - 62167104000)] = v.to_f
|
118
|
+
end
|
119
|
+
return hash
|
120
|
+
end
|
121
|
+
|
122
|
+
# A method to parse the data originally from the energy file and calculate the amount of time
|
123
|
+
# that past respresented by the data and total energy outputted (and assign them to variables)
|
124
|
+
#
|
125
|
+
def parse_energy
|
126
|
+
energy_hash = parse_hash
|
127
|
+
# total energy produced
|
128
|
+
temp_array = []
|
129
|
+
temp_array = energy_hash.to_a
|
130
|
+
# runtime in hours
|
131
|
+
@energy_run_time = (temp_array[temp_array.length - 1][0] - temp_array[0][0])/3600.0
|
132
|
+
# energy in Wh
|
133
|
+
@energy_amount = (temp_array[temp_array.length - 1][1] - temp_array[0][1])
|
134
|
+
|
135
|
+
# if the program parsed energy before power, do power now
|
136
|
+
@parsed_energy = true
|
137
|
+
read_file unless @parsed_power
|
138
|
+
output_report
|
139
|
+
end
|
140
|
+
|
141
|
+
# A method to parse the data originally from the power file and find the maximum power
|
142
|
+
# reading, minimum power reading, and assign them to class variables
|
143
|
+
#
|
144
|
+
def parse_power
|
145
|
+
power_hash = parse_hash
|
146
|
+
@max_power = power_hash.values.max
|
147
|
+
@min_power = power_hash.values.min
|
148
|
+
@parsed_power = true
|
149
|
+
read_file unless @parsed_energy
|
150
|
+
end
|
151
|
+
|
152
|
+
# A method to output a human readable report summarizing the data captured in the energy and power files.
|
153
|
+
#
|
154
|
+
# This method is called after the energy and power files have been parsed and the desired values
|
155
|
+
# calculated and comitted to variables.
|
156
|
+
#
|
157
|
+
def output_report
|
158
|
+
# Have user indicate the type of renewable energy system that generated the file
|
159
|
+
# The Aurora is type-agnostic: it only reports power and energy regardless of the type.
|
160
|
+
#
|
161
|
+
puts "Enter the number for the type of renewable production system?\n"
|
162
|
+
puts "1.\tPV Solar\n"
|
163
|
+
puts "2.\tThermal Solar\n"
|
164
|
+
puts "3.\tOnshore Wind\n"
|
165
|
+
puts "4.\tGeothermal\n"
|
166
|
+
puts "5.\tHydroelectric\n"
|
167
|
+
puts "6.\tBiomass\n"
|
168
|
+
print "Your Choice: "
|
169
|
+
warning = ""
|
170
|
+
input = STDIN.gets.chomp
|
171
|
+
case input.to_i
|
172
|
+
when 1
|
173
|
+
@system_type = :PV_Solar
|
174
|
+
when 2
|
175
|
+
@system_type = :Thermal_Solar
|
176
|
+
when 3
|
177
|
+
@system_type = :Onshore_Wind
|
178
|
+
when 4
|
179
|
+
@system_type = :Geothermal
|
180
|
+
when 5
|
181
|
+
@system_type = :Hydroelectric
|
182
|
+
when 6
|
183
|
+
@system_type = :Biomass
|
184
|
+
else
|
185
|
+
warning = "Invalid energy type give. Default is "
|
186
|
+
@system_type = :PV_Solar
|
187
|
+
end
|
188
|
+
@carbon_savings = (@energy_amount / 1000.0) * (CO2_USGRID - ENERGY_TYPES[@system_type])
|
189
|
+
@ave_power = (@energy_amount / @energy_run_time).round(2)
|
190
|
+
# Write a new output file. Note that this overwrites any existing file.
|
191
|
+
output_file = File.open("Energy Report", 'w+')
|
192
|
+
output_file.write("ENERGY REPORT\n")
|
193
|
+
output_file.write("Energy System Type: #{warning} #{@system_type.to_s.humanize}\n\n")
|
194
|
+
output_file.write("Total Operating Time: #{@energy_run_time} hours\n")
|
195
|
+
output_file.write("Total Energy Produced: #{@energy_amount} Wh\n")
|
196
|
+
output_file.write("Your Power Range was #{@min_power} to #{@max_power} W.\n")
|
197
|
+
output_file.write("Your Average Power was: #{@ave_power} W\n\n")
|
198
|
+
output_file.write("Carbon Productivity-Sequestration:\n")
|
199
|
+
output_file.write("#{@system_type.to_s.humanize} Rating: #{ENERGY_TYPES[@system_type]} g CO2 per kWh\n")
|
200
|
+
output_file.write("US Average: #{CO2_USGRID} g CO2 per kWh\n")
|
201
|
+
output_file.write("Your energy production resulted in #{@carbon_savings.to_i} g net " \
|
202
|
+
"CO2 Productivity-Sequestration\n")
|
203
|
+
output_file.close
|
204
|
+
if File.exists?("Energy Report")
|
205
|
+
puts "Report generated successfully!"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aurora_file_processor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Ashfield
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: The gem takes exactly one energy file and one power file generated by
|
14
|
+
the inverter. The two filenames are enter on the command line without spaces (no
|
15
|
+
order necessary)
|
16
|
+
email: biodieselchris@gmail.com
|
17
|
+
executables:
|
18
|
+
- aurora_file_processor
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/aurora_file_processor.rb
|
23
|
+
- bin/aurora_file_processor
|
24
|
+
homepage: http://rubygems.org/gems/aurora_file_processor
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.1.9
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: A gem to process energy and power files outputted by the Aurora Power-One
|
48
|
+
inverter
|
49
|
+
test_files: []
|