claudiob-radiotagmap 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/VERSION +1 -1
- data/lib/radiotagmap.rb +16 -6
- data/radiotagmap.gemspec +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -19,6 +19,9 @@ Ruby gem to map by U.S. state the music played on FM radios
|
|
19
19
|
|
20
20
|
## History ##
|
21
21
|
|
22
|
+
v0.0.7 2009/09/18
|
23
|
+
More contrast in color and defaults to forever and Logger::INFO
|
24
|
+
|
22
25
|
v0.0.6 2009/09/18
|
23
26
|
Only plot the color of the presence of ONE genre/tag (not two)
|
24
27
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/radiotagmap.rb
CHANGED
@@ -12,6 +12,8 @@ module Radiotagmap
|
|
12
12
|
@log = Logger.new(STDERR)
|
13
13
|
@log.level = Logger::WARN
|
14
14
|
@log.level = Logger::DEBUG ### Only for debug purpose ###
|
15
|
+
|
16
|
+
@max_weight = 0.0
|
15
17
|
|
16
18
|
# Returns the index of the family of genres/tags that is currently
|
17
19
|
# most playing on the FM radios of a given U.S. state.
|
@@ -24,7 +26,7 @@ module Radiotagmap
|
|
24
26
|
# == Examples
|
25
27
|
# get_main_tag "CA", [['Rock', 'Indie Rock'], ['Country', 'Alt Country']]
|
26
28
|
#--
|
27
|
-
def self.get_tags_weight(state = "CA", among = [['
|
29
|
+
def self.get_tags_weight(state = "CA", among = [['Country'], ['Rock']])
|
28
30
|
among = among.collect{|family| family.collect(&:downcase)}
|
29
31
|
|
30
32
|
# stations = Yesradio::search_stations(:loc => state)
|
@@ -42,7 +44,7 @@ module Radiotagmap
|
|
42
44
|
return if artists.nil?
|
43
45
|
@log.debug "#{state} | #{artists.length} artists"
|
44
46
|
@log.debug "#{state} | #{artists.join(' ')}"
|
45
|
-
|
47
|
+
|
46
48
|
# The same function as above, but without threads, would be:
|
47
49
|
# artists = stations.collect do |station|
|
48
50
|
# Yesradio::get_station :name => station.name
|
@@ -94,12 +96,15 @@ module Radiotagmap
|
|
94
96
|
def self.get_map_color(weights = [0.5, 0.2])
|
95
97
|
a = "aa"
|
96
98
|
if weights.nil?
|
97
|
-
a << "
|
99
|
+
a << "999999"
|
98
100
|
else
|
101
|
+
value = weights[0]
|
102
|
+
@max_weight = [@max_weight, value].max
|
103
|
+
value = value/@max_weight unless @max_weight.zero?
|
99
104
|
r = "ff" # "%02x" % (255*weights[0]).round
|
100
|
-
b = "%02x" % (255*(1-
|
105
|
+
b = "%02x" % (255*(1-value)).round
|
101
106
|
g = "ff" #"%02x" % (255*(1-weights.sum)).round
|
102
|
-
a << b <<
|
107
|
+
a << b << b << r # The more country, the more red
|
103
108
|
end
|
104
109
|
end
|
105
110
|
|
@@ -115,8 +120,13 @@ module Radiotagmap
|
|
115
120
|
# == Examples
|
116
121
|
# update_kml
|
117
122
|
#--
|
118
|
-
def self.update_kml(kml_path = "./overlay.kml", among = [['
|
123
|
+
def self.update_kml(kml_path = "./overlay.kml", among = [['Country']], forever = true)
|
124
|
+
@log.level = Logger::INFO
|
119
125
|
begin
|
126
|
+
# TO DO: to increase contrast in color, call one get_map_color
|
127
|
+
# passing the entire array, so that the MAX is first calculated
|
128
|
+
# (e.g. the state with more country only has 6/10 country artists)
|
129
|
+
# and then the contrast of colors is normalized based on that value
|
120
130
|
STATES_COORDS.each do |state, coords|
|
121
131
|
color = get_map_color(get_tags_weight(state, among))
|
122
132
|
@log.debug "#{state} | The new color is #{color}"
|
data/radiotagmap.gemspec
CHANGED