tf2_line_parser 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.tool-versions +2 -0
- data/README.md +2 -2
- data/lib/tf2_line_parser/events/event.rb +1 -1
- data/lib/tf2_line_parser/events/world_intermission_win_limit.rb +11 -0
- data/lib/tf2_line_parser/line.rb +47 -6
- data/lib/tf2_line_parser/version.rb +1 -1
- data/spec/lib/tf2_line_parser/parser_spec.rb +16 -0
- metadata +5 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce1e976cd8122572fc3e7ca491e66064e93a6bf46153c1d8fbc3d47961c1df22
|
|
4
|
+
data.tar.gz: d6cc774e17ab02595f7253e31ed9f436dc163681fd82ca2385d5118d80c5c639
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0bd2e58a37355dc74faf0f3b3db946e13cf273453d9ed46e6073fd3a15585ecdecfce3caf54279303a16f004141bcb7509d4ece264c82f09e16c3def603b24a7
|
|
7
|
+
data.tar.gz: 74717248ec519c02913b20bb6b4565b147a7b6aa11a211f78917756ab9696a3620eb98ec4c0347988d2a39feed30cc6cf42c2653857665ee871e7f68f0d11eb3
|
data/.tool-versions
ADDED
data/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# TF2 line parser
|
|
1
|
+
# TF2 line parser
|
|
2
2
|
|
|
3
3
|
A TF2 log line parser. Unlike the other log parsers I've found, this one parses the line and returns a plain old ruby object to describe the event of the line.
|
|
4
4
|
I plan to use this for my own stats parsing tool.
|
|
5
5
|
|
|
6
6
|
## Requirements
|
|
7
|
-
* Ruby
|
|
7
|
+
* Ruby (no runtime dependencies)
|
|
8
8
|
|
|
9
9
|
## Credits
|
|
10
10
|
* nTraum, I stole most of the regexes from his [TF2Stats](https://github.com/nTraum/tf2stats/) project.
|
|
@@ -38,7 +38,7 @@ module TF2LineParser
|
|
|
38
38
|
# ordered by how common the messages are
|
|
39
39
|
@types ||= [ShotFired, ShotHit, PositionReport, HeadshotDamage, Airshot, Damage, AirshotHeal, Heal, PickupItem, Assist, Kill, CaptureBlock, PointCapture, ChargeDeployed,
|
|
40
40
|
MedicDeath, MedicDeathEx, EmptyUber, ChargeReady, ChargeEnded, FirstHealAfterSpawn, LostUberAdvantage, BuiltObject, PlayerExtinguished, JoinedTeam, EnteredGame, RoleChange, Spawn, Suicide, KilledObject, Say, TeamSay, Domination, Revenge, RoundWin, CurrentScore,
|
|
41
|
-
RoundLength, RoundStart, RoundSetupBegin, RoundSetupEnd, MiniRoundStart, MiniRoundSelected, IntermissionWinLimit, Connect, Disconnect, RconCommand, ConsoleSay, MatchEnd, FinalScore,
|
|
41
|
+
RoundLength, RoundStart, RoundSetupBegin, RoundSetupEnd, MiniRoundStart, MiniRoundSelected, WorldIntermissionWinLimit, IntermissionWinLimit, Connect, Disconnect, RconCommand, ConsoleSay, MatchEnd, FinalScore,
|
|
42
42
|
RoundStalemate, Unknown].freeze
|
|
43
43
|
end
|
|
44
44
|
|
data/lib/tf2_line_parser/line.rb
CHANGED
|
@@ -10,8 +10,8 @@ module TF2LineParser
|
|
|
10
10
|
KEYWORD_DISPATCH = {
|
|
11
11
|
'shot_fired' => [Events::ShotFired],
|
|
12
12
|
'shot_hit' => [Events::ShotHit],
|
|
13
|
-
'damage' =>
|
|
14
|
-
'healed' =>
|
|
13
|
+
'damage' => :check_damage_subtypes,
|
|
14
|
+
'healed' => :check_heal_subtypes,
|
|
15
15
|
'picked up' => [Events::PickupItem],
|
|
16
16
|
'kill assist' => [Events::Assist],
|
|
17
17
|
'killed' => [Events::Kill],
|
|
@@ -43,7 +43,7 @@ module TF2LineParser
|
|
|
43
43
|
'Round_Setup_End' => [Events::RoundSetupEnd],
|
|
44
44
|
'Mini_Round_Start' => [Events::MiniRoundStart],
|
|
45
45
|
'Mini_Round_Selected' => [Events::MiniRoundSelected],
|
|
46
|
-
'Intermission_Win_Limit' => [Events::IntermissionWinLimit],
|
|
46
|
+
'Intermission_Win_Limit' => [Events::WorldIntermissionWinLimit, Events::IntermissionWinLimit],
|
|
47
47
|
'Round_Stalemate' => [Events::RoundStalemate],
|
|
48
48
|
'Game_Over' => [Events::MatchEnd],
|
|
49
49
|
'connected, address' => [Events::Connect],
|
|
@@ -70,7 +70,13 @@ module TF2LineParser
|
|
|
70
70
|
# Class method to parse without object allocation
|
|
71
71
|
def self.parse(line)
|
|
72
72
|
types = find_candidate_types(line)
|
|
73
|
-
try_parse_types(line, types)
|
|
73
|
+
result = try_parse_types(line, types)
|
|
74
|
+
return result if result
|
|
75
|
+
|
|
76
|
+
# If candidate types didn't match, fall back to Unknown (unless we already tried fallbacks)
|
|
77
|
+
return nil if types == FALLBACK_TYPES
|
|
78
|
+
|
|
79
|
+
try_parse_types(line, [Events::Unknown])
|
|
74
80
|
end
|
|
75
81
|
|
|
76
82
|
class << self
|
|
@@ -84,8 +90,17 @@ module TF2LineParser
|
|
|
84
90
|
end_idx = line.index('"', start_idx + 11)
|
|
85
91
|
if end_idx
|
|
86
92
|
keyword = line[start_idx + 11...end_idx]
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
result = KEYWORD_DISPATCH[keyword]
|
|
94
|
+
if result
|
|
95
|
+
case result
|
|
96
|
+
when :check_damage_subtypes
|
|
97
|
+
return check_damage_subtypes(line)
|
|
98
|
+
when :check_heal_subtypes
|
|
99
|
+
return check_heal_subtypes(line)
|
|
100
|
+
else
|
|
101
|
+
return result
|
|
102
|
+
end
|
|
103
|
+
end
|
|
89
104
|
end
|
|
90
105
|
end
|
|
91
106
|
end
|
|
@@ -133,6 +148,32 @@ module TF2LineParser
|
|
|
133
148
|
end
|
|
134
149
|
nil
|
|
135
150
|
end
|
|
151
|
+
|
|
152
|
+
def check_damage_subtypes(line)
|
|
153
|
+
damage_attr_pos = line.index('(damage "')
|
|
154
|
+
return [Events::Damage] unless damage_attr_pos
|
|
155
|
+
|
|
156
|
+
suffix = line[damage_attr_pos..-1]
|
|
157
|
+
if suffix.include?('(headshot "')
|
|
158
|
+
[Events::HeadshotDamage]
|
|
159
|
+
elsif suffix.include?('(airshot "')
|
|
160
|
+
[Events::Airshot]
|
|
161
|
+
else
|
|
162
|
+
[Events::Damage]
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def check_heal_subtypes(line)
|
|
167
|
+
heal_attr_pos = line.index('(healing "')
|
|
168
|
+
return [Events::Heal] unless heal_attr_pos
|
|
169
|
+
|
|
170
|
+
suffix = line[heal_attr_pos..-1]
|
|
171
|
+
if suffix.include?('(airshot "')
|
|
172
|
+
[Events::AirshotHeal]
|
|
173
|
+
else
|
|
174
|
+
[Events::Heal]
|
|
175
|
+
end
|
|
176
|
+
end
|
|
136
177
|
end
|
|
137
178
|
end
|
|
138
179
|
end
|
|
@@ -456,6 +456,12 @@ module TF2LineParser
|
|
|
456
456
|
parse(line)
|
|
457
457
|
end
|
|
458
458
|
|
|
459
|
+
it 'recognizes world intermission win limit' do
|
|
460
|
+
line = 'L 01/24/2026 - 15:30:45: World triggered "Intermission_Win_Limit"'
|
|
461
|
+
expect(Events::WorldIntermissionWinLimit).to receive(:new).with(anything)
|
|
462
|
+
parse(line)
|
|
463
|
+
end
|
|
464
|
+
|
|
459
465
|
it 'recognizes ubercharges' do
|
|
460
466
|
line = log_lines[1416]
|
|
461
467
|
name = 'broder mirelin'
|
|
@@ -731,6 +737,16 @@ module TF2LineParser
|
|
|
731
737
|
parse(line)
|
|
732
738
|
end
|
|
733
739
|
|
|
740
|
+
it 'falls back to Unknown when keyword matches but regex does not' do
|
|
741
|
+
# A triggered event with a recognized keyword but unrecognized format should
|
|
742
|
+
# fall back to Unknown instead of returning nil
|
|
743
|
+
line = 'L 01/24/2026 - 15:30:45: Something triggered "Round_Win" with unexpected format'
|
|
744
|
+
time = '01/24/2026 - 15:30:45'
|
|
745
|
+
unknown = 'Something triggered "Round_Win" with unexpected format'
|
|
746
|
+
expect(Events::Unknown).to receive(:new).with(time, unknown)
|
|
747
|
+
parse(line)
|
|
748
|
+
end
|
|
749
|
+
|
|
734
750
|
it 'can parse all lines in the example log files without exploding' do
|
|
735
751
|
broder_vs_epsilon = File.expand_path('../../fixtures/logs/broder_vs_epsilon.log', __dir__)
|
|
736
752
|
special_characters = File.expand_path('../../fixtures/logs/special_characters.log', __dir__)
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tf2_line_parser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Arie
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2026-01-24 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: coveralls_reborn
|
|
@@ -75,6 +74,7 @@ files:
|
|
|
75
74
|
- ".coverage"
|
|
76
75
|
- ".gitignore"
|
|
77
76
|
- ".rspec"
|
|
77
|
+
- ".tool-versions"
|
|
78
78
|
- ".travis.yml"
|
|
79
79
|
- Gemfile
|
|
80
80
|
- Gemfile.lock
|
|
@@ -135,6 +135,7 @@ files:
|
|
|
135
135
|
- lib/tf2_line_parser/events/spawn.rb
|
|
136
136
|
- lib/tf2_line_parser/events/suicide.rb
|
|
137
137
|
- lib/tf2_line_parser/events/unknown.rb
|
|
138
|
+
- lib/tf2_line_parser/events/world_intermission_win_limit.rb
|
|
138
139
|
- lib/tf2_line_parser/line.rb
|
|
139
140
|
- lib/tf2_line_parser/parser.rb
|
|
140
141
|
- lib/tf2_line_parser/player.rb
|
|
@@ -156,7 +157,6 @@ files:
|
|
|
156
157
|
homepage: http://github.com/Arie/tf2_line_parser
|
|
157
158
|
licenses: []
|
|
158
159
|
metadata: {}
|
|
159
|
-
post_install_message:
|
|
160
160
|
rdoc_options: []
|
|
161
161
|
require_paths:
|
|
162
162
|
- lib
|
|
@@ -171,8 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
171
171
|
- !ruby/object:Gem::Version
|
|
172
172
|
version: '0'
|
|
173
173
|
requirements: []
|
|
174
|
-
rubygems_version:
|
|
175
|
-
signing_key:
|
|
174
|
+
rubygems_version: 4.0.3
|
|
176
175
|
specification_version: 4
|
|
177
176
|
summary: TF2 log line parser
|
|
178
177
|
test_files:
|