solar-simulator 0.0.1 → 0.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/.gitignore +1 -0
- data/bin/solar-simulator +31 -0
- data/lib/solar/simulator/network.rb +30 -0
- data/lib/solar/simulator/panel.rb +10 -6
- data/lib/solar/simulator/version.rb +1 -1
- data/lib/solar/simulator.rb +1 -0
- data/solar-simulator.gemspec +2 -0
- data/spec/network_spec.rb +10 -0
- metadata +35 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: be355873e57e451a98ef540a0fd12196a5104678
         | 
| 4 | 
            +
              data.tar.gz: 67137cf6f8fd95ecd3294f047c405f0f1ce90d4d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e49ca52e11c7ac2ecf002bf8abbcc79cbf25dd8e2089e02bbf842a42d9522bd23611ff120c0485a37b8004806aafdac8de0664f16ffd56abbf511a07314e7d1b
         | 
| 7 | 
            +
              data.tar.gz: bbfc6f86278b30452d13640bb279aa0b23c90a1c61de6a042c0e82a4e9f577c9c2de17a25dfc62e92be4ef41a7985be8bedddf34351321892a4edbc298262922
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/bin/solar-simulator
    ADDED
    
    | @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            require 'forever'
         | 
| 3 | 
            +
            require 'slop'
         | 
| 4 | 
            +
            require 'solar/simulator'
         | 
| 5 | 
            +
            opts = nil
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Forever.run do
         | 
| 8 | 
            +
              before :all do
         | 
| 9 | 
            +
                opts = Slop.parse({help: true}) do
         | 
| 10 | 
            +
                  banner 'Usage: solar-simulator [options]'
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  on 's=', 'serial=', 'Serial number of the Panel', required: true
         | 
| 13 | 
            +
                  on 'u=', 'uri=', 'URI of collector server', required: true
         | 
| 14 | 
            +
                  on 'n', 'nominal-power', 'Nominal Power of the Panel'
         | 
| 15 | 
            +
                  on 't=', 'type=', 'Panel type 0 single phase, 1 three phase'
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
              every 15.seconds do
         | 
| 19 | 
            +
                data = Solar::Simulator::Panel.run({type: opts[:type]})
         | 
| 20 | 
            +
                puts data
         | 
| 21 | 
            +
                Solar::Simulator::Network.send_payload(data, opts.to_hash)
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
              on_error do |e|
         | 
| 24 | 
            +
                puts e.message 
         | 
| 25 | 
            +
                stop! if e.class < Slop::Error
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              on_exit do
         | 
| 29 | 
            +
                puts "Simulation ended"
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            require 'net/http'
         | 
| 2 | 
            +
            require 'uri'
         | 
| 3 | 
            +
            require 'json'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Solar
         | 
| 6 | 
            +
              module Simulator
         | 
| 7 | 
            +
                class Network 
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def self.send_payload(data, options = {})
         | 
| 10 | 
            +
                    payload = { p: {
         | 
| 11 | 
            +
                      se: options[:serial],
         | 
| 12 | 
            +
                      ts: data[:timestamp],
         | 
| 13 | 
            +
                      ty: "gr",
         | 
| 14 | 
            +
                      cfg: options[:type].to_i || 0,
         | 
| 15 | 
            +
                      d: data[:values]
         | 
| 16 | 
            +
                    }
         | 
| 17 | 
            +
                    }
         | 
| 18 | 
            +
                    uri = URI.parse(options[:uri])
         | 
| 19 | 
            +
                    req = Net::HTTP::Post.new(uri.request_uri)
         | 
| 20 | 
            +
                    req["content-type"] = "application/json"
         | 
| 21 | 
            +
                    req.body = payload.to_json
         | 
| 22 | 
            +
                    Net::HTTP.start(uri.host, uri.port) { |http|http.request(req) }
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                 
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
             | 
| @@ -6,16 +6,20 @@ module Solar | |
| 6 6 | 
             
                  Seasons = [[3240, 700],[3600, 600],[3120, 850],[2880, 1000]]
         | 
| 7 7 | 
             
                  GammaVoltage = 11
         | 
| 8 8 | 
             
                  GammaCurrent = 12
         | 
| 9 | 
            +
                  Types = [:single_phase, :three_phase]
         | 
| 9 10 |  | 
| 10 11 | 
             
                  def self.run(options = {})
         | 
| 11 12 | 
             
                    options[:time] ||= Time.now
         | 
| 12 13 | 
             
                    options[:nominal_power] ||= 6000.0
         | 
| 13 14 | 
             
                    options[:max_current] = options[:nominal_power]/230.0
         | 
| 15 | 
            +
                    options[:type] = Types[options[:type].to_i || 0]
         | 
| 14 16 | 
             
                    timestamp = options[:time].to_i
         | 
| 17 | 
            +
                    
         | 
| 18 | 
            +
                    phases = options[:type] == :single_phase ? 1 : 3
         | 
| 15 19 |  | 
| 16 20 | 
             
                    lux = self.simulate_lux(options)
         | 
| 17 | 
            -
                    voltage = self.simulate_voltage(options) | 
| 18 | 
            -
                    current = self.simulate_current(lux, options)
         | 
| 21 | 
            +
                    voltage = phases.times.map{self.simulate_voltage(options)}
         | 
| 22 | 
            +
                    current = phases.times.map{self.simulate_current(lux, options)}
         | 
| 19 23 |  | 
| 20 24 | 
             
                    payload = {}
         | 
| 21 25 | 
             
                    payload[:timestamp] = timestamp
         | 
| @@ -36,9 +40,9 @@ module Solar | |
| 36 40 | 
             
                    base_voltage = 230
         | 
| 37 41 |  | 
| 38 42 | 
             
                    if sign
         | 
| 39 | 
            -
                       | 
| 43 | 
            +
                      (base_voltage + delta).round(2)
         | 
| 40 44 | 
             
                    else
         | 
| 41 | 
            -
                       | 
| 45 | 
            +
                      (base_voltage - delta).round(2)
         | 
| 42 46 | 
             
                    end
         | 
| 43 47 | 
             
                  end
         | 
| 44 48 |  | 
| @@ -46,9 +50,9 @@ module Solar | |
| 46 50 | 
             
                    max_delta = (options[:max_current] * lux / 1023.0) * (GammaCurrent / 100.0)
         | 
| 47 51 | 
             
                    delta = rand * max_delta
         | 
| 48 52 | 
             
                    if Random.rand(2)
         | 
| 49 | 
            -
                       | 
| 53 | 
            +
                      ((options[:max_current]*lux/1023.0)+delta).round(2)
         | 
| 50 54 | 
             
                    else
         | 
| 51 | 
            -
                       | 
| 55 | 
            +
                      ((options[:max_current]*lux/1023.0)-delta).round(2)
         | 
| 52 56 | 
             
                    end
         | 
| 53 57 | 
             
                  end
         | 
| 54 58 | 
             
                end
         | 
    
        data/lib/solar/simulator.rb
    CHANGED
    
    
    
        data/solar-simulator.gemspec
    CHANGED
    
    | @@ -19,6 +19,8 @@ Gem::Specification.new do |spec| | |
| 19 19 | 
             
              spec.require_paths = ["lib"]
         | 
| 20 20 |  | 
| 21 21 | 
             
              spec.add_dependency "activesupport", "~> 4.0.0"
         | 
| 22 | 
            +
              spec.add_dependency "slop"
         | 
| 23 | 
            +
              spec.add_dependency "foreverb"
         | 
| 22 24 |  | 
| 23 25 | 
             
              spec.add_development_dependency "bundler", "~> 1.3"
         | 
| 24 26 | 
             
              spec.add_development_dependency "rake"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: solar-simulator
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Diego R. Brogna
         | 
| @@ -24,6 +24,34 @@ dependencies: | |
| 24 24 | 
             
                - - ~>
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: 4.0.0
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: slop
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - '>='
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - '>='
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: foreverb
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - '>='
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - '>='
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 27 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 56 | 
             
              name: bundler
         | 
| 29 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -69,7 +97,8 @@ dependencies: | |
| 69 97 | 
             
            description: Realistic solar panel simulator
         | 
| 70 98 | 
             
            email:
         | 
| 71 99 | 
             
            - dierbro@gmail.com
         | 
| 72 | 
            -
            executables: | 
| 100 | 
            +
            executables:
         | 
| 101 | 
            +
            - solar-simulator
         | 
| 73 102 | 
             
            extensions: []
         | 
| 74 103 | 
             
            extra_rdoc_files: []
         | 
| 75 104 | 
             
            files:
         | 
| @@ -79,10 +108,13 @@ files: | |
| 79 108 | 
             
            - LICENSE.txt
         | 
| 80 109 | 
             
            - README.md
         | 
| 81 110 | 
             
            - Rakefile
         | 
| 111 | 
            +
            - bin/solar-simulator
         | 
| 82 112 | 
             
            - lib/solar/simulator.rb
         | 
| 113 | 
            +
            - lib/solar/simulator/network.rb
         | 
| 83 114 | 
             
            - lib/solar/simulator/panel.rb
         | 
| 84 115 | 
             
            - lib/solar/simulator/version.rb
         | 
| 85 116 | 
             
            - solar-simulator.gemspec
         | 
| 117 | 
            +
            - spec/network_spec.rb
         | 
| 86 118 | 
             
            - spec/panel_spec.rb
         | 
| 87 119 | 
             
            - spec/simulator_spec.rb
         | 
| 88 120 | 
             
            - spec/spec_helper.rb
         | 
| @@ -111,6 +143,7 @@ signing_key: | |
| 111 143 | 
             
            specification_version: 4
         | 
| 112 144 | 
             
            summary: Realistic solar panel simulator
         | 
| 113 145 | 
             
            test_files:
         | 
| 146 | 
            +
            - spec/network_spec.rb
         | 
| 114 147 | 
             
            - spec/panel_spec.rb
         | 
| 115 148 | 
             
            - spec/simulator_spec.rb
         | 
| 116 149 | 
             
            - spec/spec_helper.rb
         |