Skip to content

Commit

Permalink
Backup commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBacon committed Mar 18, 2024
1 parent 1bf0dfb commit 5179589
Show file tree
Hide file tree
Showing 6 changed files with 605 additions and 13 deletions.
12 changes: 11 additions & 1 deletion app/checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import app.auth as auth
import app.species.cache as cache
import app.checks.srefs as srefs
from .srefs import srefs
from .vague_dates import VagueDate


router = APIRouter()
Expand Down Expand Up @@ -69,6 +70,15 @@ async def check_by_tvk(
results.append(Checked(**result_data))
continue

# 3. Confirm date is valid.
vague_date = VagueDate(record.date)
if not vague_date.validate():
result_data['ok'] = False
result_data['message'] = 'Invalid date.'
results.append(Checked(**result_data))
continue

# 4. Check the record against the rules.
results.append(Checked(**result_data))

return results
Expand Down
32 changes: 29 additions & 3 deletions app/checks/srefs/ci_grid.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
import re


class CiGrid:

srid = 23030

def __init__(self, sref: str):
self.sref = sref

def validate(self) -> bool:
if len(self.sref) == 8:
return True
else:

# Ignore any spaces in the grid ref.
self.sref = self.sref.replace(' ', '')

# Check the first two letters are a valid combination.
# Column is in range S-Z
# Rows in the range U-V and A-G
sq100 = self.sref[:2].upper()
if not re.match(r'[S-Z]([U-V]|[A-G])', sq100):
return False

# Check either remaining chars are all numeric and an equal
# number, up to 10 digits OR for DINTY Tetrads, 2 numbers followed by a
# letter (Excluding O, including I).
eastnorth = self.sref[2:]
if ((
not re.match(r'^[0-9]*$', eastnorth) or
len(eastnorth) % 2 != 0 or
len(eastnorth) > 10
) and (
not re.match(r'^[0-9][0-9][A-NP-Z]$', eastnorth)
)):
return False

return True
4 changes: 2 additions & 2 deletions app/checks/srefs/gb_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def validate(self) -> bool:
len(eastnorth) % 2 != 0 or
len(eastnorth) > 10
) and (
not re.match(r'^[0-9][0-9][A-NP-Z]$', eastnorth))
):
not re.match(r'^[0-9][0-9][A-NP-Z]$', eastnorth)
)):
return False

return True
30 changes: 27 additions & 3 deletions app/checks/srefs/ni_grid.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import re


class NiGrid:

srid = 29901

def __init__(self, sref: str):
self.sref = sref

def validate(self) -> bool:
if len(self.sref) == 8:
return True
else:

# Ignore any spaces in the grid ref.
self.sref = self.sref.replace(' ', '')

# Check the first letter is valid.
sq100 = self.sref[0].upper()
if not re.match(r'[A-HJ-Z]', sq100):
return False

# Check either remaining chars are all numeric and an equal
# number, up to 10 digits OR for DINTY Tetrads, 2 numbers followed by a
# letter (Excluding O, including I).
eastnorth = self.sref[1:]
if ((
not re.match(r'^[0-9]*$', eastnorth) or
len(eastnorth) % 2 != 0 or
len(eastnorth) > 10
) and (
not re.match(r'^[0-9][0-9][A-NP-Z]$', eastnorth)
)):
return False

return True
Loading

0 comments on commit 5179589

Please sign in to comment.