Skip to content

Instantly share code, notes, and snippets.

@raphaelmolesim
Created May 12, 2012 21:54
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 raphaelmolesim/2669316 to your computer and use it in GitHub Desktop.
Save raphaelmolesim/2669316 to your computer and use it in GitHub Desktop.
Também levei um susto
require 'nokogiri'
# tá aqui o orçamento executado de 2011 da camara de sp
#http://www.camara.sp.gov.br/index.php?option=com_wrapper&view=wrapper&Itemid=219
xml = File.read "COMPLETO.xml"
p = lambda { |i| i.inner_text.gsub(",", ".").to_f }
def m fl
"%1.2f" % fl
end
doc = Nokogiri::XML(xml)
fornecedores = doc.xpath("//fornecedor").collect { |i| i.attribute("nome").value }.uniq
rank = fornecedores.inject({}) {|map, f| map[f] = doc.xpath("//fornecedor[@nome='#{f}']//vlrPago").collect { |i| p.call(i) }.inject(0) { |r, item| r+item } ; map }
rank.sort { |a1, a2| a1.last <=> a2.last}.reverse.take(10).each { |k,v| puts "==> #{k} => #{m((v/316000000)*100)}% => R$#{m(v)}"} ; nil
"==> Folha De Pagamento Cargos Em Comissão 19 => 24.15% => R$76300699.77
==> Folha De Pagamento Efetivos => 23.72% => R$74950806.35
==> Instituto Nacional De Seguro Social - Inss => 8.01% => R$25312646.82
==> Folha De Pagamento Clt => 6.93% => R$21887402.58
==> Instituto De Previdência Municipal De São Paulo Iprem => 5.37% => R$16982906.44
==> Fundação Para O Desenvolvimento Das Artes E Da Comunicação Fundac => 3.94% => R$12435438.81
==> Sodexho Pass Do Brasil Servicos E Comercio S.A => 3.67% => R$11600852.15
==> Contexto Propaganda Ltda. => 3.21% => R$10153030.16
==> Fg Vereadores => 2.16% => R$6826470.52
==> Folha De Pagamento Comissionados 23 => 2.04% => R$6442328.22"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment