Skip to content

Instantly share code, notes, and snippets.

@toothrot
Forked from ashaegupta/character_frequency
Created June 1, 2015 15:27
Show Gist options
  • Save toothrot/535b456cba45cd31d24f to your computer and use it in GitHub Desktop.
Save toothrot/535b456cba45cd31d24f to your computer and use it in GitHub Desktop.
characters = ["astro.png",
"banyan.png",
"bear.png",
"bird.png",
"chillanna.png",
"cupcake.png",
"dino.png",
"frog.png",
"gorilla.png",
"monkey.png",
"octopus.png",
"parrot.png",
"raccoon.png",
"spacepod.png",
"stargirl.png",
"robo.png"]
character_frequency = [
{char:"astro.png", count:0},
{char:"banyan.png", count:0},
{char:"bear.png", count:0},
{char:"bird.png", count:0},
{char:"chillanna.png", count:0},
{char:"cupcake.png", count:0},
{char:"dino.png", count:0},
{char:"frog.png", count:0},
{char:"gorilla.png", count:0},
{char:"monkey.png", count:0},
{char:"octopus.png", count:0},
{char:"parrot.png", count:0},
{char:"raccoon.png", count:0},
{char:"stargirl.png", count:0},
{char:"spacepod.png", count:0},
{char:"robo.png", count:0}]
has_characters = 0
projects = Project.last(200)
projects.each{ |p|
p p.title
data_as_string = p.data.to_s
project_chars = characters.select{|char| data_as_string.include?(char)}
unless project_chars.empty?
has_characters += 1
project_chars.each{ |c|
p c
character_frequency.find{|s| s[:char] == c}[:count] += 1
}
end
p "---"
}
p "percent projects that use hs chars: #{has_characters.to_f / projects.length.to_f}"
p "character frequency..."
character_frequency.each{ |c|
p "#{c[:char]} : #{c[:count]}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment