jsontochoropleth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jsontochoropleth.rb +46 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f40bf11d4e60d1970ae386f6f9f545d82c14173a
4
+ data.tar.gz: 118f50815061fc56d9b5ec0507ea9184436908fd
5
+ SHA512:
6
+ metadata.gz: 9b6d9db640eb5d1362ec29f80419fda1b05ed71816465714ffa0dc18322a363c5e5ea6866af3955c727cf7912b267f213a444b66613d6512f357a04c3405e8ab
7
+ data.tar.gz: 51568c0554144e90dfbd639dea7259bc6e4662268dd853adf660fbc335e4db15c07c19fe57fb3e333093b696a774c38d56524e4fcec48473e46fafd4856d6243
@@ -0,0 +1,46 @@
1
+ require 'json'
2
+
3
+ class JSONToChoropleth
4
+ def initialize(input, location, number)
5
+ @input = JSON.parse(input)
6
+ @location = location
7
+ @number = number
8
+ end
9
+
10
+ def genfill
11
+ countryhash = Hash.new
12
+
13
+ rangehash = Hash.new
14
+ fullcount = 0
15
+ @input.each do |r|
16
+ fullcount = fullcount + r[@number].to_f
17
+ end
18
+
19
+ average = fullcount.to_f/@input.length.to_f
20
+
21
+ rangehash["#FFFF99"] = average/3
22
+ rangehash["#FFFF00"] = average/2
23
+ rangehash["#FFA800"] = average
24
+ rangehash["#FF6800"] = average/0.5
25
+ rangehash["#FF0000"] = average/0.25
26
+
27
+ @input.each do |t|
28
+ numusers = t[@number]
29
+ prevv = 0
30
+ count = 0
31
+
32
+ rangehash.each do |k,v|
33
+ if (numusers > prevv) && (numusers <= v)
34
+ countryhash[t[@location]] = k
35
+ elsif (count == 4) && (numusers >= v)
36
+ countryhash[t[@location]] = k
37
+ end
38
+ prevv = v
39
+ count = count + 1
40
+ end
41
+ end
42
+
43
+ return JSON.pretty_generate(countryhash)
44
+ end
45
+ end
46
+
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsontochoropleth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - M. C. McGrath
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Converts as JSON to a world choropleth map.
14
+ email: shidash@shidash.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/jsontochoropleth.rb
20
+ homepage: https://github.com/TransparencyToolkit/JSONToChoropleth
21
+ licenses:
22
+ - GPL
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.14
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Converts JSONs to choropleth maps
44
+ test_files: []
45
+ has_rdoc: