Skip to content

Commit

Permalink
Merge pull request #1046 from MetPX/issue980
Browse files Browse the repository at this point in the history
#980 Expand scope of isProblem.
  • Loading branch information
petersilva authored May 27, 2024
2 parents a6ffe07 + d1a463e commit 561edb3
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions sarracenia/flowcb/gather/am.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,13 @@ def correctContents(self, bulletin, bulletin_firstchars, lines, missing_ahl, bul
# Also we need the first characters of the bulletin to match the ones from the mapping header.
if bulletin_station in map_elements[2:] and bulletin_firstchars == map_elements[0][:2]:

# Make sure the whole T1T2AiA2ii is correct when present in the bulletin
if len(lines[0].split(b' ')[0]) > 2 and lines[0][:6].decode(charset) != ahl_from_station[0]:
continue

# We want to append the new AHL without removing the timestamp nor the BBB.
bulletin_ahl = lines[0].split(b' ')
bulletin_ahl[0] = ahl_from_station[0] + ' ' + ahl_from_station[1]

logger.debug("Adding missing headers in file contents for station mappings")

# These bulletins should already have two elements of the header. Maybe three if the BBB is there.
if len(bulletin_ahl) == 2:
Expand All @@ -374,6 +376,8 @@ def correctContents(self, bulletin, bulletin_firstchars, lines, missing_ahl, bul
else:
logger.error("Not able to add new station AHLs.")

logger.debug("Adding missing headers in file contents for station mappings")

# We found the station. We can leave the loop now.
reconstruct = 1
break
Expand All @@ -390,21 +394,37 @@ def correctContents(self, bulletin, bulletin_firstchars, lines, missing_ahl, bul

reconstruct = 1

if reconstruct == 1:
new_bulletin, lines = self.reconstruct_bulletin(lines, new_bulletin)

# Check if the header is okay before proceeding to correcting rest of bulletin.
# We want to verify the header AFTER all the contents have been corrected
verified_header , isProblem = self.bulletinHandler.verifyHeader(lines[0], charset)
if verified_header != lines[0]:
lines[0] = verified_header
reconstruct = 1

if reconstruct == 1:
# Reconstruct the bulletin
for i in lines:
new_bulletin += i + b'\n'

logger.debug("Missing contents added")
if reconstruct == 1:
new_bulletin, lines = self.reconstruct_bulletin(lines, new_bulletin=b'')

return new_bulletin , isProblem

def reconstruct_bulletin(self, lines, new_bulletin):
"""
Reconstruct the bulletin once contents have been modified
"""
# Reconstruct the bulletin
for i in lines:
new_bulletin += i + b'\n'

new_lines = new_bulletin.splitlines()

logger.debug("Missing contents added")

return new_bulletin, new_lines




def gather(self, messageCountMax):

Expand Down Expand Up @@ -450,6 +470,8 @@ def gather(self, messageCountMax):
## Random Integer

binary = 0
isProblem = False

missing_ahl = self.o.MissingAMHeaders

# Fill in temporary filename for the timebeing
Expand All @@ -465,7 +487,7 @@ def gather(self, messageCountMax):

# Correct the bulletin contents, the Sundew way
if not binary:
station = lines[1].split()[0].decode(charset)
station = self.bulletinHandler.getStation(bulletin.decode(charset))
new_bulletin, isProblem = self.correctContents(bulletin, firstchars, lines, missing_ahl, station, charset)
if new_bulletin != b'':
bulletin = new_bulletin
Expand Down

0 comments on commit 561edb3

Please sign in to comment.