User:Jules/pymongo: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "<source lang="python"> import pymongo, sys from math import sqrt from pymongo import MongoClient client = MongoClient() #client = MongoClient('localhost',27017) db = client.p...")
 
No edit summary
 
Line 29: Line 29:


</source>
</source>
As a result for a diagonal such as: <br />
<big>''abs((1*lat)+(2*lon)+1)''</big><br />
''with thresh = 0.001'' <br />
[[File:Result.png]]

Latest revision as of 12:38, 22 November 2015

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