Skip to content

Instantly share code, notes, and snippets.

@beeflamian
Created October 9, 2017 13:08
Show Gist options
  • Save beeflamian/b4b92419ab4de81eaa99dc4ccdd505e7 to your computer and use it in GitHub Desktop.
Save beeflamian/b4b92419ab4de81eaa99dc4ccdd505e7 to your computer and use it in GitHub Desktop.
shuttle
locales = Set.new
stat = {}
projects = ['Android Register', 'Dashboard (New)', 'iOS Dashboard', 'iOS Register', 'IRF Forms', 'Public Web', 'Regulator Emails', 'solidshop', 'Help Center Articles', 'Payroll', 'Square / Web', 'Macro Texts']
start_t = Time.current.beginning_of_year
end_t = start_t.end_of_month
while start_t < Time.current do
File.open("/app/shuttle/current/translations_stat_#{start_t.month}.csv", 'w') do |f|
projects.each do |p|
project = Project.find_by_name(p)
stat[project.name] = {}
name = project.name
stat[name]['source'] = 0
keys = Set.new
project.translations.where(created_at: start_t..end_t).each do |t|
unless keys.include?(t.key.id)
stat[name]['source'] += t.words_count
keys.add(t.key.id)
end
unless t.key.is_block_tag
locale = t.rfc5646_locale
locales.add(locale)
stat[name][locale] = 0 unless stat[name][locale]
stat[name][locale] += t.words_count if t.translated
end
end
end
locales = locales.to_a
title = "project source " + locales.join(' ')
f.write("#{title}\n")
stat.each do |project, data|
output = "#{project} #{data['source']}"
locales.each do |locale|
if data[locale]
output += " #{data[locale]}"
else
output += " 0"
end
end
f.write("#{output}\n")
end
end
start_t = end_t + 1
end_t = start_t.end_of_month
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment