User:Jules/pymongo

From XPUB & Lens-Based wiki
< User:Jules
Revision as of 12:38, 22 November 2015 by Jules (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
import pymongo, sys
from math import sqrt
from pymongo import MongoClient
client = MongoClient()
#client = MongoClient('localhost',27017)

db = client.poetic_geoips
collection = db.ips

#precision
thresh = 0.00001

keep = []

a = 1
b = 2
c = 0

bot = sqrt(a*a + b*b)
for d in collection.find():
	lat,lon = d['coordinates']
	ip = d['ip']
	# print >> sys.stderr, "lat,lon", lat, lon
	top = abs((a*lat)+(b*lon)+c)
	dist = top / bot
	if (abs(dist) < thresh) and lat != 0.0 and lon != 0.0:
		print >> sys.stderr, "hit", lat, lon, ip


As a result for a diagonal such as:
abs((1*lat)+(2*lon)+1)
with thresh = 0.001


Result.png