-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfd.py
executable file
·275 lines (210 loc) · 9.35 KB
/
fd.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
############################################################################################
#
# fd.py - Rev 1.0
# Copyright (C) 2021-5 by Joseph B. Attili, aa2il AT arrl DOT net
#
# Keying routines for ARRL and Winter Field Day.
#
############################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
############################################################################################
from tkinter import END,E,W
from collections import OrderedDict
from default import DEFAULT_KEYING
from datetime import datetime
from rig_io import CONTEST_BANDS,ARRL_SECS
import numpy as np
from utilities import error_trap
############################################################################################
VERBOSITY=0
############################################################################################
# Keying class for Winter and ARRL Field Day
class FD_KEYING(DEFAULT_KEYING):
def __init__(self,P):
now = datetime.utcnow()
if now.month==1:
EVENT='WINTER'
else:
EVENT='ARRL'
DEFAULT_KEYING.__init__(self,P,EVENT+'-FD','FD_202*.txt')
P.CONTEST_ID=EVENT+'-FIELD-DAY'
# On-the-fly scoring - NEW!
self.nqsos=0
self.BANDS = CONTEST_BANDS
self.sec_cnt = np.zeros((len(ARRL_SECS),len(self.BANDS)),dtype=np.int32)
self.init_scoring()
# Routient to set macros for this contest
def macros(self):
MACROS = OrderedDict()
MACROS[0] = {'Label' : 'CQ' , 'Text' : 'CQ FD [MYCALL] '}
MACROS[0+12] = {'Label' : 'QRZ? ' , 'Text' : 'QRZ? '}
MACROS[1] = {'Label' : 'Reply' , 'Text' : '[CALL] TU [MYCAT] [MYSEC] '}
MACROS[1+12] = {'Label' : 'TU/QRZ?' , 'Text' : '[CALL_CHANGED] TNX AGN [NAME] EE [LOG]'}
MACROS[2] = {'Label' : 'TU/QRZ?' , 'Text' : '[CALL_CHANGED] R73 [MYCALL] [LOG]'}
MACROS[2+12] = {'Label' : 'TU/QRZ?' , 'Text' : '[CALL_CHANGED] FB [NAME] 73EE [LOG]'}
MACROS[3] = {'Label' : 'Call?' , 'Text' : '[CALL]? '}
MACROS[3+12] = {'Label' : 'CALL?' , 'Text' : 'CALL? '}
MACROS[4] = {'Label' : '[MYCALL]' , 'Text' : '[MYCALL] '}
MACROS[4+12] = {'Label' : 'His Call' , 'Text' : '[CALL] '}
MACROS[5] = {'Label' : 'S&P Reply' , 'Text' : 'TU [MYCAT] [MYSEC]'}
MACROS[5+12] = {'Label' : 'S&P Reply' , 'Text' : 'TU [NAME] [MYCAT] [MYSEC] '}
MACROS[6] = {'Label' : '? ' , 'Text' : '? '}
MACROS[6+12] = {'Label' : 'AGN?' , 'Text' : 'AGN? '}
MACROS[7] = {'Label' : 'Log QSO' , 'Text' : '[LOG] '}
MACROS[7+12] = {'Label' : 'RR' , 'Text' : 'RR '}
MACROS[8] = {'Label' : 'Cat 2x' , 'Text' : '[-2][MYCAT] [MYCAT] [+2]'}
MACROS[9] = {'Label' : 'Sec 2x' , 'Text' : '[-2][MYSEC] [MYSEC] [+2]'}
MACROS[10] = {'Label' : 'NR? ' , 'Text' : 'NR? '}
MACROS[11] = {'Label' : 'QTH? ' , 'Text' : 'SEC? '}
MACROS[11+12] = {'Label' : 'QRL? ' , 'Text' : 'QRL? '}
return MACROS
# Routine to generate a hint for a given call
def hint(self,call):
P=self.P
cat = P.MASTER[call]['fdcat']
sec = P.MASTER[call]['fdsec']
return cat+' '+sec
# Routine to get practice qso info
def qso_info(self,HIST,call,iopt):
cat = HIST[call]['fdcat'] # Category
qth = HIST[call]['fdsec'] # Section
if iopt==1:
done = len(cat)>0 and len(qth)>0
return done
else:
self.call = call
self.cat = cat
self.qth = qth
txt2 = ' '+cat+' '+qth
return txt2
# Routine to process qso element repeats
# Override default routine since NR is category for this contest
# Perhaps there is a better name? Category? Need to Check FD rules
def repeat(self,label,exch2):
if 'CALL' in label:
txt2=self.call+' '+self.call
elif 'NR?' in label:
txt2=self.cat+' '+self.cat
elif 'QTH?' in label or 'SEC?' in label:
txt2=self.qth+' '+self.qth
else:
txt2=exch2
return txt2
# Error checking
def error_check(self):
P=self.P
call2 = P.gui.get_call().upper()
cat2 = P.gui.get_cat().upper()
qth2 = P.gui.get_qth().upper()
match = self.call==call2 and self.cat==cat2 and self.qth==qth2
if not match:
txt='********************** ERROR **********************'
print(txt)
P.gui.txt.insert(END, txt+'\n')
print('Call sent:',self.call,' - received:',call2)
P.gui.txt.insert(END,'Call sent: '+self.call+' - received: '+call2+'\n')
print('Catergory sent:',self.cat,' - received:',cat2)
P.gui.txt.insert(END,'Category sent: '+self.cat+' - received: '+cat2+'\n')
print('QTH sent:',self.qth,' - received:',qth2)
P.gui.txt.insert(END,'QTH sent: '+self.qth+ ' - received: '+qth2+'\n')
print(txt+'\n')
P.gui.txt.insert(END, txt+'\n')
P.gui.txt.see(END)
return match
# Highlight function keys that make sense in the current context
def highlight(self,gui,arg):
if arg==0:
gui.btns1[1].configure(background='green',highlightbackground='green')
gui.btns1[2].configure(background='green',highlightbackground='green')
gui.call.focus_set()
elif arg==1:
gui.cat.focus_set()
elif arg==4:
gui.btns1[5].configure(background='red',highlightbackground= 'red')
gui.btns1[7].configure(background='red',highlightbackground= 'red')
gui.btns1[1].configure(background='pale green',highlightbackground=gui.default_color)
gui.btns1[2].configure(background='pale green',highlightbackground=gui.default_color)
elif arg==7:
gui.btns1[1].configure(background='pale green',highlightbackground=gui.default_color)
gui.btns1[5].configure(background='indian red',highlightbackground=gui.default_color)
gui.btns1[7].configure(background='indian red',highlightbackground=gui.default_color)
# Specific contest exchange for field day
def enable_boxes(self,gui):
gui.contest=True
gui.hide_all()
self.macros=[1,None,2]
gui.cat_lab.grid(columnspan=1,column=4,sticky=E+W)
gui.cat.grid(column=4,columnspan=2)
gui.qth_lab.grid(columnspan=1,column=6,sticky=E+W)
gui.qth.grid(column=6,columnspan=2)
gui.boxes=[gui.call]
gui.boxes.append(gui.cat)
gui.boxes.append(gui.qth)
if not self.P.NO_HINTS:
gui.hint_lab.grid(column=7,columnspan=1,sticky=E+W)
gui.hint.grid(column=7,columnspan=3)
# Gather together logging info for this contest
def logging(self):
gui=self.P.gui
call=gui.get_call().upper()
cat=gui.get_cat().upper()
qth = gui.get_qth().upper()
exch=cat+','+qth
valid = len(call)>=3 and len(cat)>0 and len(qth)>0
MY_CAT = self.P.SETTINGS['MY_CAT']
MY_SEC = self.P.SETTINGS['MY_SEC']
exch_out = MY_CAT+','+MY_SEC
qso2={}
return exch,valid,exch_out,qso2
# Dupe processing for this contest
def dupe(self,a):
gui=self.P.gui
gui.cat.delete(0,END)
gui.cat.insert(0,a[0])
if len(a)>=2:
gui.qth.delete(0,END)
gui.qth.insert(0,a[1])
# Hint insertion
def insert_hint(self,h=None):
gui=self.P.gui
if h==None:
h = gui.hint.get()
if type(h) == str:
h = h.split(' ')
gui.cat.delete(0, END)
gui.qth.delete(0, END)
if len(h)>=1:
gui.cat.insert(0,h[0])
if len(h)>=2:
gui.qth.insert(0,h[1])
# On-the-fly scoring
def scoring(self,qso):
print("\nFD->SCORING: qso=",qso)
self.nqsos+=1
call=qso['CALL']
band = qso["BAND"]
idx = self.BANDS.index(band)
try:
qth = qso["QTH"].upper()
idx1 = ARRL_SECS.index(qth)
except:
self.P.gui.status_bar.setText('Unrecognized/invalid section!')
error_trap('FD->SCORING - Unrecognized/invalid section!')
return
self.sec_cnt[idx1,idx] = 1
mults = 1 # np.sum( np.sum(self.sec_cnt,axis=0) )
score=self.nqsos * mults
print("SCORING: score=",score,self.nqsos,mults)
txt='{:3d} QSOs x {:3d} Mults = {:6,d} \t\t\t Last Worked: {:s}' \
.format(self.nqsos,mults,score,call)
self.P.gui.status_bar.setText(txt)