Skip to content

Commit 338b78f

Browse files
committed
Added the 1st working version that will crosscheck the 'Cabrillo'
Still a lot of work to be done: - validate if header fields are present multiple times - to use the 'checklogs' - check for duplicated qso's - check if qso is inside the valid contest date/time - add support for multipliers & calculate multipliers The current implementation of 'cabrillo' library doesn't fit with logXchecker way to do the validation. So this implemenation can be considered more of a TEST, not a working tool. This means I have 2 options: modify the cabrillo library or reimplement the cabrillo parser from scratch (like I did for .edi files)
1 parent 3a07b51 commit 338b78f

File tree

5 files changed

+502
-125
lines changed

5 files changed

+502
-125
lines changed

cabrillo.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

edi.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,6 @@ def __init__(self, message, line):
776776

777777

778778
def crosscheck_logs_filter(log_class, rules=None, logs_folder=None, checklogs_folder=None):
779-
780779
ignored_logs = []
781780

782781
if not rules:
@@ -852,7 +851,7 @@ def crosscheck_logs(operator_instances, rules, band_nr):
852851
if not _logs1:
853852
continue
854853

855-
# use 1st log that : is not checklog , is not to ignore & has valid header
854+
# use logs that : is not checklog , is not to ignore & has valid header
856855
for log1 in _logs1:
857856
if all((log1.use_as_checklog is False,
858857
log1.ignore_this_log is False,
@@ -890,14 +889,14 @@ def crosscheck_logs(operator_instances, rules, band_nr):
890889
qso1.cc_error = 'No log from {}'.format(callsign2)
891890
continue
892891

893-
# check if we have proper band logs from 2nd ham
892+
# check if we have the proper band logs from 2nd ham
894893
_logs2 = ham2.logs_by_band_regexp(rules.contest_band(band_nr)['regexp'])
895894
if not _logs2:
896895
qso1.cc_confirmed = False
897896
qso1.cc_error = 'No log for this band from {}'.format(callsign2)
898897
continue
899898

900-
# use 1st log that : is not to ignore & has valid header
899+
# use the 1st log that : is not to ignore & has valid header
901900
for log2 in _logs2:
902901
if all((log2.ignore_this_log is False,
903902
log2.valid_header is True)):
@@ -907,7 +906,7 @@ def crosscheck_logs(operator_instances, rules, band_nr):
907906
qso1.cc_error = 'No valid log from {}'.format(callsign2)
908907
continue
909908

910-
# get 2nd ham qsos and compare them with 1st ham qso
909+
# get the 2nd ham qsos and compare them with the 1st ham qso
911910
for qso2 in log2.qsos:
912911
if qso2.valid is False:
913912
continue

logXchecker.py

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
import sys
2121

2222
import edi
23-
import cabrillo
23+
import parse_cabrillo
2424
import rules as _rules
2525
import version
26-
from edi import crosscheck_logs_filter
2726

2827
# SORT_OUTPUT = False # TODO : sort the results output
2928

@@ -91,21 +90,21 @@ def load_log_format_module(module_name):
9190
# pass
9291

9392

94-
def print_human_friendly_output(output, verbose=False):
93+
def print_human_friendly_output(lfmodule, output, verbose=False):
9594
"""Will print a human-fiendly output for easy read"""
9695
# single log
97-
if output.get(edi.INFO_LOG, False):
98-
print_log_human_friendly(output)
96+
if output.get(lfmodule.INFO_LOG, False):
97+
print_log_human_friendly(lfmodule, output)
9998
# multi logs
100-
if output.get(edi.INFO_MLC, False):
101-
print('Checking logs from folder : {}'.format(output[edi.INFO_MLC]))
99+
if output.get(lfmodule.INFO_MLC, False):
100+
print('Checking logs from folder : {}'.format(output[lfmodule.INFO_MLC]))
102101
print('#########################')
103-
# print('Checking logs from folder : {}'.format(output[edi.INFO_MLC]))
104-
for log in output[edi.INFO_LOGS]:
105-
print_log_human_friendly(log)
102+
# print('Checking logs from folder : {}'.format(output[lfmodule.INFO_MLC]))
103+
for log in output[lfmodule.INFO_LOGS]:
104+
print_log_human_friendly(lfmodule, log)
106105
print('--------')
107106
# cross check
108-
if output.get(edi.INFO_CC, False):
107+
if output.get(lfmodule.INFO_CC, False):
109108
print('Cross check logs from folder : {}'.format(output[edi.INFO_CC]))
110109
print('#########################')
111110
for _call, _values in output[edi.INFO_OPERATORS].items():
@@ -124,40 +123,40 @@ def print_human_friendly_output(output, verbose=False):
124123
print('--------')
125124

126125

127-
def print_log_human_friendly(output):
126+
def print_log_human_friendly(lfmodule, output):
128127
"""Will print human fiendly info for a log"""
129128
has_errors = False
130-
print('Checking log : {}'.format(output[edi.INFO_LOG]))
131-
if output[edi.ERR_IO]:
132-
print('Input/Output : {}'.format(output[edi.ERR_IO]))
129+
print('Checking log : {}'.format(output[lfmodule.INFO_LOG]))
130+
if output[lfmodule.ERR_IO]:
131+
print('Input/Output : {}'.format(output[lfmodule.ERR_IO]))
133132
has_errors = True
134133
pass
135-
if output[edi.ERR_HEADER]:
134+
if output[lfmodule.ERR_HEADER]:
136135
print('Header errors :')
137-
for err in output[edi.ERR_HEADER]:
136+
for err in output[lfmodule.ERR_HEADER]:
138137
print('Line {} : {}'.format(err[0], err[1]))
139138
has_errors = True
140-
if output[edi.ERR_QSO]:
139+
if output[lfmodule.ERR_QSO]:
141140
print('QSO errors :')
142-
for err in output[edi.ERR_QSO]:
141+
for err in output[lfmodule.ERR_QSO]:
143142
print('Line {} : {} <- {}'.format(err[0], err[1], err[2]))
144143
has_errors = True
145144

146145
if has_errors is False:
147146
print('No error found')
148147

149148

150-
def print_csv_output(output):
149+
def print_csv_output(lfmodule, output):
151150
# cross check
152-
if output.get(edi.INFO_CC, False):
151+
if output.get(lfmodule.INFO_CC, False):
153152
print('Callsign, ValidLog, Band, Category, ConfirmedQso, Points')
154-
for _call, _values in output[edi.INFO_OPERATORS].items():
153+
for _call, _values in output[lfmodule.INFO_OPERATORS].items():
155154
for _band, _details in _values['band'].items():
156155
if not _details.get('checklog', False) is True:
157156
print('{}, {}, {}, {}, {}, {}'.format(_call, _details['valid'], _band, _details['category'], _details['qsos_confirmed'], _details['points']))
158157
else:
159-
# if output.get(edi.INFO_LOG, False):
160-
# if output.get(edi.INFO_MLC, False):
158+
# if output.get(lfmodule.INFO_LOG, False):
159+
# if output.get(lfmodule.INFO_MLC, False):
161160
print('NOT IMPLEMENTED')
162161

163162

@@ -179,6 +178,8 @@ def main():
179178

180179
if log_format == 'EDI':
181180
lfmodule = edi
181+
elif log_format == 'CABRILLO':
182+
lfmodule = parse_cabrillo
182183
else:
183184
print('Selected log type is unsupported : {}'.format(log_format))
184185
sys.exit(1)
@@ -191,7 +192,7 @@ def main():
191192

192193
# if 'validate one log'
193194
if args.singlelogcheck:
194-
output[edi.INFO_LOG] = args.singlelogcheck
195+
output[lfmodule.INFO_LOG] = args.singlelogcheck
195196
if not os.path.isfile(args.singlelogcheck):
196197
print('Cannot open file : {}'.format(args.singlelogcheck))
197198
sys.exit(1)
@@ -200,43 +201,44 @@ def main():
200201

201202
# validate multiple logs
202203
elif args.multilogcheck:
203-
output[edi.INFO_MLC] = args.multilogcheck
204+
output[lfmodule.INFO_MLC] = args.multilogcheck
204205
if not os.path.isdir(args.multilogcheck):
205206
print('Cannot open logs folder : {}'.format(args.multilogcheck))
206207
sys.exit(1)
207208
logs_output = []
208209
for filename in os.listdir(args.multilogcheck):
209210
log_output = {}
210211
_log = log(os.path.join(args.multilogcheck, filename), rules=rules)
211-
log_output[edi.INFO_LOG] = filename
212+
log_output[lfmodule.INFO_LOG] = filename
212213
log_output.update(_log.errors)
213214
logs_output.append(log_output)
214-
output[edi.INFO_LOGS] = logs_output
215+
output[lfmodule.INFO_LOGS] = logs_output
215216
# add also checklogs
216217
if args.checklogs:
217218
if os.path.isdir(args.checklogs):
218219
logs_output = []
219220
for filename in os.listdir(args.checklogs):
220221
log_output = {}
221222
_log = log(os.path.join(args.checklogs, filename), rules=rules, checklog=True)
222-
log_output[edi.INFO_LOG] = filename
223+
log_output[lfmodule.INFO_LOG] = filename
223224
log_output.update(_log.errors)
224225
logs_output.append(log_output)
225-
output[edi.INFO_LOGS].extend(logs_output)
226+
output[lfmodule.INFO_LOGS].extend(logs_output)
226227

227228
# crosscheck logs
228229
elif args.crosscheck:
229230
if not rules:
230231
print("No rules were provided")
231232
sys.exit(1)
232-
output[edi.INFO_CC] = args.crosscheck
233-
output[edi.INFO_OPERATORS] = {}
234-
op_instance = crosscheck_logs_filter(log, rules=rules, logs_folder=args.crosscheck, checklogs_folder=args.checklogs)
233+
output[lfmodule.INFO_CC] = args.crosscheck
234+
output[lfmodule.INFO_OPERATORS] = {}
235+
print("DEBUG : LOG=", log)
236+
op_instance = lfmodule.crosscheck_logs_filter(log, rules=rules, logs_folder=args.crosscheck, checklogs_folder=args.checklogs)
235237
for _call, _instance in op_instance.items():
236238
op_output = {}
237-
op_output[edi.INFO_BANDS] = {}
239+
op_output[lfmodule.INFO_BANDS] = {}
238240
for _log in _instance.logs:
239-
op_output[edi.INFO_BANDS][_log.band] = {
241+
op_output[lfmodule.INFO_BANDS][_log.band] = {
240242
'path': _log.path,
241243
'points': _log.qsos_points,
242244
'qsos_confirmed': _log.qsos_confirmed,
@@ -252,19 +254,19 @@ def main():
252254
_cc_errors.append('{} : {}'.format(qso.qso_line, qso.cc_error))
253255
else:
254256
_cc_valid.append('{} : {} : {}'.format(qso.qso_line, qso.points, qso.cc_confirmed))
255-
op_output[edi.INFO_BANDS][_log.band]['qso_errors'] = _cc_errors
256-
op_output[edi.INFO_BANDS][_log.band]['qso_valid'] = _cc_valid
257+
op_output[lfmodule.INFO_BANDS][_log.band]['qso_errors'] = _cc_errors
258+
op_output[lfmodule.INFO_BANDS][_log.band]['qso_valid'] = _cc_valid
257259

258-
output[edi.INFO_OPERATORS][_call] = op_output
260+
output[lfmodule.INFO_OPERATORS][_call] = op_output
259261

260262
if args.output.upper() == 'HUMAN-FRIENDLY':
261-
print_human_friendly_output(output, verbose=args.verbose)
263+
print_human_friendly_output(lfmodule, output, verbose=args.verbose)
262264
elif args.output.upper() == 'JSON':
263265
print(edi.dict_to_json(output))
264266
elif args.output.upper() == 'XML':
265267
print(edi.dict_to_xml(output))
266268
elif args.output.upper() == 'CSV':
267-
print_csv_output(output)
269+
print_csv_output(lfmodule, output)
268270

269271
if __name__ == '__main__':
270272
main()

0 commit comments

Comments
 (0)