csgolytics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +7 -0
- data/README.md +99 -0
- data/bin/csgolytics-import +89 -0
- data/db/csgo_assists.sql +13 -0
- data/db/csgo_frags.sql +17 -0
- data/lib/csgolytics/feed_upload.rb +53 -0
- data/lib/csgolytics/http_server.rb +41 -0
- data/lib/csgolytics/log_listener.rb +62 -0
- data/lib/csgolytics/log_parser.rb +79 -0
- data/lib/csgolytics/log_reader.rb +75 -0
- data/lib/csgolytics/schema_manager.rb +44 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3660933561cc7673f3b1eda381fc034a06d575a0
|
4
|
+
data.tar.gz: 01d2a323968d64b29d731952dcdc71910e92044f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df2675b4924ea7fb7297885bfeb18174fe77675ceedacbca8b0d1a1d511a84aeac03d18b5521f44b82f7fc36dd59b6dd805baac646fad23e8f2159c1dfc038e2
|
7
|
+
data.tar.gz: 1e26a07e7b195c4170213b7afb4082a5828eac5e2ba9d0c76795d2f0cc937e611f34bd1ff53b15933605157f5ae13e08266d754aac83034d5d56f26ad14e825c
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2016 Paul Asmuth
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy and modify copies of the Software, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
CSGOLytics
|
2
|
+
==========
|
3
|
+
|
4
|
+
CSGOLytics imports the Valve SRCDS/CS:GO (Counter Strike Global Offense) server logfile and writes all game events as structured data (JSON) into a backend database ([EventQL](https://eventql.io/)).
|
5
|
+
|
6
|
+
![Screenshot](https://raw.githubusercontent.com/paulasmuth/csgolytics/master/screenshot.png)
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
The most simple way to install CSGOLytics is by using rubygems:
|
12
|
+
|
13
|
+
$ gem install csgolytics
|
14
|
+
|
15
|
+
Usage
|
16
|
+
-----
|
17
|
+
|
18
|
+
CSGOLytics requires a running [EventQL](https://eventql.io/) database. To use CSGOLytics, you also have to enable detailed logging in your dedicated server. You can either execute these lines via rcon or put them into your `autoexec.cfg` file.
|
19
|
+
|
20
|
+
> rcon log on
|
21
|
+
> rcon mp_logdetail 3
|
22
|
+
|
23
|
+
#### Sending log data via logtail
|
24
|
+
|
25
|
+
The preferred way of importing the CS:GO logfiles is by using the included `csgolytics-import` tool. To start the import tool, execute this command:
|
26
|
+
|
27
|
+
$ ./csgolytics-import \
|
28
|
+
--logdir /path/to/csgo/server/csgo/logs \
|
29
|
+
--eventql_host localhost \
|
30
|
+
--eventql_port 9175 \
|
31
|
+
--eventql_database csgolytics
|
32
|
+
|
33
|
+
#### Sending log data via UDP
|
34
|
+
|
35
|
+
Alternatively, you can use the built-in remote logging support to receive the log data via udp. However this is less reliable. To use UDP logging, start the import tool with this command.
|
36
|
+
|
37
|
+
$ ./csgolytics-import \
|
38
|
+
--listen_udp 0.0.0.0:3764 \
|
39
|
+
--eventql_host localhost \
|
40
|
+
--eventql_port 9175 \
|
41
|
+
--eventql_database csgolytics
|
42
|
+
|
43
|
+
|
44
|
+
Then execute this line via rcon or put it into the `autoexec.cfg` file (replace x.x.x.x with the address on which csgolytics-import is listening for udp packets)
|
45
|
+
|
46
|
+
> rcon logaddress_add x.x.x.x:3764
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
Game Events (JSON)
|
51
|
+
------------------
|
52
|
+
|
53
|
+
#### Frag Event (csgo_frags)
|
54
|
+
|
55
|
+
{
|
56
|
+
"event":"frag",
|
57
|
+
"time":"2016-12-18T11:51:19Z",
|
58
|
+
"attacker_name":"le_fnord",
|
59
|
+
"attacker_steamid":"STEAM_1:0:123456789",
|
60
|
+
"attacker_team":"CT",
|
61
|
+
"attacker_coords_x":-285,
|
62
|
+
"attacker_coords_y":343,
|
63
|
+
"attacker_coords_z":1,
|
64
|
+
"victim_name":"Allen",
|
65
|
+
"victim_steamid":"BOT",
|
66
|
+
"victim_team":"T",
|
67
|
+
"victim_coords_x":-282,
|
68
|
+
"victim_coords_y":424,
|
69
|
+
"victim_coords_z":125,
|
70
|
+
"weapon":"ak47",
|
71
|
+
"headshot":false,
|
72
|
+
"penetrated":false,
|
73
|
+
"server_id":"aim"
|
74
|
+
}
|
75
|
+
|
76
|
+
#### Assist Event (csgo_assists)
|
77
|
+
|
78
|
+
{
|
79
|
+
"event":"assist",
|
80
|
+
"time":"2016-12-18T11:51:19Z",
|
81
|
+
"attacker_name":"le_fnord",
|
82
|
+
"attacker_steamid":"STEAM_1:0:123456789",
|
83
|
+
"attacker_team":"CT",
|
84
|
+
"victim_name":"Allen",
|
85
|
+
"victim_steamid":"BOT",
|
86
|
+
"victim_team":"T"
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
License
|
91
|
+
-------
|
92
|
+
|
93
|
+
Copyright (c) 2016 Paul Asmuth
|
94
|
+
|
95
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
96
|
+
|
97
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
98
|
+
|
99
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << ::File::expand_path("../../lib", __FILE__)
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "yaml"
|
6
|
+
require 'optparse'
|
7
|
+
require 'eventql'
|
8
|
+
require 'webrick'
|
9
|
+
require "csgolytics/schema_manager"
|
10
|
+
require "csgolytics/feed_upload"
|
11
|
+
require "csgolytics/log_reader"
|
12
|
+
|
13
|
+
# parse flags
|
14
|
+
flags = {}
|
15
|
+
|
16
|
+
flag_parser = OptionParser.new do |opts|
|
17
|
+
opts.banner = "Usage: csgolytics [options]"
|
18
|
+
|
19
|
+
opts.on("--logdir=PATH", "/path/to/csgo/log") do |val|
|
20
|
+
flags[:logdir] = val
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("--server_id=ID", "my_csgo_server_id") do |val|
|
24
|
+
flags[:server_id] = val
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("--eventql_host=HOST", "EventQL host") do |val|
|
28
|
+
flags[:eventql_host] = val
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("--eventql_port=PORT", "EventQL port") do |val|
|
32
|
+
flags[:eventql_port] = val
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("--eventql_database=DATABASE", "EventQL database") do |val|
|
36
|
+
flags[:eventql_database] = val
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("--eventql_auth_token=TOKEN", "EventQL auth_token") do |val|
|
40
|
+
flags[:eventql_auth_token] = val
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("-v", "--[no-]verbose", "Print debug output") do |val|
|
44
|
+
flags[:verbose] = val
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("-h", "--help", "You're reading it") do
|
48
|
+
puts opts
|
49
|
+
exit 0
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
flag_parser.parse!
|
55
|
+
|
56
|
+
# check arguments
|
57
|
+
unless File.directory?(flags[:logdir])
|
58
|
+
$stderr.puts "ERROR: #{flags[:logdir]} is not a directory"
|
59
|
+
exit 1
|
60
|
+
end
|
61
|
+
|
62
|
+
# init eventql client
|
63
|
+
$stderr.puts "Connecting to EventQL at #{flags[:eventql_host]}"
|
64
|
+
db = EventQL.connect(
|
65
|
+
:host => flags[:eventql_host],
|
66
|
+
:port => flags[:eventql_port],
|
67
|
+
:database => flags[:eventql_database],
|
68
|
+
:auth_token => flags[:eventql_auth_token]
|
69
|
+
)
|
70
|
+
|
71
|
+
# migrate database
|
72
|
+
schema_manager = CSGOLytics::SchemaManager.new(
|
73
|
+
db,
|
74
|
+
::File::expand_path("../../db", __FILE__))
|
75
|
+
|
76
|
+
schema_manager.migrate!
|
77
|
+
|
78
|
+
# start feed upload
|
79
|
+
feed_upload = CSGOLytics::FeedUpload.new(db, flags[:server_id])
|
80
|
+
|
81
|
+
# start log reader
|
82
|
+
log_reader = CSGOLytics::LogReader.new(flags[:logdir])
|
83
|
+
log_reader.on_logline do |l|
|
84
|
+
feed_upload.insert_logline(l)
|
85
|
+
end
|
86
|
+
|
87
|
+
log_reader.start
|
88
|
+
|
89
|
+
|
data/db/csgo_assists.sql
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
CREATE TABLE csgo_assists (
|
2
|
+
time_key uint64,
|
3
|
+
event_id string,
|
4
|
+
server_id string,
|
5
|
+
time datetime,
|
6
|
+
attacker_name string,
|
7
|
+
attacker_steamid string,
|
8
|
+
attacker_team string,
|
9
|
+
victim_name string,
|
10
|
+
victim_steamid string,
|
11
|
+
victim_team string,
|
12
|
+
PRIMARY KEY (time_key, event_id)
|
13
|
+
) WITH user_defined_partitions = "true";
|
data/db/csgo_frags.sql
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
CREATE TABLE csgo_frags (
|
2
|
+
time_key uint64,
|
3
|
+
event_id string,
|
4
|
+
server_id string,
|
5
|
+
time datetime,
|
6
|
+
attacker_name string,
|
7
|
+
attacker_steamid string,
|
8
|
+
attacker_team string,
|
9
|
+
victim_name string,
|
10
|
+
victim_steamid string,
|
11
|
+
victim_team string,
|
12
|
+
weapon string,
|
13
|
+
headshoot bool,
|
14
|
+
penetrated bool,
|
15
|
+
distance double,
|
16
|
+
PRIMARY KEY (time_key, event_id)
|
17
|
+
) WITH user_defined_partitions = "true";
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "securerandom"
|
2
|
+
require "csgolytics/log_parser"
|
3
|
+
|
4
|
+
module CSGOLytics; end
|
5
|
+
|
6
|
+
class CSGOLytics::FeedUpload
|
7
|
+
|
8
|
+
PARTITION_SIZE = 3600 * 24
|
9
|
+
|
10
|
+
EVENT_TABLE_MAP = {
|
11
|
+
"frag" => "csgo_frags",
|
12
|
+
"assist" => "csgo_assists"
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(db, server_id = nil)
|
16
|
+
@db = db
|
17
|
+
@server_id = server_id
|
18
|
+
@log_parser = CSGOLytics::LogParser.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def insert_logline(logline, event_id = nil)
|
22
|
+
ev = @log_parser.parse(logline)
|
23
|
+
unless ev
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
if event_id
|
28
|
+
ev[:event_id] = event_id
|
29
|
+
else
|
30
|
+
ev[:event_id] = Digest::SHA1.hexdigest logline
|
31
|
+
end
|
32
|
+
|
33
|
+
if @server_id
|
34
|
+
ev[:server_id] = @server_id
|
35
|
+
end
|
36
|
+
|
37
|
+
upload_event(ev)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def upload_event(ev)
|
43
|
+
table = EVENT_TABLE_MAP[ev[:event]]
|
44
|
+
unless table
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
48
|
+
ev[:time_key] = (Time.parse(ev[:time]).to_i / PARTITION_SIZE) * PARTITION_SIZE
|
49
|
+
|
50
|
+
@db.insert!([{ :table => table, :database => @db.get_database, :data => ev }])
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module CSGOLytics; end
|
2
|
+
|
3
|
+
class CSGOLytics::HTTPServlet < WEBrick::HTTPServlet::AbstractServlet
|
4
|
+
|
5
|
+
def initialize(server, backend)
|
6
|
+
super server
|
7
|
+
@backend = backend
|
8
|
+
end
|
9
|
+
|
10
|
+
def do_POST (request, response)
|
11
|
+
if request.path == "/api/v1/insert_logline"
|
12
|
+
@backend.insert_logline request.body.force_encoding("utf-8")
|
13
|
+
response.status = 201
|
14
|
+
response.body = "ok"
|
15
|
+
response.content_type = "text/plan"
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
response.status = 404
|
20
|
+
response.body = "not found"
|
21
|
+
response.content_type = "text/plan"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class CSGOLytics::HTTPServer
|
27
|
+
|
28
|
+
def initialize(backend, port)
|
29
|
+
@http = WEBrick::HTTPServer.new(:Port => port)
|
30
|
+
@http.mount "/", CSGOLytics::HTTPServlet, backend
|
31
|
+
end
|
32
|
+
|
33
|
+
def listen
|
34
|
+
@http.start
|
35
|
+
end
|
36
|
+
|
37
|
+
def shutdown
|
38
|
+
@http.shutdown
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "socket"
|
2
|
+
|
3
|
+
module CSGOLytics; end
|
4
|
+
|
5
|
+
class CSGOLytics::LogListener
|
6
|
+
|
7
|
+
REMOTE_LOG_PKT_HEADER = "\xff\xff\xff\xffR"
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@ssock = UDPSocket.new
|
11
|
+
@ssock.bind("0.0.0.0", 3764)
|
12
|
+
@callbacks = []
|
13
|
+
|
14
|
+
@remotes_map = {}
|
15
|
+
config["servers"].each do |server|
|
16
|
+
server["remote_addrs"].each do |remote_addr|
|
17
|
+
@remotes_map[remote_addr] = server["server_id"]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def listen
|
23
|
+
while msg = @ssock.recvfrom(0xffff)
|
24
|
+
payload, raddr = msg
|
25
|
+
payload = payload.force_encoding("utf-8")
|
26
|
+
|
27
|
+
remote_addrs = [
|
28
|
+
"#{raddr[2]}:#{raddr[1]}",
|
29
|
+
"#{raddr[3]}:#{raddr[1]}"
|
30
|
+
].uniq
|
31
|
+
|
32
|
+
remote_server_id = nil
|
33
|
+
remote_addrs.each do |r|
|
34
|
+
remote_server_id ||= @remotes_map[r]
|
35
|
+
end
|
36
|
+
|
37
|
+
unless remote_server_id
|
38
|
+
$stderr.puts "WARNING: unknown server: #{remote_addrs.inspect}"
|
39
|
+
next
|
40
|
+
end
|
41
|
+
|
42
|
+
unless payload.start_with?(REMOTE_LOG_PKT_HEADER)
|
43
|
+
$stderr.puts "WARNING: received invalid log packet"
|
44
|
+
next
|
45
|
+
end
|
46
|
+
|
47
|
+
logline = payload[REMOTE_LOG_PKT_HEADER.length..-1]
|
48
|
+
while ["\0", "\r", "\n"].include?(logline[-1])
|
49
|
+
logline = logline[0..-2]
|
50
|
+
end
|
51
|
+
|
52
|
+
@callbacks.each do |cb|
|
53
|
+
cb[logline, remote_server_id]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def on_logline(&cb)
|
59
|
+
@callbacks << cb
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "socket"
|
2
|
+
require "date"
|
3
|
+
require "time"
|
4
|
+
|
5
|
+
module CSGOLytics; end
|
6
|
+
|
7
|
+
class CSGOLytics::LogParser
|
8
|
+
|
9
|
+
def parse(line)
|
10
|
+
ev = nil
|
11
|
+
return ev if ev = parse_frag(line)
|
12
|
+
return ev if ev = parse_assist(line)
|
13
|
+
return ev
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def parse_frag(line)
|
19
|
+
r = /^L (?<time>\d{2}\/\d{2}\/\d{4} - \d{2}:\d{2}:\d{2}): "(?<attacker_name>.*)<\d+><(?<attacker_steamid>BOT|(STEAM_\d+:\d+:\d+))><(?<attacker_team>CT|TERRORIST)>" \[(?<attacker_coords>-?\d+ -?\d+ -?\d+)\] killed "(?<victim_name>.*)<\d+><(?<victim_steamid>BOT|(STEAM_\d+:\d+:\d+))><(?<victim_team>CT|TERRORIST)>" \[(?<victim_coords>-?\d+ -?\d+ -?\d+)\] with "(?<weapon>\w+)" ?\(?(?<headshot>headshot)? ?(?<penetrated>penetrated)?\)?$/
|
20
|
+
|
21
|
+
m = r.match(line)
|
22
|
+
if m
|
23
|
+
attacker_coords = m[:attacker_coords].split
|
24
|
+
victim_coords = m[:victim_coords].split
|
25
|
+
|
26
|
+
return {
|
27
|
+
:event => "frag",
|
28
|
+
:time => parse_time(m[:time]).utc.iso8601,
|
29
|
+
:attacker_name => m[:attacker_name],
|
30
|
+
:attacker_steamid => m[:attacker_steamid],
|
31
|
+
:attacker_team => normalize_team(m[:attacker_team]),
|
32
|
+
:attacker_coords_x => attacker_coords[0].to_i,
|
33
|
+
:attacker_coords_y => attacker_coords[1].to_i,
|
34
|
+
:attacker_coords_z => attacker_coords[2].to_i,
|
35
|
+
:victim_name => m[:victim_name],
|
36
|
+
:victim_steamid => m[:victim_steamid],
|
37
|
+
:victim_team => normalize_team(m[:victim_team]),
|
38
|
+
:victim_coords_x => victim_coords[0].to_i,
|
39
|
+
:victim_coords_y => victim_coords[1].to_i,
|
40
|
+
:victim_coords_z => victim_coords[2].to_i,
|
41
|
+
:weapon => m[:weapon],
|
42
|
+
:headshot => !!m[:headshot],
|
43
|
+
:penetrated => !!m[:penetrated]
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_assist(line)
|
49
|
+
r = /^L (?<time>\d{2}\/\d{2}\/\d{4} - \d{2}:\d{2}:\d{2}): "(?<attacker_name>.*)<\d+><(?<attacker_steamid>BOT|(STEAM_\d+:\d+:\d+))><(?<attacker_team>CT|TERRORIST)>" assisted killing "(?<victim_name>.*)<\d+><(?<victim_steamid>BOT|(STEAM_\d+:\d+:\d+))><(?<victim_team>CT|TERRORIST)>"$/
|
50
|
+
|
51
|
+
m = r.match(line)
|
52
|
+
if m
|
53
|
+
return {
|
54
|
+
:event => "assist",
|
55
|
+
:time => parse_time(m[:time]).utc.iso8601,
|
56
|
+
:attacker_name => m[:attacker_name],
|
57
|
+
:attacker_steamid => m[:attacker_steamid],
|
58
|
+
:attacker_team => normalize_team(m[:attacker_team]),
|
59
|
+
:victim_name => m[:victim_name],
|
60
|
+
:victim_steamid => m[:victim_steamid],
|
61
|
+
:victim_team => normalize_team(m[:victim_team])
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def parse_time(time_str)
|
67
|
+
DateTime.strptime("#{time_str} #{Time.now.strftime("%:z")}", "%m/%d/%Y - %H:%M:%S %z").to_time
|
68
|
+
end
|
69
|
+
|
70
|
+
def normalize_team(team)
|
71
|
+
case team
|
72
|
+
when "CT" then return "CT"
|
73
|
+
when "T" then return "T"
|
74
|
+
when "TERRORIST" then return "T"
|
75
|
+
else return "?"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require 'optparse'
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'digest/sha1'
|
6
|
+
|
7
|
+
module CSGOLytics; end
|
8
|
+
|
9
|
+
class CSGOLytics::LogReader
|
10
|
+
|
11
|
+
POLL_INTERVAL = 1
|
12
|
+
|
13
|
+
def initialize(logdir)
|
14
|
+
@logdir = logdir
|
15
|
+
@callbacks = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_logline(&cb)
|
19
|
+
@callbacks << cb
|
20
|
+
end
|
21
|
+
|
22
|
+
def start
|
23
|
+
# tail the logfiles
|
24
|
+
loop do
|
25
|
+
begin
|
26
|
+
# list all logfiles
|
27
|
+
@logfiles = {}
|
28
|
+
@logfiles_completed = {}
|
29
|
+
Dir.entries(@logdir).each do |f|
|
30
|
+
if f.end_with?(".log")
|
31
|
+
@logfiles[f] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
if f =~ /^\.(.*\.log)\.csgolytics_complete$/
|
35
|
+
@logfiles_completed[$1] = true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@logfiles = (@logfiles.keys - @logfiles_completed.keys).sort
|
40
|
+
|
41
|
+
# read each logfile from the last offset and upload new lines
|
42
|
+
@logfiles.each_with_index do |fname, logfile_index|
|
43
|
+
fpath = File.join(@logdir, fname)
|
44
|
+
offset_file_path = File.join(@logdir, ".#{fname}.csgolytics_offset")
|
45
|
+
offset = 0
|
46
|
+
if File.exists?(offset_file_path)
|
47
|
+
offset = IO.read(offset_file_path).to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
puts "Reading #{fpath} from #{offset}"
|
51
|
+
|
52
|
+
f = File.open(fpath)
|
53
|
+
f.seek(offset)
|
54
|
+
while l = (f.readline rescue nil)
|
55
|
+
@callbacks.each do |cb|
|
56
|
+
cb[l.chomp]
|
57
|
+
end
|
58
|
+
|
59
|
+
File.write(offset_file_path + "~", f.tell)
|
60
|
+
FileUtils.mv(offset_file_path + "~", offset_file_path)
|
61
|
+
end
|
62
|
+
|
63
|
+
if logfile_index < @logfiles.length - 1
|
64
|
+
FileUtils.touch(File.join(@logdir, ".#{fname}.csgolytics_complete"))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
rescue Exception => e
|
68
|
+
$stderr.puts "ERROR: #{e.to_s}"
|
69
|
+
end
|
70
|
+
|
71
|
+
sleep POLL_INTERVAL
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "socket"
|
2
|
+
|
3
|
+
module CSGOLytics; end
|
4
|
+
|
5
|
+
class CSGOLytics::SchemaManager
|
6
|
+
|
7
|
+
def initialize(db, schema_path)
|
8
|
+
@db = db
|
9
|
+
@schema_path = schema_path
|
10
|
+
|
11
|
+
@tables = []
|
12
|
+
Dir.entries(schema_path).each do |tbl|
|
13
|
+
next if tbl.start_with?(".")
|
14
|
+
|
15
|
+
if tbl =~ /(\w+)\.sql/
|
16
|
+
@tables << $1
|
17
|
+
else
|
18
|
+
$stderr.puts "ERROR: invalid table schema file #{tbl}"
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def migrate!
|
25
|
+
$stderr.puts "Migrating database schemas, this may take a second"
|
26
|
+
list_tables_qry = @db.query("show tables;")
|
27
|
+
list_tables_res = list_tables_qry.execute!
|
28
|
+
|
29
|
+
actual_tables = list_tables_res[0]["rows"].map(&:first)
|
30
|
+
(@tables - actual_tables).each do |tbl|
|
31
|
+
create_table!(tbl)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def create_table!(tbl)
|
38
|
+
$stderr.puts "Creating table: #{tbl}"
|
39
|
+
create_table_sql = IO.read(File::join(@schema_path, tbl + ".sql"))
|
40
|
+
create_table_qry = @db.query(create_table_sql)
|
41
|
+
create_table_qry.execute!
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: csgolytics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Asmuth
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: CS:GO Analaytics with EventQL
|
14
|
+
email: paul@eventql.io
|
15
|
+
executables:
|
16
|
+
- csgolytics-import
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- bin/csgolytics-import
|
23
|
+
- db/csgo_assists.sql
|
24
|
+
- db/csgo_frags.sql
|
25
|
+
- lib/csgolytics/feed_upload.rb
|
26
|
+
- lib/csgolytics/http_server.rb
|
27
|
+
- lib/csgolytics/log_listener.rb
|
28
|
+
- lib/csgolytics/log_parser.rb
|
29
|
+
- lib/csgolytics/log_reader.rb
|
30
|
+
- lib/csgolytics/schema_manager.rb
|
31
|
+
homepage: http://github.com/eventql/eventql
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata: {}
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 2.5.1
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: CS:GO Analaytics with EventQL
|
55
|
+
test_files: []
|