Created
September 8, 2014 15:41
-
-
Save fuchsi/e7e59e08ffcc729c0c7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'mongo' | |
require 'date' | |
require 'awesome_print' | |
## Messages | |
# captured | |
# destroyed an | |
# deployed an | |
# created a Control Field @ | |
# destroyed a Control Field @ | |
# linked | |
# destroyed the Link | |
module Intel | |
include Mongo | |
mongo_client = MongoClient.new("localhost", 27017) | |
db = mongo_client.db("ingress") | |
coll = db.collection("Chat.Public") | |
actions = { | |
captured: 0, | |
destroyed: 0, | |
deployed: 0, | |
field_created: 0, | |
field_destroyed: 0, | |
link_created: 0, | |
link_destroyed: 0 | |
} | |
deployed = {} | |
destroyed = {} | |
resos = %w(L1 L2 L3 L4 L5 L6 L7 L8) | |
want_player = ARGV[0] | |
start_date = DateTime.strptime(ARGV[1], '%Y-%m-%d') | |
timestamp = (start_date.to_time.to_i * 1000) | |
puts "stats for #{want_player} since " + start_date.to_s | |
coll.find({ 'markup.PLAYER1.plain' => want_player, 'time' => { '$gt' => timestamp } }).each do |row| | |
player = row['markup']['PLAYER1']['plain'] | |
unless row['markup'].has_key? 'TEXT1' | |
next | |
end | |
unless row['markup']['TEXT1'].has_key? 'plain' | |
next | |
end | |
message = row['markup']['TEXT1']['plain'] | |
if player == want_player | |
case message | |
when ' captured ' | |
actions[:captured] += 1 | |
when ' destroyed an ' | |
actions[:destroyed] += 1 | |
reso = row['markup']['TEXT2']['plain'] | |
unless destroyed.has_key? reso | |
destroyed[reso] = 0 | |
end | |
destroyed[reso] += 1 | |
when ' deployed an ' | |
actions[:deployed] += 1 | |
reso = row['markup']['TEXT2']['plain'] | |
unless deployed.has_key? reso | |
deployed[reso] = 0 | |
end | |
deployed[reso] += 1 | |
when ' created a Control Field @' | |
actions[:field_created] += 1 | |
when ' destroyed a Control Field @' | |
actions[:field_destroyed] += 1 | |
when ' linked ' | |
actions[:link_created] += 1 | |
when ' destroyed the Link ' | |
actions[:link_destroyed] += 1 | |
end | |
end | |
end | |
#ap actions | |
puts "captured #{actions[:captured]} portals" | |
puts "deployed #{actions[:deployed]} resonators" | |
puts "destroyed #{actions[:destroyed]} resonators" | |
puts "created #{actions[:link_created]} links" | |
puts "destroyed #{actions[:link_destroyed]} links" | |
puts "created #{actions[:field_created]} fields" | |
puts "destroyed #{actions[:field_destroyed]} fields" | |
puts "\ndeploy stats" | |
resos.each do |reso| | |
puts "#{reso}: #{deployed[reso]}" | |
end | |
puts "\ndestroy stats" | |
resos.each do |reso| | |
puts "#{reso}: #{destroyed[reso]}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'mongo' | |
require 'date' | |
require 'awesome_print' | |
module Intel | |
include Mongo | |
class Point | |
attr_accessor :x | |
attr_accessor :y | |
def initialize(x,y) | |
@x = x | |
@y = y | |
end | |
end | |
class Polygon | |
attr_accessor :points | |
def initialize(points) | |
@points = points | |
end | |
def contains_point?(point) | |
contains_point = false | |
i = -1 | |
j = @points.size - 1 | |
while (i += 1) < @points.size | |
a_point_on_polygon = @points[i] | |
trailing_point_on_polygon = @points[j] | |
if point_is_between_the_ys_of_the_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon) | |
if ray_crosses_through_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon) | |
contains_point = !contains_point | |
end | |
end | |
j = i | |
end | |
return contains_point | |
end | |
private | |
def point_is_between_the_ys_of_the_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon) | |
(a_point_on_polygon.y <= point.y && point.y < trailing_point_on_polygon.y) || | |
(trailing_point_on_polygon.y <= point.y && point.y < a_point_on_polygon.y) | |
end | |
def ray_crosses_through_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon) | |
(point.x < (trailing_point_on_polygon.x - a_point_on_polygon.x) * (point.y - a_point_on_polygon.y) / | |
(trailing_point_on_polygon.y - a_point_on_polygon.y) + a_point_on_polygon.x) | |
end | |
end | |
mongo_client = MongoClient.new("localhost", 27017) | |
db = mongo_client.db("ingress") | |
coll = db.collection("Chat.Public") | |
start_date = DateTime.strptime(ARGV[0], '%Y-%m-%d') | |
timestamp = (start_date.to_time.to_i * 1000) | |
end_date = start_date << -1 | |
timestamp_end = (end_date.to_time.to_i * 1000) | |
players = {} | |
total = 0 | |
cond = { | |
'markup.TEXT1.plain' => ' destroyed an ', | |
'markup.TEXT2.plain' => 'L8', | |
'time' => { '$ge' => timestamp }, | |
'time' => { '$lt' => timestamp_end } | |
} | |
case ARGV[1] | |
when "heilbronn" | |
location = [[49.117927873763634,9.14834976196289],[49.10118443594031,9.172039031982422],[49.11657961817908,9.223709106445312],[49.11534368503192,9.253406524658203],[49.13050982532791,9.269542694091797],[49.16329776043147,9.238815307617188],[49.160603679993315,9.189891815185547]] | |
loc = "Heilbronn" | |
when "brackenheim" | |
location = [[49.09345695129238,9.077668190002441],[49.07903846447682,9.058184623718262],[49.071757365026,9.058399200439453],[49.07085769565072,9.066081047058105],[49.079319566609286,9.079427719116211],[49.09101200564338,9.084792137145996]] | |
loc = "Brackenheim" | |
else | |
location = [] | |
loc = "NR01-GOLF-11 and NR01-GOLF-12" | |
end | |
puts "top 50 R8 destroyers for #{loc} since " + start_date.to_s | |
if location.count > 0 | |
points = [] | |
location.each do |l| | |
points << Point.new(l[0], l[1]) | |
end | |
polygon = Polygon.new(points) | |
end | |
coll.find(cond).each do |row| | |
player = row['markup']['PLAYER1']['plain'] | |
if location.count > 0 | |
x = row['markup']['PORTAL1']['latE6'].fdiv 1000000 | |
y = row['markup']['PORTAL1']['lngE6'].fdiv 1000000 | |
point = Point.new(x,y) | |
unless polygon.contains_point?(point) | |
next | |
end | |
#puts row['text'] | |
end | |
unless players.has_key? player | |
players[player] = {num: 0, faction: row['markup']['PLAYER1']['team']} | |
end | |
players[player][:num] += 1 | |
total += 1 | |
end | |
top = players.sort {|a, b| b[1][:num] <=> a[1][:num] } | |
top[0, 50].each do |p| | |
percent = (p[1][:num].fdiv(total) * 100).round(2) | |
puts "#{p[0]} (#{p[1][:faction][0]}): #{p[1][:num]} (#{percent}%)" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment