Created
April 19, 2012 17:00
-
-
Save kohgpat/2422304 to your computer and use it in GitHub Desktop.
Statistics from xml parcels
This file contains 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
# encoding: UTF-8 | |
require 'hpricot' | |
class Reporter | |
attr_accessor :path | |
attr_accessor :documents | |
def initialize(path) | |
@path = path | |
@documents = [] | |
Dir.foreach(path) do |file| | |
next if file == '.' or file == '..' | |
if File.zero?(file) | |
puts "Empty file: #{file}" | |
end | |
xml = File.open("#{path}/#{file}") | |
doc = Hpricot::XML(xml) | |
@documents << doc | |
end | |
end | |
def statistics | |
puts "Statistics: #{path}" | |
puts "Number of choice: #{choice}" | |
puts "Number of choice from another smo: #{choice_from_smo}" | |
puts "Number of change: #{change}" | |
end | |
def choice | |
count = 0 | |
@documents.each do |doc| | |
(doc/:OP).each do |op| | |
tip_op = op.attributes["TIP_OP"] | |
rsmo = op.at("VIZIT").attributes["RSMO"] | |
if !tip_op.index('010').nil? or !tip_op.index('061').nil? and rsmo == '1' | |
count = count + 1 | |
end | |
end | |
end | |
count | |
end | |
def choice_from_smo | |
count = 0 | |
@documents.each do |doc| | |
(doc/:OP).each do |op| | |
tip_op = op.attributes["TIP_OP"] | |
rsmo = op.at("VIZIT").attributes["RSMO"] | |
if !tip_op.index('03').nil? and rsmo == '1' | |
count = count + 1 | |
end | |
end | |
end | |
count | |
end | |
def change | |
count = 0 | |
@documents.each do |doc| | |
(doc/:OP).each do |op| | |
tip_op = op.attributes["TIP_OP"] | |
rsmo = op.at("VIZIT").attributes["RSMO"] | |
if !tip_op.index('03').nil? and rsmo == '0' | |
count = count + 1 | |
end | |
end | |
end | |
count | |
end | |
end | |
reporter = Reporter.new(ARGV[0]) | |
reporter.statistics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment