Sha256: 1ad0e1c53eb20e330779f9368458087a1d3e52ed7265a8f4f8475f42bea0a0c7

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env ruby

require 'json'


module Edj
	class Item
		def self.from(hash)
			case hash["event"]
			when "Scan"
				ScanItem.new(hash)
			when "EngineerProgress"
				EngineerProgressItem.new(hash)
			when "EngineerContributionItem"
				EngineerContributionItem.new(hash)
			end
		end

		def initialize(hash)
			@raw = hash
		end

		def timestamp()
			@raw["timestamp"]
		end
	end

	class Journal
		attr_reader :tree

		def initialize(f)
			@f = f
			@tree = {}
		end

		def filter(type)
			File.open(@f).readlines
				.map {|line| Item.from(JSON.parse(line))}
				.select {|item| item.is_a? type }
		end

		def scan_value()
			total_value = 0
			File.open(@f).each do |line|
				item = Item.from(JSON.parse(line))
				if item.is_a? ScanItem then
					v = item.value
					bits = item.bodyName.split(' ')
					(1..(bits.size-1)).each do |i|
						entry = bits[0..i].join(' ')
						o = @tree[entry]
						@tree[entry] ||= 0
						@tree[entry] += v
					end
					STDOUT.puts("#{item.timestamp} #{item.bodyName} --> #{v}")
					total_value = total_value + v
				end
			end
			total_value
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
edj-0.1.0 lib/edj/base.rb