add deg.py

This commit is contained in:
Motiejus Jakštys 2019-11-21 11:13:42 +02:00
parent 9810896325
commit c891d8b2d3

22
misc/deg.py Normal file
View File

@ -0,0 +1,22 @@
from decimal import Decimal as Dec
Deg = namedtuple('Deg', ['hh', 'mm', 'ss'])
def guess(inp):
if isinstance(inp, Dec):
return inp
if '-' in instr:
deg, mm, ss = instr.split('-')
ddeg, dmm, dss = Dec(deg), Dec(mm), Dec(ss)
return deg + dmm/60 + dss/3600
else:
return Dec(instr)
def hms(deg):
assert isinstance(deg, Dec)
pdeg, pmm = divmod(deg, 1)
pmm = pmm * Dec(60)
pmm, pss = divmod(pmm, 1)
pss = pss * Dec(60)
return Deg(pdeg, pmm, pss)