Created
May 24, 2017 17:15
-
-
Save basmoura/d9a18942731108746cc9cd349ef661fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
class App | |
def initialize | |
collect | |
process | |
end | |
def collect | |
@lines = [] | |
file = File.open("/Users/basmoura/Downloads/_chat.txt").read | |
file.each_line do |line| | |
@lines << line if line.match(/(:\s.*:\s)/) | |
end | |
@l = @lines.group_by { |l| Date.strptime(l[/\d.\/\d.\/\d./], "%d/%m/%y").strftime("%m/%y") if l.match(/\d.\/\d.\/\d./) } | |
end | |
def process | |
users = ["Puig", "Guguets", "Eloy", "Heitor Figueiredo", "Guigo", | |
"Aldo Cristiano", "Sinho", "Coxinha", "Diego Mota", "Breno Moura", | |
"Negao", "FlavioPrado", "Leonardo", "Dudu", "Cleyton", "Formiga", | |
"Sidney Menezes", "Palin", "Caio", "Rodriguinho", "Naldinho", | |
"Flavinho", "Vitor Bessa"].sort_by(&:downcase) | |
@sum = 0.0 | |
puts "Perído: 23/12/16 19:04:09 - 24/05/17 12:28:27" | |
puts "Total de mensagens: #{@lines.count}" | |
puts "" | |
users.each do |user| | |
@l.each do |k, v| | |
total = v.select { |line| line.match(/:\s#{user}:/i) }.count | |
percent = (total.to_f / v.count.to_f) * 100 | |
@sum += percent | |
puts "#{k} - #{user}: #{total} mensagens. (#{percent.round(2)}%)" | |
end | |
end | |
end | |
def print | |
puts "Total apurado: #{@sum.round}%" | |
end | |
end | |
App.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment