sniff 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.
Files changed (79) hide show
  1. data/README.markdown +73 -0
  2. data/lib/sniff/active_record_ext.rb +12 -0
  3. data/lib/sniff/conversions_ext.rb +45 -0
  4. data/lib/sniff/database.rb +157 -0
  5. data/lib/sniff/emitter.rb +65 -0
  6. data/lib/sniff/tasks.rb +14 -0
  7. data/lib/sniff/timeframe.rb +251 -0
  8. data/lib/sniff.rb +31 -0
  9. data/lib/test_support/data_models/census_division.rb +9 -0
  10. data/lib/test_support/data_models/census_region.rb +9 -0
  11. data/lib/test_support/data_models/climate_division.rb +8 -0
  12. data/lib/test_support/data_models/country.rb +9 -0
  13. data/lib/test_support/data_models/egrid_region.rb +7 -0
  14. data/lib/test_support/data_models/egrid_subregion.rb +8 -0
  15. data/lib/test_support/data_models/gender.rb +6 -0
  16. data/lib/test_support/data_models/petroleum_administration_for_defense_district.rb +9 -0
  17. data/lib/test_support/data_models/state.rb +13 -0
  18. data/lib/test_support/data_models/urbanity.rb +6 -0
  19. data/lib/test_support/data_models/zip_code.rb +14 -0
  20. data/lib/test_support/db/fixtures/census_divisions.csv +10 -0
  21. data/lib/test_support/db/fixtures/census_regions.csv +5 -0
  22. data/lib/test_support/db/fixtures/climate_divisions.csv +360 -0
  23. data/lib/test_support/db/fixtures/countries.csv +247 -0
  24. data/lib/test_support/db/fixtures/egrid_regions.csv +6 -0
  25. data/lib/test_support/db/fixtures/egrid_subregions.csv +27 -0
  26. data/lib/test_support/db/fixtures/genders.csv +3 -0
  27. data/lib/test_support/db/fixtures/petroleum_administration_for_defense_districts.csv +8 -0
  28. data/lib/test_support/db/fixtures/states.csv +58 -0
  29. data/lib/test_support/db/fixtures/urbanities.csv +5 -0
  30. data/lib/test_support/db/fixtures/yearly_anonymous_emissions.csv +0 -0
  31. data/lib/test_support/db/fixtures/yearly_typical_emissions.csv +0 -0
  32. data/lib/test_support/db/fixtures/zip_codes.csv +3390 -0
  33. data/lib/test_support/db/schema.rb +117 -0
  34. data/spec/lib/sniff/database_spec.rb +22 -0
  35. data/spec/spec.opts +2 -0
  36. data/spec/spec_helper.rb +5 -0
  37. data/vendor/geokit-rails/CHANGELOG.rdoc +46 -0
  38. data/vendor/geokit-rails/MIT-LICENSE +20 -0
  39. data/vendor/geokit-rails/README.markdown +561 -0
  40. data/vendor/geokit-rails/Rakefile +18 -0
  41. data/vendor/geokit-rails/about.yml +9 -0
  42. data/vendor/geokit-rails/assets/api_keys_template +61 -0
  43. data/vendor/geokit-rails/init.rb +1 -0
  44. data/vendor/geokit-rails/install.rb +14 -0
  45. data/vendor/geokit-rails/lib/geokit-rails/acts_as_mappable.rb +456 -0
  46. data/vendor/geokit-rails/lib/geokit-rails/adapters/abstract.rb +31 -0
  47. data/vendor/geokit-rails/lib/geokit-rails/adapters/mysql.rb +22 -0
  48. data/vendor/geokit-rails/lib/geokit-rails/adapters/postgresql.rb +22 -0
  49. data/vendor/geokit-rails/lib/geokit-rails/adapters/sqlserver.rb +43 -0
  50. data/vendor/geokit-rails/lib/geokit-rails/defaults.rb +22 -0
  51. data/vendor/geokit-rails/lib/geokit-rails/geocoder_control.rb +16 -0
  52. data/vendor/geokit-rails/lib/geokit-rails/ip_geocode_lookup.rb +46 -0
  53. data/vendor/geokit-rails/lib/geokit-rails.rb +24 -0
  54. data/vendor/geokit-rails/test/acts_as_mappable_test.rb +474 -0
  55. data/vendor/geokit-rails/test/boot.rb +25 -0
  56. data/vendor/geokit-rails/test/database.yml +20 -0
  57. data/vendor/geokit-rails/test/fixtures/companies.yml +7 -0
  58. data/vendor/geokit-rails/test/fixtures/custom_locations.yml +54 -0
  59. data/vendor/geokit-rails/test/fixtures/locations.yml +54 -0
  60. data/vendor/geokit-rails/test/fixtures/mock_addresses.yml +17 -0
  61. data/vendor/geokit-rails/test/fixtures/mock_families.yml +2 -0
  62. data/vendor/geokit-rails/test/fixtures/mock_houses.yml +9 -0
  63. data/vendor/geokit-rails/test/fixtures/mock_organizations.yml +5 -0
  64. data/vendor/geokit-rails/test/fixtures/mock_people.yml +5 -0
  65. data/vendor/geokit-rails/test/fixtures/stores.yml +0 -0
  66. data/vendor/geokit-rails/test/ip_geocode_lookup_test.rb +77 -0
  67. data/vendor/geokit-rails/test/models/company.rb +3 -0
  68. data/vendor/geokit-rails/test/models/custom_location.rb +12 -0
  69. data/vendor/geokit-rails/test/models/location.rb +4 -0
  70. data/vendor/geokit-rails/test/models/mock_address.rb +4 -0
  71. data/vendor/geokit-rails/test/models/mock_family.rb +3 -0
  72. data/vendor/geokit-rails/test/models/mock_house.rb +3 -0
  73. data/vendor/geokit-rails/test/models/mock_organization.rb +4 -0
  74. data/vendor/geokit-rails/test/models/mock_person.rb +4 -0
  75. data/vendor/geokit-rails/test/models/store.rb +3 -0
  76. data/vendor/geokit-rails/test/schema.rb +60 -0
  77. data/vendor/geokit-rails/test/tasks.rake +31 -0
  78. data/vendor/geokit-rails/test/test_helper.rb +23 -0
  79. metadata +492 -0
@@ -0,0 +1,117 @@
1
+ require 'sniff/database'
2
+
3
+ Sniff::Database.define_schema do
4
+ create_table "census_divisions", :primary_key => "number", :id => false, :force => true do |t|
5
+ t.string "number"
6
+ t.string "name"
7
+ t.string "census_region_name"
8
+ t.integer "census_region_number"
9
+ t.datetime "created_at"
10
+ t.datetime "updated_at"
11
+ end
12
+
13
+ create_table "census_regions", :primary_key => "number", :id => false, :force => true do |t|
14
+ t.string "number"
15
+ t.string "name"
16
+ t.datetime "created_at"
17
+ t.datetime "updated_at"
18
+ end
19
+
20
+ create_table "climate_divisions", :primary_key => "name", :id => false, :force => true do |t|
21
+ t.string "name"
22
+ t.float "heating_degree_days"
23
+ t.float "cooling_degree_days"
24
+ t.string "state_postal_abbreviation"
25
+ t.datetime "created_at"
26
+ t.datetime "updated_at"
27
+ end
28
+
29
+ create_table "countries", :primary_key => "iso_3166_code", :id => false, :force => true do |t|
30
+ t.string "iso_3166_code"
31
+ t.string "name"
32
+ t.datetime "created_at"
33
+ t.datetime "updated_at"
34
+ end
35
+
36
+ create_table "egrid_regions", :primary_key => "name", :id => false, :force => true do |t|
37
+ t.string "name"
38
+ t.float "loss_factor"
39
+ t.string "loss_factor_units"
40
+ t.datetime "updated_at"
41
+ t.datetime "created_at"
42
+ end
43
+
44
+ create_table "egrid_subregions", :primary_key => "abbreviation", :id => false, :force => true do |t|
45
+ t.string "abbreviation"
46
+ t.string "name"
47
+ t.float "electricity_emission_factor"
48
+ t.string "electricity_emission_factor_units"
49
+ t.string "nerc_abbreviation"
50
+ t.string "egrid_region_name"
51
+ t.datetime "updated_at"
52
+ t.datetime "created_at"
53
+ end
54
+
55
+ create_table "fallbacks", :force => true do |t|
56
+ t.string "name"
57
+ t.text "values"
58
+ t.datetime "created_at"
59
+ t.datetime "updated_at"
60
+ end
61
+
62
+ create_table "genders", :primary_key => "name", :id => false, :force => true do |t|
63
+ t.string "name"
64
+ t.datetime "created_at"
65
+ t.datetime "updated_at"
66
+ end
67
+
68
+ create_table "petroleum_administration_for_defense_districts", :primary_key => "code", :id => false, :force => true do |t|
69
+ t.string "code"
70
+ t.string "district_code"
71
+ t.string "district_name"
72
+ t.string "subdistrict_code"
73
+ t.string "subdistrict_name"
74
+ t.datetime "updated_at"
75
+ t.datetime "created_at"
76
+ end
77
+
78
+ create_table "states", :primary_key => "postal_abbreviation", :id => false, :force => true do |t|
79
+ t.string "postal_abbreviation"
80
+ t.integer "fips_code"
81
+ t.string "name"
82
+ t.string "census_division_number"
83
+ t.string "petroleum_administration_for_defense_district_code"
84
+ t.datetime "updated_at"
85
+ t.datetime "created_at"
86
+ end
87
+
88
+ create_table "urbanities", :primary_key => "name", :id => false, :force => true do |t|
89
+ t.string "name"
90
+ t.datetime "created_at"
91
+ t.datetime "updated_at"
92
+ end
93
+
94
+ create_table "yearly_anonymous_emissions", :force => true do |t|
95
+ t.string "component"
96
+ t.integer "year"
97
+ t.float "emission"
98
+ end
99
+
100
+ create_table "yearly_typical_emissions", :force => true do |t|
101
+ t.string "component"
102
+ t.integer "year"
103
+ t.float "emission"
104
+ end
105
+
106
+ create_table "zip_codes", :primary_key => "name", :id => false, :force => true do |t|
107
+ t.string "name"
108
+ t.string "state_postal_abbreviation"
109
+ t.string "description"
110
+ t.string "latitude"
111
+ t.string "longitude"
112
+ t.string "egrid_subregion_abbreviation"
113
+ t.string "climate_division_name"
114
+ t.datetime "created_at"
115
+ t.datetime "updated_at"
116
+ end
117
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe Sniff::Database do
5
+ describe '#connect' do
6
+ before :all do
7
+ @db_path = File.join(File.dirname(__FILE__), '..', '..', '..')
8
+ Sniff.init(@db_path)
9
+ @sqlite_path = File.join(@db_path, 'db', 'emitter_data.sqlite3')
10
+ end
11
+ after :all do
12
+ FileUtils.rm_f(@sqlite_path)
13
+ end
14
+ it 'should create an sqlite database in the given directory' do
15
+ File.exists?(@sqlite_path).should be_true
16
+ end
17
+ it 'should load data' do
18
+ ZipCode.count.should > 0
19
+ end
20
+ end
21
+ end
22
+
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'sniff' # loaded using path in Gemfile
@@ -0,0 +1,46 @@
1
+ == 2009-10-02 / Version 1.2.0
2
+ * Overhaul the test suite to be independent of a Rails project
3
+ * Added concept of database adapter. Ported mysql/postgresql conditional code to their own adapter.
4
+ * Added SQL Server support. THANKS http://github.com/brennandunn for all the improvements in this release
5
+
6
+ == 2009-09-26 / Version 1.1.3
7
+ * documentation updates and updated to work with Geokit gem v1.5.0
8
+ * IMPORTANT: in the Geokit gem, Geokit::Geocoders::timeout became Geokit::Geocoders::request_timeout for jruby compatibility.
9
+ The plugin sets this in config/initializers/geokit_config.rb. So if you've upgraded the gem to 1.5.0, you need to
10
+ make the change manually from Geokit::Geocoders::timeout to Geokit::Geocoders::request_timeout in config/initializers/geokit_config.rb
11
+
12
+ == 2009-06-08 / Version 1.1.2
13
+ * Added support for hashes in :through. So you can do: acts_as_mappable :through => { :state => :country } (Thanks José Valim).
14
+
15
+ == 2009-05-22 / Version 1.1.1
16
+ * Support for multiple ip geocoders (Thanks dreamcat4)
17
+ * Now checks if either :origin OR :bounds is passed, and proceeds with geokit query if this is true (Thanks Glenn Powell)
18
+ * Raises a helpful error if someone uses through but the association does not exists or was not defined yet (Thanks José Valim)
19
+
20
+ == 2009-04-11 / Version 1.1.0
21
+ * Fixed :through usages so that the through model is only included in the query if there
22
+ is an :origin passed in (Only if it is a geokit search) (Thanks Glenn Powell)
23
+ * Move library initialisation into lib/geokit-rails. init.rb uses lib/geokit-rails now (thanks Alban Peignier)
24
+ * Handle the case where a user passes a hash to the :conditions Finder option (thanks Adam Greene)
25
+ * Added ability to specify domain-specific API keys (Thanks Glenn Powell)
26
+
27
+ == 2009-02-20
28
+ * More powerful assosciations in the Rails Plugin:You can now specify a model as mappable "through" an associated model.
29
+ In other words, that associated model is the actual mappable model with "lat" and "lng" attributes, but this "through" model
30
+ can still utilize all Geokit's "find by distance" finders. Also Rails 2.3 compatibility (thanks github/glennpow)
31
+
32
+ == 2008-12-18
33
+ * Split Rails plugin from geocoder gem
34
+ * updated for Rails 2.2.2
35
+
36
+ == 2008-08-20
37
+ * Further fix of distance calculation, this time in SQL. Now uses least() function, which is available in MySQL version 3.22.5+ and postgres versions 8.1+
38
+
39
+ == 2008-01-16
40
+ * fixed the "zero-distance" bug (calculating between two points that are the same)
41
+
42
+ == 2007-11-12
43
+ * fixed a small but with queries crossing meridian, and also fixed find(:closest)
44
+
45
+ == 2007-10-11
46
+ * Fixed Rails2/Edge compatability
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Bill Eisenhauer & Andre Lewis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.