Source code for sardine.inputs.inputs_validator
[docs]
class InputsValidator:
def __init__(self):
'''
Initializes the InputsValidator class
'''
pass
[docs]
@staticmethod
def validate_sequence(source_lines, source_sequence, receiver_lines, receiver_sequence):
'''
This function's purpose is to check the logical consistency between the expected and actual sequences of source and receiver operations
Creates an empty list of errors found
Gets the source lines available by removing the suffixes "A"/"B" (if there are) from the given source lines, creates a set with the resulting list
Gets the shot lines by removing the suffixes "A"/"B" (if there are) from the given source sequence, creates a set with the resulting list
If the source lines set and the shot lines set have different lengths, it prints a Warning message and appends an error to the errors found list
Gets the receiver lines set with the list of the given receiver lines
Gets the deployment lines by looking for the action='LO' items in the given receiver sequence, creates a set with the resulting list
Gets the recovery lines by looking for the action='PU' items in the given receiver sequence, creates a set with the resulting list
If the receiver lines set and the deployment lines set have different lengths, it prints a Warning message and appends an error to the errors found list
If the receiver lines set and the recovery lines set have different lengths, it prints a Warning message and appends an error to the errors found list
Explains logic::
For each line in the receiver sequence:
If the action is pick up (PU):
- Gets a list of the lines previously deployed, as a list of the lines prior to the current with action=LO
- Gets a list of the lines not previously deployed, as a list of the lines that are not in the previously deployed list
- If the list of lines not previously deployed is not empty, it prints a Warning message and appends an error to the errors found list
Returns the list of errors found
'''
errors_found = []
# Replace the last A / B half spread identifier (first letter is zipper if any)
lines_available = [s[::-1].replace('A', '').replace('B', '')[::-1] for s in source_lines.keys()]
source_lines_set = set(lines_available)
lines_shot = [s['line'][::-1].replace('A', '').replace('B', '')[::-1] for s in source_sequence]
source_sequence_set = set(lines_shot)
if source_lines_set != source_sequence_set:
print('!!WARNING!! Incorrect source sequence')
print('{} lines, {} lines shot'.format(len(source_lines_set), len(source_sequence_set)))
errors_found.append('SLError')
receiver_lines_set = set(receiver_lines.keys())
deployment_set = set([s['line'] for s in receiver_sequence if s['action'] == 'LO'])
recovery_set = set([s['line'] for s in receiver_sequence if s['action'] == 'PU'])
if receiver_lines_set != deployment_set:
print('!!WARNING!! Incorrect deployment sequence')
errors_found.append('RLError')
if receiver_lines_set != recovery_set:
print('!!WARNING!! Incorrect recovery sequence')
errors_found.append('RLError')
for i, line in enumerate(receiver_sequence):
is_pickup = (line['action'] == 'PU')
if is_pickup:
lines_previously_deployed = [line['line'] for line in receiver_sequence[:i]
if line['action'] == 'LO']
line_not_previously_deployed = (line['line'] not in lines_previously_deployed)
if line_not_previously_deployed:
print('!!WARNING!! Line {} recovered without being previously deployed!'.format(line['line']))
errors_found.append('RecoveryError')
return errors_found