83 lines
1.8 KiB
Python
83 lines
1.8 KiB
Python
from variables import letras, meses
|
|
import math
|
|
|
|
def signoLetra(signo1, signo2):
|
|
if signo1 == '+':
|
|
letra1 = 'N'
|
|
else:
|
|
letra1 = 'S'
|
|
|
|
if signo2 == '+':
|
|
letra2 = 'E'
|
|
else:
|
|
letra2 = 'W'
|
|
|
|
return letra1, letra2
|
|
|
|
def letraSigno(letra):
|
|
if letra == 'N' or letra == 'E':
|
|
signo = '+'
|
|
elif letra == 'S' or letra == 'W':
|
|
signo = '-'
|
|
|
|
else:
|
|
return None
|
|
|
|
return signo
|
|
|
|
def decimalGrado(numero):
|
|
a = float(numero)
|
|
grados = int(numero)
|
|
b = a - grados
|
|
minutos = int(b*60)
|
|
c = b*60-minutos
|
|
segundos = int(c*60)
|
|
return grados,minutos,segundos
|
|
|
|
|
|
def gradoDecimal(grados,minutos,segundos):
|
|
a = float(segundos)/3600 + float(minutos)/60 + float(grados)
|
|
return a
|
|
|
|
def comprobarLetra(dni: str):
|
|
num = int(dni[:-1])
|
|
letra = dni[-1]
|
|
if letras[num % 23] != letra:
|
|
return False
|
|
else:
|
|
return True
|
|
|
|
def convertirMes(mes):
|
|
return meses.index(mes)
|
|
|
|
def haversine(coord1, coord2):
|
|
r = 6367.45 * 1000 # conversión a metros
|
|
for i in coord1.keys():
|
|
coord1[i] = math.radians(coord1[i])
|
|
coord2[i] = math.radians(coord2[i])
|
|
|
|
dlat = coord2['latitud'] - coord1['latitud']
|
|
dlong = coord2['longitud'] - coord1['longitud']
|
|
h = math.sin(dlat / 2)**2 + math.cos(coord1['latitud']) * math.cos(coord2['latitud']) * math.sin(dlong / 2)**2
|
|
d = 2 * math.atan2(math.sqrt(h), math.sqrt(1 - h))
|
|
return d * r
|
|
|
|
def convertirSegundos(instante):
|
|
try:
|
|
int(instante['mes'])
|
|
except ValueError:
|
|
instante['mes'] = convertirMes(instante['mes'].lower())
|
|
|
|
try:
|
|
int(instante['segundo'])
|
|
|
|
except ValueError:
|
|
if instante['segundo'].lower == "pm":
|
|
instante['hora'] += 12
|
|
|
|
if instante['hora'] == 24:
|
|
instante['hora'] = 0
|
|
|
|
instante['segundo'] = 0
|
|
|
|
return instante |