eve_static 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.sql.bz2
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eve_static.gemspec
4
+ gemspec
5
+
6
+ gem 'sequel'
7
+ gem 'mysql2'
8
+ gem 'awesome_print'
9
+ gem 'rspec', :group => :test
data/LICENSE.txt ADDED
@@ -0,0 +1,16 @@
1
+ EveStatic: Library to access eve online static database
2
+ Copyright (C) 2013 Femaref
3
+ femaref@googlemail.com
4
+
5
+ This program is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU General Public License
7
+ as published by the Free Software Foundation; limited to version 2.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # EveStatic
2
+
3
+ EveStatic is a gem designed to access the eve online static database dump, and provides convenience methods,
4
+ especially for industry calculations.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'eve_static'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install eve_static
19
+
20
+ ## Usage
21
+
22
+ There is only one class at the moment, `EveStatic::Database`. It is based on the sequel gem,
23
+ and takes the same parameters as the `Sequel.connect` method, the `:adapter` parameter defaults to
24
+ the `mysql2` adapter.
25
+
26
+ Example:
27
+
28
+ db = EveStatic::Database.new(:user => "some_user", :database => "evestatic")
29
+ db.materials("Raven") # output omitted
30
+
31
+ You'll need to supply the current eve static database dump yourself.
32
+
33
+ Any method requiring a type works with either the `typeID` or `typeName`, and automatically coerces
34
+ blueprint names as well (so if you supply `Raven`, it will automatically lookup `Raven Blueprint` in
35
+ `invBlueprintTypes` for manufacture times et al).
36
+
37
+ If you want to query for data yourself, the sequel database object is exposed as `instance` on the `EveStatic::Database` object.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eve_static/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "eve_static"
8
+ gem.version = EveStatic::VERSION
9
+ gem.authors = ["Femaref"]
10
+ gem.email = ["femaref@googlemail.com"]
11
+ gem.description = %q{EveStatic is a gem designed to access the eve online static database dump, and provides conveinience methods, especially for industry calculations.}
12
+ gem.summary = %q{EveStatic: Library to access eve online static database}
13
+ gem.homepage = "https://github.com/Femaref/eve-static"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,45 @@
1
+ module EveStatic
2
+ module Coerce
3
+ def coerce_type_id(type)
4
+ coerce_type(type)[:typeID]
5
+ end
6
+
7
+ def coerce_type_name(type)
8
+ coerce_type(type)[:typeName]
9
+ end
10
+
11
+
12
+ def coerce_industry_type(type)
13
+ hash = coerce_type(type)
14
+
15
+ typeID = hash[:typeID]
16
+ typeName = hash[:typeName]
17
+
18
+ if !(typeName =~ /.+Blueprint/)
19
+ typeID = blueprint(typeID)[:blueprintTypeID]
20
+ end
21
+
22
+ typeID
23
+ end
24
+
25
+ private
26
+
27
+ def coerce_type(type)
28
+ if type.is_a? String
29
+ hash = {
30
+ :typeName => type,
31
+ :typeID => typeID(type)
32
+ }
33
+ elsif type.is_a? Integer
34
+ hash = {
35
+ :typeName => typeName(type),
36
+ :typeID => type
37
+ }
38
+ else
39
+ raise "type needs to be either Integer or String"
40
+ end
41
+
42
+ hash
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ module EveStatic
2
+ class Database
3
+ include EveStatic::Queries::Basic
4
+ include EveStatic::Queries::Industry
5
+ include EveStatic::Coerce
6
+
7
+ def initialize(opt = {})
8
+ defaults = {
9
+ :adapter => 'mysql2'
10
+ }
11
+
12
+ @db = Sequel.connect(defaults.merge(opt))
13
+ end
14
+
15
+ def instance
16
+ @db
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module EveStatic
2
+ module Queries
3
+ module Basic
4
+ def typeID(typeName)
5
+ if !typeName.is_a?(String)
6
+ raise "please supply typeName as a String"
7
+ end
8
+
9
+ instance[:invTypes].where(:typeName => typeName).select(Sequel.lit('typeID')).first[:typeID]
10
+ end
11
+
12
+ def typeName(typeID)
13
+ if !typeID.is_a?(Integer)
14
+ raise "please supply typeID as an Integer"
15
+ end
16
+
17
+ instance[:invTypes].where(:typeID => typeID).select(Sequel.lit('typeName')).first[:typeName]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,146 @@
1
+ module EveStatic
2
+ module Queries
3
+ module Industry
4
+ module ClassMethods
5
+ def industry_time_generator(method, defaults = {}, &block)
6
+ if !block_given?
7
+ raise 'you need to supply a block to industry_time_generator'
8
+ end
9
+
10
+ define_method method do |type, opt = {}|
11
+ params = defaults.merge(opt)
12
+ typeID = coerce_industry_type(type)
13
+
14
+ result = instance[:invBlueprintTypes].where(:blueprintTypeID => typeID).first
15
+
16
+ block.call(result, params)
17
+ end
18
+ end
19
+
20
+ def research_time(base, skill, slot, implant)
21
+ base * (1 - (0.05 * skill)) * slot * implant
22
+ end
23
+ end
24
+
25
+
26
+ def self.included(klass)
27
+ klass.extend(ClassMethods)
28
+
29
+ klass.instance_eval do
30
+ industry_time_generator(:manufacture_time, {
31
+ :industry => 0.0,
32
+ :implant_modifier => 1.0,
33
+ :slot_modifier => 1.0,
34
+ :pe => 0.0
35
+ }) do |result, params|
36
+ if params[:pe] >= 0
37
+ pe = params[:pe].to_f/(1.0+params[:pe].to_f)
38
+ else
39
+ pe = params[:pe].to_f - 1.0
40
+ end
41
+
42
+ res = result[:productionTime] * ((1-(0.04*params[:industry])))*params[:implant_modifier]*params[:slot_modifier]
43
+ res = res * ( 1.0 - ((result[:productivityModifier].to_f)/result[:productionTime].to_f) * pe)
44
+ res.to_i
45
+ end
46
+
47
+ industry_time_generator(:material_research_time, {
48
+ :metallurgy => 0.0,
49
+ :implant_modifier => 1.0,
50
+ :slot_modifier => 1.0
51
+ }) do |result, params|
52
+ research_time(result[:researchMaterialTime], params[:metallurgy], params[:slot_modifier], params[:implant_modifier]).to_i
53
+ end
54
+
55
+ industry_time_generator(:production_research_time, {
56
+ :research => 0.0,
57
+ :implant_modifier => 1.0,
58
+ :slot_modifier => 1.0
59
+ }) do |result, params|
60
+ research_time(result[:researchProductivityTime], params[:research], params[:slot_modifier], params[:implant_modifier]).to_i
61
+ end
62
+
63
+ industry_time_generator(:copy_research_time, {
64
+ :science => 0.0,
65
+ :implant_modifier => 1.0,
66
+ :slot_modifier => 1.0
67
+ }) do |result, params|
68
+ research_time(result[:researchCopyTime], params[:science], params[:slot_modifier], params[:implant_modifier]).to_i
69
+ end
70
+ end
71
+ end
72
+
73
+ def blueprint(type)
74
+ typeID = coerce_type_id(type)
75
+
76
+ result = instance[:invBlueprintTypes].where(:productTypeID => typeID).first
77
+ result ||= instance[:invBlueprintTypes].where(:blueprintTypeID => typeID).first
78
+
79
+ result
80
+ end
81
+
82
+ def product(type)
83
+ typeID = coerce_type_id(type)
84
+
85
+ instance[:invBlueprintTypes].where(:blueprintTypeID => typeID).select(Sequel.lit('productTypeID')).first[:productTypeID]
86
+ end
87
+
88
+ def materials(type, me = 0)
89
+ typeID = coerce_industry_type(type)
90
+ productTypeID = product(typeID)
91
+
92
+ bp = blueprint(typeID)
93
+
94
+ raw = raw_materials(productTypeID).to_a
95
+
96
+ extra = extra_materials(typeID).to_a
97
+
98
+ subtract = extra.select { |e| e[:recycle] }
99
+
100
+ subtract = subtract.map do |s|
101
+ raw_materials(s[:requiredTypeID]).to_a
102
+ end
103
+
104
+ subtract = subtract.flatten
105
+ raw_hash = Hash[raw.map { |r| [ r[:materialTypeID], r ] }]
106
+
107
+ subtract.each do |s|
108
+ if raw_hash.keys.include? s[:materialTypeID]
109
+ raw_hash[s[:materialTypeID]][:quantity] -= s[:quantity]
110
+ end
111
+ end
112
+
113
+ raw = raw_hash.values
114
+ raw = raw.select do |r|
115
+ r[:quantity] > 0
116
+ end
117
+
118
+ raw = raw.map { |r| r.merge({ :waste => waste(r[:quantity], bp[:wasteFactor], me) }) }
119
+
120
+ { :raw => raw,
121
+ :extra => extra }
122
+ end
123
+
124
+ private
125
+
126
+ def raw_materials(typeID)
127
+ instance[:invTypeMaterials].where( :invTypeMaterials__typeID => typeID ).select(:materialTypeID, :quantity)
128
+ end
129
+
130
+ def extra_materials(typeID)
131
+ instance[:ramTypeRequirements].where( :typeID => typeID ).where(:activityID => 1).select(:requiredTypeID, :quantity, :damagePerJob, :recycle)
132
+ end
133
+
134
+ def waste(base, base_waste, me)
135
+ if me >= 0
136
+ me = (1.0/(me + 1.0))
137
+ else
138
+ me = (1.0 - me)
139
+ end
140
+
141
+ result = base * (base_waste.to_f/100.0) * me
142
+ result.to_i
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,3 @@
1
+ module EveStatic
2
+ VERSION = "0.0.1"
3
+ end
data/lib/eve_static.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "eve_static/version"
2
+ require 'bundler'
3
+
4
+ Bundler.require(:default)
5
+
6
+ module EveStatic
7
+ autoload :Database, 'eve_static/database.rb'
8
+ autoload :Coerce, 'eve_static/coerce.rb'
9
+
10
+ module Queries
11
+ autoload :Basic, 'eve_static/queries/basic.rb'
12
+ autoload :Industry, 'eve_static/queries/industry.rb'
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eve_static
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Femaref
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: EveStatic is a gem designed to access the eve online static database
15
+ dump, and provides conveinience methods, especially for industry calculations.
16
+ email:
17
+ - femaref@googlemail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - eve_static.gemspec
28
+ - lib/eve_static.rb
29
+ - lib/eve_static/coerce.rb
30
+ - lib/eve_static/database.rb
31
+ - lib/eve_static/queries/basic.rb
32
+ - lib/eve_static/queries/industry.rb
33
+ - lib/eve_static/version.rb
34
+ homepage: https://github.com/Femaref/eve-static
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 1.8.24
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: ! 'EveStatic: Library to access eve online static database'
58
+ test_files: []