mirror of
https://github.com/dh1tw/pyhamtools.git
synced 2025-12-06 06:52:00 +01:00
refined callsign algorithm
This commit is contained in:
parent
f9bd608741
commit
b4613f92e9
|
|
@ -1,6 +1,15 @@
|
|||
Changelog
|
||||
---------
|
||||
|
||||
PyHamTools 0.5.5
|
||||
================
|
||||
|
||||
18. August 2016
|
||||
|
||||
* Refined callsign detection rule for two digit prefix with appendix (e.g. 7N0ERX/1)
|
||||
* Refined callsign detection rule for callsigns with two appendixes (e.g. SV8GXQ/P/QRP)
|
||||
|
||||
|
||||
PyHamTools 0.5.4
|
||||
================
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ class Callinfo(object):
|
|||
if re.search('\-\d{1,3}$', entire_callsign): # cut off any -10 / -02 appendixes
|
||||
callsign = re.sub('\-\d{1,3}$', '', entire_callsign)
|
||||
|
||||
if re.search('/[A-Z0-9]{2,4}/[A-Z0-9]{1,4}$', callsign):
|
||||
if re.search('/[A-Z0-9]{1,4}/[A-Z0-9]{1,4}$', callsign):
|
||||
callsign = re.sub('/[A-Z0-9]{1,4}$', '', callsign) # cut off 2. appendix DH1TW/HC2/P -> DH1TW/HC2
|
||||
|
||||
# multiple character appendix (callsign/xxx)
|
||||
|
|
@ -199,8 +199,11 @@ class Callinfo(object):
|
|||
|
||||
elif re.search('\d$', appendix):
|
||||
area_nr = re.search('\d$', appendix).group(0)
|
||||
callsign = re.sub('/\d$', '', callsign)
|
||||
callsign = re.sub('[\d]+', area_nr, callsign)
|
||||
callsign = re.sub('/\d$', '', callsign) #remove /number
|
||||
if len(re.findall(r'\d+', callsign)) == 1: #call has just on digit e.g. DH1TW
|
||||
callsign = re.sub('[\d]+', area_nr, callsign)
|
||||
else: # call has several digits e.g. 7N4AAL
|
||||
pass # no (two) digit prefix contries known where appendix would change entitiy
|
||||
return self._iterate_prefix(callsign, timestamp)
|
||||
|
||||
else:
|
||||
|
|
@ -231,8 +234,8 @@ class Callinfo(object):
|
|||
# Check if operation is invalid
|
||||
invalid = False
|
||||
try:
|
||||
if self._lookuplib.is_invalid_operation(callsign, timestamp):
|
||||
invalid = True
|
||||
invalid = self._lookuplib.is_invalid_operation(callsign, timestamp)
|
||||
if invalid:
|
||||
raise KeyError
|
||||
except KeyError:
|
||||
if invalid:
|
||||
|
|
|
|||
|
|
@ -102,6 +102,23 @@ response_prefix_VK9GMW_clublog = {
|
|||
u'longitude': -155.8
|
||||
}
|
||||
|
||||
response_callsign_exceptions_7N1PRD_0_clublog = {
|
||||
u'adif': 339,
|
||||
u'continent': u'AS',
|
||||
u'country': u'JAPAN',
|
||||
u'cqz': 25,
|
||||
u'latitude': 35.7,
|
||||
u'longitude': -139.8
|
||||
}
|
||||
|
||||
response_callsign_exceptions_SV8GXQ_P_QRP_clublog = {
|
||||
u'adif': 236,
|
||||
u'continent': u'EU',
|
||||
u'country': u'GREECE',
|
||||
u'cqz': 20,
|
||||
u'latitude': 38.0,
|
||||
u'longitude': -23.7
|
||||
}
|
||||
|
||||
response_Exception_VP8STI_with_start_and_stop_date = {
|
||||
'adif': 240,
|
||||
|
|
@ -221,6 +238,8 @@ class Test_callinfo_methods:
|
|||
assert fix_callinfo._dismantle_callsign("DH1TW/NOT") == response_prefix_DH_clublog
|
||||
assert fix_callinfo._dismantle_callsign("VK9DLX/NOT") == response_prefix_VK9DLX_clublog
|
||||
assert fix_callinfo._dismantle_callsign("7QAA") == response_callsign_exceptions_7QAA_clublog
|
||||
assert fix_callinfo._dismantle_callsign("7N1PRD/0") == response_callsign_exceptions_7N1PRD_0_clublog
|
||||
assert fix_callinfo._dismantle_callsign("SV8GXQ/P/QRP") == response_callsign_exceptions_SV8GXQ_P_QRP_clublog
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
fix_callinfo._dismantle_callsign("OZ/JO85")
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from datetime import datetime
|
|||
import pytz
|
||||
import redis
|
||||
|
||||
from pyhamtools import LookupLib
|
||||
from pyhamtools import LookupLib, Callinfo
|
||||
|
||||
|
||||
UTC = pytz.UTC
|
||||
|
|
@ -13,6 +13,16 @@ UTC = pytz.UTC
|
|||
r = redis.Redis()
|
||||
|
||||
|
||||
response_Exception_VP8STI_with_start_and_stop_date = {
|
||||
'adif': 240,
|
||||
'country': u'SOUTH SANDWICH ISLANDS',
|
||||
'continent': u'SA',
|
||||
'latitude': -59.45,
|
||||
'longitude': 27.4,
|
||||
'cqz': 13,
|
||||
}
|
||||
|
||||
|
||||
class TestStoreDataInRedis:
|
||||
|
||||
def test_copy_data_in_redis(self, fixClublogXML, fix_redis):
|
||||
|
|
@ -39,4 +49,9 @@ class TestStoreDataInRedis:
|
|||
lib = LookupLib(lookuptype="redis", redis_prefix="CF", redis_instance=r)
|
||||
fixCountryFile.copy_data_in_redis("CF", r)
|
||||
assert lib.lookup_callsign("3D2RI") == fixCountryFile.lookup_callsign("3D2RI")
|
||||
assert lib.lookup_prefix("DH") == fixCountryFile.lookup_prefix("DH")
|
||||
assert lib.lookup_prefix("DH") == fixCountryFile.lookup_prefix("DH")
|
||||
|
||||
def test_redis_lookup(self, fixClublogXML, fix_redis):
|
||||
timestamp = datetime(year=2016, month=1, day=20, tzinfo=UTC)
|
||||
ci = Callinfo(fix_redis)
|
||||
assert ci.get_all("VP8STI", timestamp) == response_Exception_VP8STI_with_start_and_stop_date
|
||||
|
|
|
|||
Loading…
Reference in a new issue