Created
August 21, 2015 17:41
-
-
Save gamikun/81585df0e82323436e78 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
from __future__ import print_function | |
import sys | |
import math | |
import time | |
db = [] | |
with open("./lonlat", 'rb') as fi: | |
for l in fi: | |
p = l.split() | |
db.append((float(p[0]), float(p[1]), p[2])) | |
""" | |
Hermosillo | |
latitude = float("29.100045") | |
longitude = float("-111.007476") | |
""" | |
#Monterrey | |
latitude = float("25.666667") | |
longitude = float("-100.316667") | |
if len(sys.argv) >= 3: | |
latitude = float(sys.argv[1]) | |
longitude = float(sys.argv[2]) | |
def determine_timezone(latitude, longitude): | |
mindistance = 999999 | |
timezone = 'no se' | |
for loc in db: | |
lat, lon, name = loc | |
latdif = abs(lat - latitude) | |
londif = abs(lon - longitude) | |
rawdif = math.sqrt(pow(latdif, 2) + pow(londif, 2)) | |
if rawdif < mindistance: | |
mindistance = rawdif | |
timezone = name | |
lastrawdif = rawdif | |
return (timezone, lastrawdif) | |
if len(sys.argv) >= 4: | |
n = int(sys.argv[3]) | |
else: | |
n = 1 | |
print_stuff = '--print' in sys.argv | |
ftime = time.time() | |
for i in range(n): | |
tz, dif = determine_timezone(latitude, longitude) | |
if print_stuff: | |
print("Discrepancia: %.15f" % dif) | |
print("Zona horaria: %s" % tz) | |
ltime = time.time() - ftime | |
print("Tiempo: %.3f" % ltime) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment