-
Notifications
You must be signed in to change notification settings - Fork 0
/
profit_calc.rb
executable file
·142 lines (117 loc) · 3.53 KB
/
profit_calc.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env ruby
# sample data file:
#
# Battle Report
# Location LIND (A07:54:70:20)
# Time 2010-02-05 19:11:07
# Attack Force
# Player [CR] Anacaona lvl 60.46
# Fleet Name tumble 22
# Defensive Force
# Player [Ni] BlueWolf74727 lvl 57.44
# Fleet Name Fleet 260 (Destroyed)
# Base 262383
# Start Defenses 100%
# End Defenses 0%
# Command Centers 11
# Commander Devin Tauros (Research 10)
#
# Attack Force
# Unit Start Quant. End Quant. Power Armour Shield
# Fighters 121584 120030 4.8 4.8 0
# Corvette 4244 3467 9.6 9.6 0
# Destroyer 5388 5000 17.2 19.2 0
# Cruiser 8271 8142.7 51.6 57.6 3.9
#
# Defensive Force
# Unit Start Quant. End Quant. Power Armour Shield
# Fighters 23 0 7.8 5 0
# Dreadnought 5 0 1874.9 1280 40
# Disruptor Turrets 10 0 384 640 16
# Planetary Shield 5 0 6.6 5120 40
# Planetary Ring 5 0 3276.8 2560 24
#
# Total cost of units destroyed: 114545 ( Attacker: 64430 ; Defender: 50115 )
# Experience: ( Attacker: +5169 ; Defender: +6028 )
# New debris in space: 66150
# Attacker conquered the base
# Attacker got 19287 credits for pillaging defender's base.
#
data_file = ARGV[0]
attack = true
if !ARGV[1].nil?
attack = false if ARGV[1].eql?("defend")
end
r_units_destroyed = /Total cost of units destroyed: [0-9]+ \( Attacker: ([0-9]+) ; Defender: ([0-9]+) \)/
r_derbs = /New debris in space: ([0-9]+)/i
r_pillage = /Attacker got ([0-9]+) credits for pillaging defender's base./
r_experience = /Experience: \( Attacker: \+([0-9]+) ; Defender: \+([0-9]+) \)/i
# there are two ways to see how many credits you got from a trade route.
# i'd wager that there is a way to grab them both from a single regex,
# but my regex-fu is not strong :(
r_trades1 = /You got ([0-9]+) credits from plundering this trade route/i
r_trades2 = /Plunder of trade route from[\saA-zZ]+\+([0-9]+)/i
losses = {:attacker => 0, :defender => 0}
derbs = 0
pillage = 0
trades = 0
exp = {:attacker => 0, :defender => 0}
f = File.open(data_file)
matches = f.read.scan(r_units_destroyed)
matches.each do |match|
losses[:attacker] += match[0].to_i
losses[:defender] += match[1].to_i
end
f.rewind
matches = f.read.scan(r_derbs)
matches.each do |match|
derbs += match[0].to_i
end
f.rewind
matches = f.read.scan(r_pillage)
matches.each do |match|
pillage += match[0].to_i
end
# handle the first case of trade inputs...
f.rewind
f.read.scan(r_trades1).each { |match| trades += match[0].to_i }
# matches = f.read.scan(r_trade1)
# matches.each do |match|
# trades += match[0].to_i
# end
# second case of trade inputs
f.rewind
f.read.scan(r_trades2).each { |match| trades += match[0].to_i }
f.rewind
matches = f.read.scan(r_experience)
matches.each do |match|
exp[:attacker] += match[0].to_i
exp[:defender] += match[1].to_i
end
puts
puts "=" * 50
puts "Attacker losses: #{losses[:attacker]}"
puts "Defender losses: #{losses[:defender]}"
puts "Derbs: #{derbs}"
puts "Pillage: #{pillage}"
puts "Trades: #{trades}"
if !attack
profits = pillage + derbs + trades - losses[:defender]
else
profits = pillage + derbs + trades - losses[:attacker]
end
puts "Profits: #{profits}"
if !attack
puts "Ratio: #{"%.4f" % (losses[:attacker].to_f/losses[:defender].to_f)}"
else
puts "Ratio: #{"%.4f" % (losses[:defender].to_f/losses[:attacker].to_f)}"
end
if !attack
puts "Return on Investment: #{"%.2f" % (100.0 * profits.to_f/losses[:defender].to_f)}%"
else
puts "Return on Investment: #{"%.2f" % (100.0 * profits.to_f/losses[:attacker].to_f)}%"
end
puts "Attacker XP: #{exp[:attacker]}"
puts "Defender XP: #{exp[:defender]}"
puts "=" * 50
puts