terminado
This commit is contained in:
83
proyecto/util.py
Normal file
83
proyecto/util.py
Normal file
@@ -0,0 +1,83 @@
|
||||
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
|
||||
dlat = coord2['latitud'] - coord1['latitud']
|
||||
dlong = coord2['latitud'] - coord1['longitud']
|
||||
|
||||
dlat = math.radians(dlat)
|
||||
dlong = math.radians(dlong)
|
||||
|
||||
h = math.sin(dlat)**2 + math.cos(dlat) * math.cos(dlong) * math.sin(dlong)**2
|
||||
d = 2 * r * math.asin(math.sqrt(h))
|
||||
return d
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user