Skip to content

Commit

Permalink
Added method for useful price & added to spreadsheet.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwlManAtt committed Sep 10, 2011
1 parent 964ca34 commit 93c36d3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
tsm = TSMAccounting::Database.new(File.new('data/TradeSkillMaster_Accounting.lua').read)
tsm.to_csv('/tmp/accounting.csv')

== Notes ==
The Transaction#usable_price() method outputs the price as a float. Copper >50
is rounded up to 1s. If the transaction was worth less than 50c, you'll get 0.1
instead of 0.0.

If you need greater precision, price is the copper value of the transaction. It
is included in the CSV output.

== Thanks ==
Sapu & The Consortium <http://consortium.stormspire.net/>.
23 changes: 22 additions & 1 deletion lib/tsm-accounting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def initialize(db_string)

def to_csv(output_file)
CSV.open(output_file, 'w') do |f|
f << ['Realm','Faction','Transaction Type','Time','Item','Quantity','Stack Size','Price (c)','Buyer','Seller']
f << ['Realm','Faction','Transaction Type','Time','Item','Quantity','Stack Size','Price (g)','Price (c)','Buyer','Seller']

@data.each do |realm,factions|
factions.each do |faction,ropes|
Expand All @@ -62,6 +62,7 @@ def to_csv(output_file)
row << item.name
row << tx.quantity
row << tx.stack_size
row << tx.usable_price
row << tx.price
row << tx.buyer
row << tx.seller
Expand Down Expand Up @@ -224,6 +225,26 @@ def initialize(encoded_string)
@seller = d[5]
end # initialize

def usable_price
price = @price.to_s.rjust(5,'0')
parts = {
'gold' => price[0..-5].to_i,
'silver' => price[-4..2].to_i,
'copper' => price[-2..2].to_i
}

# Round up the copper.
parts['silver'] += 1 if parts['copper'] > 50

# If this was a <50c transaction, set silver to 1 so
# it doesn't confuse people.
if parts['gold'] == 0 and parts['silver'] == 0 and parts['copper'] < 50
parts['silver'] = 1
end

return "#{parts['gold']}.#{parts['silver']}".to_f
end

protected
def decode(value)
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_="
Expand Down

0 comments on commit 93c36d3

Please sign in to comment.