Skip to content

Instantly share code, notes, and snippets.

@zverok
Created November 28, 2012 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zverok/4162199 to your computer and use it in GitHub Desktop.
Save zverok/4162199 to your computer and use it in GitHub Desktop.
{"диск"=>100,
"яндекс"=>100,
"сервис"=>54,
"получать"=>54,
"ссылка"=>53,
"эта"=>51,
"дополнительный"=>50,
"новый"=>50,
"пространство"=>49,
"заводить"=>49,
"приглашение"=>49,
"пробовать"=>48,
"файл"=>14,
"дропбокс"=>14,
"пользователь"=>14,
"быть"=>13,
"давать"=>12,
"можно"=>11,
"мочь"=>11,
"облачный"=>11,
"миллион"=>11,
"есть"=>11,
"работа"=>11,
"число"=>10}
# encoding: utf-8
require 'pp'
data = {
"диск" => 6558,
"яндекс" => 6507,
"сервис" => 3317,
"получать" => 3255,
"ссылка" => 3208,
"эта" => 3055,
"дополнительный" => 3021,
"новый" => 3009,
"пространство" => 2957,
"заводить" => 2949,
"приглашение" => 2944,
"пробовать" => 2861,
"файл" => 492,
"дропбокс" => 457,
"пользователь" => 455,
"быть" => 390,
"давать" => 360,
"можно" => 296,
"мочь" => 253,
"облачный" => 243,
"миллион" => 228,
"есть" => 228,
"работа" => 227,
"число" => 226,
}
font_min = 10
font_max = 100
data_min = data.values.min
data_max = data.values.max
normalized = {}
data.each do |word, count|
normalized[word] = ( (count-data_min).to_f/(data_max-data_min)*(font_max-font_min)+font_min).ceil
end
pp normalized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment