-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcal_jarl.py
287 lines (250 loc) · 9.1 KB
/
cal_jarl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import sys
import os
from os import path
import adif_io
import csv
import json
NO_NAME_TYPE = 'kanji'
path_to_no_list = path.abspath(path.join(path.dirname(__file__), 'no-list.json'))
with open(path_to_no_list, "r", encoding="utf-8") as f:
no_list = json.load(f)
def get_district(no):
id = int(no)
if id == 1:
return '8'
elif id >= 2 and id <= 7:
return '7'
elif id >= 8 and id <= 9:
return '0'
elif id >= 10 and id <= 17:
return '1'
elif id >= 18 and id <= 21:
return '2'
elif id >= 22 and id <= 27:
return '3'
elif id >= 28 and id <= 30:
return '9'
elif id >= 31 and id <= 35:
return '4'
elif id >= 36 and id <= 39:
return '5'
elif id >= 40 and id <= 47:
return '6'
def get_no_name(no):
if no not in no_list:
return 'ERROR'
no_info = no_list[no]
if no_info['type'] == 'Prefecture':
return no_info[NO_NAME_TYPE]
elif no_info['type'] == 'City' or no_info['type'] == 'Gun':
return get_no_name(no[0:2]) + ' ' + no_info[NO_NAME_TYPE]
elif no_info['type'] == 'Ku':
return get_no_name(no[0:4]) + ' ' + no_info[NO_NAME_TYPE]
return 'ERROR'
qsl_list_header = ['No.', 'Callsign', 'Date', 'Band', 'Mode', 'Remarks']
aja_list_header = ['City/Gun/Ku', 'Band', 'Callsign', 'Date', 'Mode', 'Remarks']
def get_info_for_qsl_list(idx, one_qso, remarks):
if one_qso:
return [idx, one_qso['CALL'], one_qso['QSO_DATE'], one_qso['BAND'], one_qso['MODE'], remarks]
else:
return [idx, '', '', '', '', remarks]
def get_info_for_aja_list(no, one_qso, remarks):
return [no, one_qso['BAND'], one_qso['CALL'], one_qso['QSO_DATE'], one_qso['MODE'], remarks]
ajd = {}
waja = {}
jcc = {}
jcg = {}
aja = {}
# Load list from CSV file
## AJD
try:
with open('checksheet_ajd.csv', 'r', newline='', encoding='utf-8-sig') as f:
csv_reader = csv.reader(f, dialect='excel')
for row in csv_reader:
if row[0] == 'No.' or row[1] == '':
continue
else:
this_ajd = row[5].split(' ')[1]
ajd[this_ajd] = {
'CALL': row[1],
'QSO_DATE': row[2],
'BAND': row[3],
'MODE': row[4]
}
except FileNotFoundError as e:
print("checksheet_ajd.csv not found. Start new statistics.")
## WAJA
try:
with open('checksheet_waja.csv', 'r', newline='', encoding='utf-8-sig') as f:
csv_reader = csv.reader(f, dialect='excel')
for row in csv_reader:
if row[0] == 'No.' or row[1] == '':
continue
else:
this_pref = row[5].split(' ')[0]
waja[this_pref] = {
'CALL': row[1],
'QSO_DATE': row[2],
'BAND': row[3],
'MODE': row[4]
}
except FileNotFoundError as e:
print("checksheet_waja.csv not found. Start new statistics.")
## JCC
try:
with open('checksheet_jcc.csv', 'r', newline='', encoding='utf-8-sig') as f:
csv_reader = csv.reader(f, dialect='excel')
for row in csv_reader:
if row[0] == 'No.' or row[1] == '':
continue
else:
this_jcc = row[5].split(' ')[0]
jcc[this_jcc] = {
'CALL': row[1],
'QSO_DATE': row[2],
'BAND': row[3],
'MODE': row[4]
}
except FileNotFoundError as e:
print("checksheet_jcc.csv not found. Start new statistics.")
## JCG
try:
with open('checksheet_jcg.csv', 'r', newline='', encoding='utf-8-sig') as f:
csv_reader = csv.reader(f, dialect='excel')
for row in csv_reader:
if row[0] == 'No.' or row[1] == '':
continue
else:
this_jcg = row[5].split(' ')[0]
jcg[this_jcg] = {
'CALL': row[1],
'QSO_DATE': row[2],
'BAND': row[3],
'MODE': row[4]
}
except FileNotFoundError as e:
print("checksheet_jcg.csv not found. Start new statistics.")
## AJA
try:
with open('checksheet_aja.csv', 'r', newline='', encoding='utf-8-sig') as f:
csv_reader = csv.reader(f, dialect='excel')
for row in csv_reader:
if row[0] == 'City/Gun/Ku' or row[2] == '':
continue
else:
this_no = row[0]
this_band = row[1]
aja[(this_no, this_band)] = {
'BAND': row[1],
'CALL': row[2],
'QSO_DATE': row[3],
'MODE': row[4]
}
except FileNotFoundError as e:
print("checksheet_aja.csv not found. Start new statistics.")
if len(sys.argv) >= 2:
adif_file = sys.argv[1]
else:
adif_file = input("Your ADIF File: ").strip('\'\"')
qsos, header = adif_io.read_from_file(adif_file)
for one_qso in qsos:
this_call = one_qso['CALL']
this_band = one_qso['BAND']
if 'QSL_RCVD' not in one_qso or one_qso['QSL_RCVD'] != "Y":
continue
if 'COUNTRY' not in one_qso or one_qso['COUNTRY'] != "JAPAN":
continue
if 'STATE' not in one_qso:
continue
this_pref = one_qso['STATE']
if this_call[0] == "J":
district_call = this_call[2]
else:
district_call = '1'
district_no = get_district(one_qso['STATE'])
if district_call == district_no:
if district_call not in ajd or ajd[district_call]['QSO_DATE'] > one_qso['QSO_DATE']:
ajd[district_call] = one_qso
if this_pref not in waja or waja[this_pref]['QSO_DATE'] > one_qso['QSO_DATE']:
waja[this_pref] = one_qso
if 'CNTY' not in one_qso:
continue
this_no = one_qso['CNTY']
if this_no not in no_list:
continue
# TODO: check delete JCC/JCG/Ku with delete Date
this_no_info = no_list[this_no]
this_no_type = this_no_info['type']
if this_no_type == 'City':
if this_no not in jcc or jcc[this_no]['QSO_DATE'] > one_qso['QSO_DATE']:
jcc[this_no] = one_qso
elif this_no_type == 'Ku':
if this_no[0:4] not in jcc or jcc[this_no[0:4]]['QSO_DATE'] > one_qso['QSO_DATE']:
jcc[this_no[0:4]] = one_qso
elif this_no_type == 'Gun':
if this_no not in jcg or jcg[this_no]['QSO_DATE'] > one_qso['QSO_DATE']:
jcg[this_no] = one_qso
if (this_no, this_band) not in aja or aja[(this_no, this_band)]['QSO_DATE'] > one_qso['QSO_DATE']:
aja[(this_no, this_band)] = one_qso
# Print checksheet
## AJD
with open('checksheet_ajd.csv', 'w', newline='', encoding='utf-8-sig') as f:
csv_writer = csv.writer(f, dialect='excel')
csv_writer.writerow(qsl_list_header)
idx = 1
for d in range(10):
this_district = "%d" % d
if this_district in ajd:
this_row = get_info_for_qsl_list(idx, ajd[this_district], "Area %d" % d)
else:
this_row = get_info_for_qsl_list(idx, False, "Area %d" % d)
csv_writer.writerow(this_row)
idx += 1
## WAJA
with open('checksheet_waja.csv', 'w', newline='', encoding='utf-8-sig') as f:
csv_writer = csv.writer(f, dialect='excel')
csv_writer.writerow(qsl_list_header)
idx = 1
for d in range(1, 48):
this_pref = "%02d" % d
if this_pref in waja:
this_row = get_info_for_qsl_list(idx, waja[this_pref], "%s %s" % (this_pref, get_no_name(this_pref)))
else:
this_row = get_info_for_qsl_list(idx, False, "%s %s" % (this_pref, get_no_name(this_pref)))
csv_writer.writerow(this_row)
idx += 1
## JCC
with open('checksheet_jcc.csv', 'w', newline='', encoding='utf-8-sig') as f:
csv_writer = csv.writer(f, dialect='excel')
csv_writer.writerow(qsl_list_header)
idx = 1
for this_jcc in sorted(jcc):
this_row = get_info_for_qsl_list(idx, jcc[this_jcc], "%s %s" % (this_jcc, get_no_name(this_jcc)))
csv_writer.writerow(this_row)
idx += 1
## JCG
with open('checksheet_jcg.csv', 'w', newline='', encoding='utf-8-sig') as f:
csv_writer = csv.writer(f, dialect='excel')
csv_writer.writerow(qsl_list_header)
idx = 1
for this_jcg in sorted(jcg):
this_row = get_info_for_qsl_list(idx, jcg[this_jcg], "%s %s" % (this_jcg, get_no_name(this_jcg)))
csv_writer.writerow(this_row)
idx += 1
## AJA
with open('checksheet_aja.csv', 'w', newline='', encoding='utf-8-sig') as f:
csv_writer = csv.writer(f, dialect='excel')
csv_writer.writerow(aja_list_header)
idx = 1
for this_aja in sorted(aja):
this_row = get_info_for_aja_list(this_aja[0], aja[this_aja], "%s" % (get_no_name(this_aja[0])))
csv_writer.writerow(this_row)
idx += 1
print("----------JARL AWARDS STATUS----------")
print("AJD: %d / %d : %d%%" % (len(ajd), 10, len(ajd) * 100 / 10))
print("WAJA: %d / %d : %d%%" % (len(waja), 47, len(waja) * 100 / 47))
print("JCC: total %d" % len(jcc))
print("JCG: total %d" % len(jcg))
print("AJA: total %d" % len(aja))
print("--------------------------------------")
# os.system("pause")