forked from scotthibbs/FDLog_Enhanced
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFDLog.py
More file actions
executable file
·3797 lines (3560 loc) · 144 KB
/
FDLog.py
File metadata and controls
executable file
·3797 lines (3560 loc) · 144 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
import os
import time
import string
import thread
import threading
import socket
import hashlib
import random
import calendar
import sqlite3
from Tkinter import Tk, END, NORMAL, DISABLED, re, sys, Toplevel, Frame, Label, Entry, Button, \
W, EW, E, NONE, NSEW, NS, StringVar, Radiobutton, Tk, Menu, Menubutton, Text, Scrollbar, Checkbutton, RAISED, IntVar
# This needs to be tested on different networks and cross platform.
#
# KD4SIR - Will probably work on copy/paste functionality
# KC7SDA - Will check network and platform compatibility and upper/lower case entry
# Originally "WB6ZQZ's Field Day Logging Program" written in 1984.
# Alan Biocca (as WB6ZQZ) ported it to python with GNU in 2002.
# Our (SCICSG) code starts from:
# FDLog 1-149-2 2011/07/11
# Copyright 2002-2013 by Alan Biocca (W6AKB) (www.fdlog.info)
# FDLog is distributed under the GNU Public License
# Additional code included from FDLog v4-1-152i 2014/05/26
# Some code modified from FDLog v4-1-153d Febuary 2017
# Forked & Repository Project
# FDLog_Enhanced at Github.com
# Copyright 2014-2019 South Central Indiana Communications Support Group
# Copyright 2019 Curtis E. Mills (WE7U)
#
# Our Goals are twofold:
# 1: Improve on fdlog faster with open and directed collaboration.
# This is now on github as FDLog_Enhanced.
# 2: Increase user friendliness (GUI) and inter-operability with other GNU programs.
# Future: Adding interoperability with other programs such as HRDeluxe Free,
# FLDigi, Rigserve etc if we can?
prog = 'FDLog_Enhanced v2019-FD-WE7U\n' \
'Copyright 2014-2019 by South Central Indiana Communications Support Group \n' \
'Copyright 2019 by Curtis E. Mills (WE7U) \n' \
'FDLog is under the GNU Public License v2 without warranty. \n' \
'The original license file is in the folder. \n'
print prog
about = """
FDLog_Enhanced can be found on www.github.com
GNU Public License V2 - in program folder.
Copyright 2014-2019 South Central Indiana Communications Support Group
Copyright 2019 Curtis E. Mills (WE7U)
"""
version = "v18"
fontsize = 10
fontinterval = 2
typeface = 'Courier 10 pitch'
fdfont = (typeface, fontsize) # regular fixed width font
fdmfont = (typeface, fontsize + fontinterval) # medium fixed width font
fdbfont = (typeface, fontsize + fontinterval * 2) # large fixed width font
# Known Bug List
#
# some foreign callsigns not supported properly
# 8a8xx
# need to change the way this works
# define a suffix as trailing letters
# prefix as anything ending in digits
# bring down a previous suffix with a character such as ' or .
#
#
def fingerprint():
t = open('FDLog.py').read()
h = hashlib.md5()
h.update(t)
print " FDLog Fingerprint", h.hexdigest()
fingerprint()
def ival(s):
"""return value of leading int"""
r = 0
if s != "":
mm = re.match(r' *(-?[0-9]*)', s)
if mm and mm.group(1):
r = int(mm.group(1))
return r
class clock_class:
level = 9 # my time quality level
offset = 0 # my time offset from system clock, add to system time, sec
adjusta = 0 # amount to adjust clock now (delta)
errors = 0 # current error sum wrt best source, in total seconds
errorn = 0 # number of time values in errors sum
srclev = 10 # current best time source level
lock = threading.RLock() # sharing lock
def update(self):
"""periodic clock update every 30 seconds"""
# Add line to get tmast variable (self.offset=float(gd.get('tmast',0)) from global database
self.lock.acquire() # take semaphore
if node == string.lower(gd.getv('tmast')):
if self.level != 0: print "Time Master"
self.offset = 0
self.level = 0
else:
if self.errorn > 0:
error = float(self.errors) / self.errorn
else:
error = 0
self.adjusta = error
err = abs(error)
if (err <= 2) & (self.errorn > 0) & (self.srclev < 9):
self.level = self.srclev + 1
else:
self.level = 9
if self.srclev > 8: self.adjusta = 0 # require master to function
if abs(self.adjusta) > 1:
print "Adjusting Clock %.1f S, src level %d, total offset %.1f S, at %s" % \
(self.adjusta, self.level, self.offset + self.adjusta, now())
self.srclev = 10
self.lock.release() # release sem
## Add line to put the offset time in global database (gd.put('tmast',self.offset))
def calib(self, fnod, stml, td):
"process time info in incoming pkt"
if fnod == node:
return
self.lock.acquire() # take semaphore
# print "time fm",fnod,"lev",stml,"diff",td
stml = int(stml)
if stml < self.srclev:
self.errors, self.errorn = 0, 0
self.srclev = stml
if stml == self.srclev:
self.errorn += 1
self.errors += td
self.lock.release() # release sem
def adjust(self):
"adjust the clock each second as needed"
rate = 0.75931 # delta seconds per second
adj = self.adjusta
if abs(adj) < 0.001: return
if adj > rate:
adj = rate
elif adj < -rate:
adj = -rate
self.offset += adj
# or self.offset = float(database.get('tmast',0)) instead of the line above.
self.adjusta -= adj
print "Slewing clock", adj, "to", self.offset
mclock = clock_class()
def initialize():
k = "" # keyboard input
z = "" # answer counter
kfd = 0 # FD indicator to skip questions
print "\n \n"
print "For the person in Charge of Logging:"
print "*** ONLY ONE PERSON CAN DO THIS ***"
print "Do you need to set up the event? Y or N"
print " if in doubt select N"
while z != "1":
k = string.lower(string.strip(sys.stdin.readline())[:1])
if k == "y": z = "1"
if k == "n": z = '1'
if z != "1": print "Press Y or N please"
if k == "y":
# Field Day or VHF contest
z = ""
print "Which contest is this?"
print "F = FD, W = WFD, and V = VHF"
while z != "1":
k = string.lower(string.strip(sys.stdin.readline())[:1])
if k == "f": z = "1"
if k == "w": z = "1"
if k == "v": z = '1'
if z != "1": print "Press F, W or V please"
if k == "f":
kfd = 1 #used later to skip grid square question.SAH
globDb.put('contst', "FD")
qdb.globalshare('contst', "FD") # global to db
renew_title()
print "Have a nice Field Day!"
if k == "w":
kfd = 2 #used later to skip grid square question
globDb.put('contst', "WFD")
qdb.globalshare('contst', "WFD") # global to db
renew_title()
print "Have a nice Field Day!"
if k == "v":
globDb.put('contst', "VHF")
qdb.globalshare('contst', "VHF") # global to db
renew_title()
print "Enjoy the VHF contest!"
# Name of the club or group
print "What is the NAME of your club or group?"
k = string.strip(sys.stdin.readline())
while k == "":
print "Please type the name of your club or group"
k = string.strip(sys.stdin.readline())
globDb.put('grpnam', k)
qdb.globalshare('grpnam', k) # global to db
renew_title()
print k, "is a nice name."
# Club Call
print "What will be your club call?"
k = string.strip(sys.stdin.readline())
while k == "":
print "Please type the club call."
k = string.strip(sys.stdin.readline())
globDb.put('fdcall', k)
qdb.globalshare('fdcall', k) # global to db
renew_title()
print k, "will be the club call."
# Gota Call
if kfd == 1:
print "What will be your GOTA call?"
k = string.strip(sys.stdin.readline())
while k == "":
print "Please type the GOTA call. (if none type none)"
k = string.strip(sys.stdin.readline())
else:
globDb.put('gcall', k)
qdb.globalshare('gcall', k) # global to db
renew_title()
print k, "will be the GOTA call."
# Class
print "What will be your class? (like 2A)"
k = string.strip(sys.stdin.readline())
while k == "":
print "Please type the class."
k = string.strip(sys.stdin.readline())
else:
globDb.put('class', k)
qdb.globalshare('class', k) # global to db
renew_title()
print k, "will be the class."
# Section
print "What will be your section? (like IN-Indiana)"
k = string.strip(sys.stdin.readline())
while k == "":
print "Please type the section (like KY-Kentucky)."
k = string.strip(sys.stdin.readline())
else:
globDb.put('sect', k)
qdb.globalshare('sect', k) # global to db
renew_title()
print k, "will be the section."
if kfd == 0:
# grid square
print "What will be your grid square? (if none type none)"
k = string.strip(sys.stdin.readline())
while k == "":
print "Please type the grid square. (For FD type none)"
k = string.strip(sys.stdin.readline())
k = k.upper() # changed the init so the grid square will be cap
else:
globDb.put('grid', k)
qdb.globalshare('grid', k) # global to db
renew_title()
print k, "will be the grid."
if kfd !=2:
#questions for vhf and fd, skip for wfd
# Public Place
z = ""
print "Will the location be in a public place?"
print "Y = yes and N = no"
while z != "1":
k = string.lower(string.strip(sys.stdin.readline())[:1])
if k == "y": z = "1"
if k == "n": z = '1'
if z == "" : print "Press Y or N please"
if k == "y":
globDb.put('public', "A public location")
qdb.globalshare('public', "A public location") # global to db
renew_title()
print "Enjoy the public place."
if k == "n":
globDb.put('public', "")
qdb.globalshare('public', "") # global to db
renew_title()
print "maybe next year..."
# Info Booth
z = ""
print "Will you have an info booth?"
print "Y = yes and N = no"
while z != "1":
k = string.lower(string.strip(sys.stdin.readline())[:1])
if k == "y": z = "1"
if k == "n": z = '1'
if z == "" : print "Press Y or N please"
if k == "y":
globDb.put('infob', "1")
qdb.globalshare('infob', "1") # global to db
renew_title()
print "Love information tables!"
if k == "n":
globDb.put('infob', "0")
qdb.globalshare('infob', "0") # global to db
renew_title()
print "An information table is easy points"
#Time Master - oh yeah the big question
z = ""
print "\n It is recommended that the first computer"
print "set up should also be the time master."
print "\n IS THIS COMPUTER TIME CORRECT??? \n"
print "Will this computer be the time master?"
print "Y = yes and N = no"
while z != "1":
k = string.lower(string.strip(sys.stdin.readline())[:1])
if k == "y": z = "1"
if k == "n": z = '1'
if z == "" : print "Press Y or N please"
if k == "y":
globDb.put('tmast', node)
qdb.globalshare('tmast', node) # global to db
renew_title()
print "Time travels to you!"
if k == "n":
pass
return
def exin(op):
"""extract Operator or Logger initials"""
r = ""
m = re.match(r'([a-z0-9]{2,3})', op)
if m:
r = m.group(1)
return r
# sqlite database upgrade
# sqlite3.connect(":memory:", check_same_thread = False)
# I found this online to correct thread errors with sql locking to one thread only.
# I'm pretty sure I emailed this fix to Alan Biocca over a year ago. :(
# Scott Hibbs 7/5/2015
class SQDB:
def __init__(self):
self.dbPath = logdbf[0:-4] + '.sq3'
print "Using database", self.dbPath
self.sqdb = sqlite3.connect(self.dbPath, check_same_thread=False) # connect to the database
# Have to add FALSE here to get this stable
self.sqdb.row_factory = sqlite3.Row # namedtuple_factory
self.curs = self.sqdb.cursor() # make a database connection cursor
sql = "create table if not exists qjournal(src text,seq int,date text,band " \
"text,call text,rept text,powr text,oper text,logr text,primary key (src,seq))"
self.curs.execute(sql)
self.sqdb.commit()
def readlog(self): # ,srcId,srcIdx): # returns list of log journal items
print "Loading log journal from sqlite database"
sql = "select * from qjournal"
result = self.curs.execute(sql)
nl = []
for r in result:
# print dir(r)
nl.append("|".join(('q', r['src'], str(r['seq']), r['date'], r['band'], r['call'], r['rept'], r['powr'],
r['oper'], r['logr'], '')))
# print nl
return nl
# Removed next(self) function. There is no self.result
# and nothing calls sqdb.next()
# def next(self): # get next item from db in text format
# n = self.result
# nl = "|".join(n.src, n['seq'], n['date'], n['band'], n['call'], n['rept'], n['powr'], n['oper'], n['logr'])
# return nl
def log(self, n): # add item to journal logfile table (and other tables...)
parms = (n.src, n.seq, n.date, n.band, n.call, n.rept, n.powr, n.oper, n.logr)
sqdb = sqlite3.connect(self.dbPath) # connect to the database
# self.sqdb.row_factory = sqlite3.Row # namedtuple_factory
curs = sqdb.cursor() # make a database connection cursor
# start commit, begin transaction
sql = "insert into qjournal (src,seq,date,band,call,rept,powr,oper,logr) values (?,?,?,?,?,?,?,?,?)"
curs.execute(sql, parms)
# sql = "insert into qsos values (src,seq,date,band,call,sfx,rept,powr,oper,logr),(?,?,?,?,?,?,?,?,?,?)"
# self.cur(sql,parms)
# update qso count, scores? or just use q db count? this doesn't work well for different weights
# update sequence counts for journals?
sqdb.commit() # do the commit
if n.band == '*QST':
print("QST\a " + n.rept+" -"+n.logr) # The "\a" emits the beep sound for QST
class qsodb:
byid = {} # qso database by src.seq
bysfx = {} # call list by suffix.band
hiseq = {} # high sequence number by node
lock = threading.RLock() # sharing lock
def new(self, source):
n = qsodb()
n.src = source # source id
return n
def tolog(self): # make log file entry
sqdb.log(self) # to database
self.lock.acquire() # and to ascii journal file as well
fd = file(logdbf, "a")
fd.write("\nq|%s|%s|%s|%s|%s|%s|%s|%s|%s|" % \
(self.src, self.seq,
self.date, self.band, self.call, self.rept,
self.powr, self.oper, self.logr))
fd.close()
self.lock.release()
def ldrec(self, line): # load log entry fm text
(dummy, self.src, self.seq,
self.date, self.band, self.call, self.rept,
self.powr, self.oper, self.logr, dummy) = string.split(line, '|')
self.seq = int(self.seq)
self.dispatch('logf')
def loadfile(self):
print "Loading Log File"
i, s, log = 0, 0, []
global sqdb # setup sqlite database connection
sqdb = SQDB()
log = sqdb.readlog() # read the database
for ln in log:
if ln[0] == 'q': # qso db line
r = qdb.new(0)
try:
r.ldrec(ln)
i += 1
except ValueError, e:
print " error, item skipped: ", e
print " in:", ln
s += 1
# sqdb.log(r)
# push a copy from the file into the
# database (temporary for transition)
if i == 0 and s == 1:
print "Log file not found, must be new"
initialize() # Set up routine
else:
print " ", i, "Records Loaded,", s, "Errors"
if i == 0:
initialize()
def cleanlog(self):
"""return clean filtered dictionaries of the log"""
d, c, g = {}, {}, {}
fdstart, fdend = gd.getv('fdstrt'), gd.getv('fdend')
self.lock.acquire()
for i in self.byid.values(): # copy, index by node, sequence
k = "%s|%s" % (i.src, i.seq)
d[k] = i
self.lock.release()
for i in d.keys(): # process deletes
if d.has_key(i):
iv = d[i]
if iv.rept[:5] == "*del:":
dummy, st, sn, dummy = iv.rept.split(':') # extract deleted id
k = "%s|%s" % (st, sn)
if k in d.keys():
# print iv.rept,; iv.pr()
del (d[k]) # delete it
# else: print "del target missing",iv.rept
del (d[i])
for i in d.keys(): # filter time window
iv = d[i]
if iv.date < fdstart or iv.date > fdend:
# print "discarding out of date range",iv.date,iv.src,iv.seq
del (d[i])
for i in d.values(): # re-index by call-band
dummy, dummy, dummy, dummy, call, dummy, dummy = self.qparse(i.call) # extract call (not /...)
k = "%s-%s" % (call, i.band)
# filter out noncontest entries
if ival(i.powr) == 0 and i.band[0] != '*': continue
if i.band == 'off': continue
if i.band[0] == '*': continue # rm special msgs
if i.src == 'gotanode':
g[k] = i # gota is separate dup space
else:
c[k] = i
return (d, c, g) # Deletes processed, fully Cleaned
# by id, call-bnd, gota by call-bnd
def prlogln(self, s):
"convert log item to print format"
# note that edit and color read data from the editor so
# changing columns matters to these other functions.
if s.band == '*QST':
ln = "%8s %5s %-41s %-3s %-3s %4s %s" % \
(s.date[4:11], s.band, s.rept[:41], s.oper, s.logr, s.seq, s.src)
elif s.band == '*set':
ln = "%8s %5s %-11s %-29s %-3s %-3s %4s %s" % \
(s.date[4:11], s.band, s.call[:10], s.rept[:29], s.oper, s.logr, s.seq, s.src)
elif s.rept[:5] == '*del:':
ln = "%8s %5s %-7s %-33s %-3s %-3s %4s %s" % \
(s.date[4:11], s.band, s.call[:7], s.rept[:33], s.oper, s.logr, s.seq, s.src)
else:
ln = "%8s %5s %-11s %-24s %4s %-3s %-3s %4s %s" % \
(s.date[4:11], s.band, s.call[:11], s.rept[:24], s.powr, s.oper, s.logr, s.seq, s.src)
return ln
def prlog(self):
"print log in time order"
l = self.filterlog("")
for i in l:
print i
def pradif(self):
"print clean log in adif format"
pgm = "FDLog (https://github.com/scotthibbs/FDLog_Enhanced)"
print "<PROGRAMID:%d>%s" % (len(pgm), pgm)
dummy, n, g = self.cleanlog()
for i in n.values() + g.values():
dat = "20%s" % i.date[0:6]
tim = i.date[7:11]
cal = i.call
bnd = "%sm" % i.band[:-1]
mod = i.band[-1:]
if mod == 'p':
mod = 'SSB'
elif mod == 'c':
mod = 'CW'
elif mod == 'd':
mod = 'RTTY'
com = i.rept
print "<QSO_DATE:8>%s" % (dat)
print "<TIME_ON:4>%s" % (tim)
print "<CALL:%d>%s" % (len(cal), cal)
print "<BAND:%d>%s" % (len(bnd), bnd)
print "<MODE:%d>%s" % (len(mod), mod)
print "<QSLMSG:%d>%s" % (len(com), com)
print "<EOR>"
print
def vhf_cabrillo(self):
"output VHF contest cabrillo QSO data"
band_map = {'6': '50', '2': '144', '220': '222', '440': '432', '900': '902', '1200': '1.2G'}
dummy, n, dummy = self.cleanlog()
mycall = string.upper(gd.getv('fdcall'))
mygrid = gd.getv('grid')
l = []
print "QSO: freq mo date time call grid call grid "
for i in n.values(): # + g.values(): no gota in vhf
freq = "%s" % i.band[:-1] # band
if freq in band_map: freq = band_map[freq]
mod = i.band[-1:] # mode
if mod == "c": mod = "CW"
if mod == "p": mod = "PH"
if mod == "d": mod = "RY"
date = "20%2s-%2s-%2s" % (i.date[0:2], i.date[2:4], i.date[4:6])
tim = i.date[7:11]
call = i.call
grid = ''
if '/' in call: # split off grid from call
call, grid = call.split('/')
l.append("%sQSO: %-5s %-2s %-10s %4s %-13s %-6s %-13s %-6s" % (
i.date, freq, mod, date, tim, mycall, mygrid, call, grid))
l.sort() # sort data with prepended date.time
for i in l: print i[13:] # rm sort key date.time
# added support for winter field day, this outputs the cabrillo format that is posted on their website.
def winter_fd(self):
"output Winter Field day QSO data in cabrillo format:"
#vars:
band_map = {'160': '1800', '80': '3500', '40': '7000', '20': '14000','15': '21000','10': '28000','6': '50', '2': '144', '220': '222', '440': '432', '900': '902', '1200': '1.2G'}
dummy, n, dummy = self.cleanlog()
l = []
mycall = string.upper(gd.getv('fdcall'))
mycat = gd.getv('class')
mystate, mysect = gd.getv('sect').split("-")
#number of tx
txnum = mycat[:-1]
#data crunching:
#QSO log generation:
for i in n.values():
freq = "%s" % i.band[:-1] # band
#if freq in band_map: freq = band_map[freq]
mod = i.band[-1:] # mode
if mod == "c": mod = "CW"
if mod == "p": mod = "PH"
if mod == "d": mod = "DI" # per 2019 rules
date = "20%2s-%2s-%2s" % (i.date[0:2], i.date[2:4], i.date[4:6])
#date = "%2s-%2s-20%2s" % (i.date[2:4], i.date[4:6], i.date[0:2])
tim = i.date[7:11]
call = i.call
cat, sect = i.rept.split(" ")
if '/' in call: # split off grid from call
call, grid = call.split('/')
#cabrillo example: QSO: 40 DI 2019-01-19 1641 KC7SDA 1H WWA KZ9ZZZ 1H NFL
l.append("%sQSO: %-5s %-2s %-10s %4s %-10s %-2s %-5s %-10s %-2s %-5s" % (
i.date,freq, mod, date, tim, mycall, mycat, mysect, call, cat, sect))
l.sort() # sort data with prepended date.time
#check operator (single or multi op):
cat_op = ""
if len(participants) > 1:
cat_op = "MULTI-OP"
else:
cat_op = "SINGLE-OP"
#check fixed or portable?
#tx power:
#calls for ops:
ops_calls_list = []
#print(participants)
#participants: {u'am': u'am, art miller, kc7sda, 37, '}
for i in participants.values():
dummy, dummy, cs, dummy, dummy = i.split(", ")
ops_calls_list.append(string.upper(cs))
ops_calls = ', '.join(ops_calls_list)
#output
print "Winter field day Cabrillo output"
print "START-OF-LOG: 3.0"
print "Created-By: FDLog (https://github.com/scotthibbs/FDLog_Enhanced)"
print "CONTEST: WFD "
print "CALLSIGN: " + mycall
print "LOCATION: " + mystate
print "ARRL-SECTION: " + mysect
print "CATEGORY-OPERATOR: " + cat_op
print "CATEGORY-STATION: " #fixed or portable
print "CATEGORY_TRANSMITTER: " + txnum # how many transmitters
print "CATEGORY_POWER: LOW" #qrp low or high
print "CATEGORY_ASSISTED: NON-ASSISTED" #assisted or non-assisted
print "CATEGORY-BAND: ALL" # leave for wfd
print "CATEGORY-MODE: MIXED" #leave for wfd
print "CATEGORY-OVERLAY: OVER-50" # leave for wfd
print "SOAPBOX: " #fill in?
print "CLAIMED-SCORE: " #figure out score and add
print "OPERATORS: " + ops_calls #agregate the ops
print "NAME: " + gd.getv('fmname')
print "ADDRESS: " + gd.getv('fmad1')
print "ADDRESS-CITY: " + gd.getv('fmcity')
print "ADDRESS-STATE: " + gd.getv('fmst')
print "ADDRES-POSTALCODE: " + gd.getv('fmzip') #zip
print "ADDRESS-COUNTRY: USA" # hard coded for now, possibly change later
print "EMAIL: " + gd.getv('fmem') #email address
#print log:
for i in l: print i[13:] # rm sort key date.time
print "END-OF-LOG:"
def filterlog(self, filt):
"""list filtered (by bandm) log in time order, nondup valid q's only"""
l = []
dummy, n, g = self.cleanlog()
for i in n.values() + g.values():
if filt == "" or re.match('%s$' % filt, i.band):
l.append(i.prlogln(i))
l.sort()
return l
def filterlog2(self, filt):
"list filtered (by bandm) log in time order, including special msgs"
l = []
m, dummy, dummy = self.cleanlog()
for i in m.values():
if filt == "" or re.match('%s$' % filt, i.band):
l.append(i.prlogln(i))
l.sort()
return l
def filterlogst(self, filt):
"list filtered (by nod) log in time order, including special msgs"
l = []
m, dummy, dummy = self.cleanlog()
for i in m.values():
if re.match('%s$' % filt, i.src):
l.append(i.prlogln(i))
l.sort()
return l
def qsl(self, time, call, bandmod, report):
"log a qsl"
return self.postnewinfo(time, call, bandmod, report)
def qst(self, msg):
"put a qst in database + log"
return self.postnewinfo(now(), '', '*QST', msg)
def globalshare(self, name, value):
"put global var set in db + log"
return self.postnewinfo(now(), name, '*set', value)
def postnewinfo(self, time, call, bandmod, report):
"post new locally generated info"
# s = self.new(node)
# s.date,s.call,s.band,s.rept,s.oper,s.logr,s.powr =
# time,call,bandmod,report,exin(operator),exin(logger),power
# s.seq = -1
return self.postnew(time, call, bandmod, report, exin(operator),
exin(logger), power)
# s.dispatch('user') # removed in 152i
def postnew(self, time, call, bandmod, report, oper, logr, powr):
"post new locally generated info"
s = self.new(node)
s.date, s.call, s.band, s.rept, s.oper, s.logr, s.powr = time, call, bandmod, report, oper, logr, powr
s.seq = -1
return s.dispatch('user')
def delete(self, nod, seq, reason):
"remove a Q by creating a delete record"
# print "del",nod,seq
a, dummy, dummy = self.cleanlog()
k = "%s|%s" % (nod, seq)
if a.has_key(k) and a[k].band[0] != '*': # only visible q
tm, call, bandmod = a[k].date, a[k].call, a[k].band
rept = "*del:%s:%s:%s" % (nod, seq, reason)
s = self.new(node)
s.date, s.call, s.band, s.rept, s.oper, s.logr, s.powr = \
now(), call, bandmod, rept, exin(operator), exin(logger), 0
s.seq = -1
s.dispatch('user')
txtbillb.insert(END, " DELETE Successful %s %s %s\n" % (tm, call, bandmod))
logw.configure(state=NORMAL)
logw.delete(0.1,END)
logw.insert(END, "\n")
# Redraw the logw text window (on delete) to only show valid calls in the log.
# This avoids confusion by only listing items in the log to edit in the future.
l = []
for i in sorted(a.values()):
if i.seq == seq:
continue
else:
l.append(logw.insert(END, "\n"))
if nod == node:
l.append(logw.insert(END, i.prlogln(i), "b"))
else:
l.append(logw.insert(END, i.prlogln(i)))
l.append(logw.insert(END, "\n"))
logw.insert(END, "\n")
logw.configure(state=DISABLED)
else:
txtbillb.insert(END, " DELETE Ignored [%s,%s] Not Found\n" % (nod, seq))
topper()
def todb(self):
""""Q record object to db"""
r = None
self.lock.acquire()
current = self.hiseq.get(self.src, 0)
self.seq = int(self.seq)
if self.seq == current + 1: # filter out dup or nonsequential
self.byid["%s.%s" % (self.src, self.seq)] = self
self.hiseq[self.src] = current + 1
# if debug: print "todb:",self.src,self.seq
r = self
elif self.seq == current:
if debug: print "dup sequence log entry ignored"
else:
print "out of sequence log entry ignored", self.seq, current + 1
self.lock.release()
return r
def pr(self):
""""print Q record object"""
sms.prmsg(self.prlogln(self))
def dispatch(self, src):
""""process new db rec (fm logf,user,net) to where it goes"""
self.lock.acquire()
self.seq = int(self.seq)
if self.seq == -1: # assign new seq num
self.seq = self.hiseq.get(self.src, 0) + 1
r = self.todb()
self.lock.release()
if r: # if new
self.pr()
if src != 'logf': self.tolog()
if src == 'user': net.bc_qsomsg(self.src, self.seq)
if self.band == '*set':
m = gd.setv(r.call, r.rept, r.date)
if not m: r = None
else:
self.logdup()
return r
def bandrpt(self):
"""band report q/band pwr/band, q/oper q/logr q/station"""
qpb, ppb, qpop, qplg, qpst, tq, score, maxp = {}, {}, {}, {}, {}, 0, 0, 0
cwq, digq, fonq = 0, 0, 0
qpgop, gotaq, nat, sat = {}, 0, [], []
dummy, c, g = self.cleanlog()
for i in c.values() + g.values():
if re.search('sat', i.band): sat.append(i)
if 'n' in i.powr: nat.append(i)
# stop ignoring above 100 q's per oper per new gota rules
# GOTA q's stop counting over 400 (500 in 2009)
if i.src == 'gotanode': # analyze gota limits
qpgop[i.oper] = qpgop.get(i.oper, 0) + 1
qpop[i.oper] = qpop.get(i.oper, 0) + 1
qplg[i.logr] = qplg.get(i.logr, 0) + 1
qpst[i.src] = qpst.get(i.src, 0) + 1
if gotaq >= 500: continue # stop over 500 total
gotaq += 1
tq += 1
score += 1
if 'c' in i.band:
cwq += 1
score += 1
qpb['gotac'] = qpb.get('gotac', 0) + 1
ppb['gotac'] = max(ppb.get('gotac', 0), ival(i.powr))
if 'd' in i.band:
digq += 1
score += 1
qpb['gotad'] = qpb.get('gotad', 0) + 1
ppb['gotad'] = max(ppb.get('gotad', 0), ival(i.powr))
if 'p' in i.band:
fonq += 1
qpb['gotap'] = qpb.get('gotap', 0) + 1
ppb['gotap'] = max(ppb.get('gotap', 0), ival(i.powr))
continue
qpb[i.band] = qpb.get(i.band, 0) + 1
ppb[i.band] = max(ppb.get(i.band, 0), ival(i.powr))
maxp = max(maxp, ival(i.powr))
qpop[i.oper] = qpop.get(i.oper, 0) + 1
qplg[i.logr] = qplg.get(i.logr, 0) + 1
qpst[i.src] = qpst.get(i.src, 0) + 1
score += 1
tq += 1
if 'c' in i.band:
score += 1 # extra cw and dig points
cwq += 1
if 'd' in i.band:
score += 1
digq += 1
if 'p' in i.band:
fonq += 1
return (qpb, ppb, qpop, qplg, qpst, tq, score, maxp, cwq, digq, fonq, qpgop, gotaq, nat, sat)
def bands(self):
""" .ba command band status station on, q/band, xx needs upgd"""
# This function from 152i
qpb, tmlq, dummy = {}, {}, {}
self.lock.acquire()
for i in self.byid.values():
if ival(i.powr) < 1: continue
if i.band == 'off': continue
v = 1
if i.rept[:5] == '*del:': v = -1
qpb[i.band] = qpb.get(i.band, 0) + v # num q's
tmlq[i.band] = max(tmlq.get(i.band, ''), i.date) # time of last (latest) q
self.lock.release()
print
print "Stations this node is hearing:"
# scan for stations on bands
for s in net.si.nodes.values(): # xx
# print dir(s)
print s.nod, s.host, s.ip, s.stm
# nod[s.bnd] = s.nod_on_band()
# print "%8s %4s %18s %s"%(s.nod,s.bnd,s.msc,s.stm)
# s.stm,s.nod,seq,s.bnd,s.msc
# i.tm,i.fnod,i.fip,i.stm,i.nod,i.seq,i.bnd,i.msc
d = {}
print
print "Node Info"
print "--node-- band --opr lgr pwr----- last"
for t in net.si.nodinfo.values():
dummy, dummy, age = d.get(t.nod, ('', '', 9999))
if age > t.age: d[t.nod] = (t.bnd, t.msc, t.age)
for t in d:
print "%8s %4s %-18s %4s" % (t, d[t][0], d[t][1], d[t][2]) # t.bnd,t.msc,t.age)
print
print " band -------- cw ----- ------- dig ----- ------- fon -----"
print " nod Q's tslq nod Q's tslq nod Q's tslq"
# xxxxxx yyyyyy xxxx xxxxx yyyyyy xxxx xxxxx yyyyyy xxxx xxxxx
t1 = now()
for b in (160, 80, 40, 20, 15, 10, 6, 2, 220, 440, 900, 1200, 'Sat'):
print "%6s" % b,
for m in 'cdp':
bm = "%s%s" % (b, m)
# be nice to do min since q instead of time of last q --- DONE
t2 = tmlq.get(bm, '') # time since last Q minutes
if t2 == '':
tdif = ''
else:
tdif = int(tmsub(t1, t2) / 60.)
tmin = tdif % 60
tdhr = tdif / 60
if tdhr > 99: tdhr = 99
tdif = tdhr * 100 + tmin
# if tdif > 9999: tdif = 9999
# tdif = str(int(tdif)) # be nice to make this hhmm instead of mmmm
# t = "" # time of latest Q hhmm
# m = re.search(r"([0-9]{4})[0-9]{2}$",tmlq.get(bm,''))
# if m: t = m.group(1)
nob = net.si.nod_on_band(bm) # node now on band
if len(nob) == 0:
nob = '' # list take first item if any
else:
nob = nob[0]
print "%6s %4s %5s" % \
(nob[0:6], qpb.get(bm, ''), tdif), # was t
# (nod.get(bm,'')[0:5],qpb.get(bm,''),t),
print
def sfx2call(self, suffix, band):
"""return calls w suffix on this band"""
return self.bysfx.get(suffix + '.' + band, [])
def qparse(self, line):
""""qso/call/partial parser"""
# check for valid input at each keystroke
# return status, time, extended call, base call, suffix, report
# stat: 0 invalid, 1 partial, 2 suffix, 3 prefix, 4 call, 5 full qso
# example --> :12.3456 wb4ghj/ve7 2a sf Steve in CAN
stat, tm, pfx, sfx, call, xcall, rept = 0, '', '', '', '', '', ''
# break into basic parts: time, call, report
m = re.match(r'(:([0-9.]*)( )?)?(([a-z0-9/]+)( )?)?([0-9a-zA-Z ]*)$', line)
if m:
tm = m.group(2)
xcall = m.group(5)
rept = m.group(7)
stat = 0
if m.group(1) > '' or xcall > '': stat = 1
# print; print "tm [%s] xcall [%s] rept [%s]"%(tm,xcall,rept)
if tm > '':
stat = 0
m = re.match(r'([0-3]([0-9]([.]([0-5]([0-9]([0-5]([0-9])?)?)?)?)?)?)?$', tm)
if m:
stat = 1 # at least partial time
if xcall > '':
stat = 0 # invalid unless something matches
m = re.match(r'([a-z]+)$', xcall)
if m:
stat = 2 # suffix
sfx = xcall
m = re.match(r'([0-9]+)$', xcall)
if m:
stat = 2 # suffix
sfx = xcall
m = re.match(r'([a-z]+[0-9]+)$', xcall)
if m:
stat = 3 # prefix
pfx = xcall
m = re.match(r'([0-9]+[a-z]+)$', xcall)
if m:
stat = 3 # prefix
pfx = xcall
m = re.match(r'(([a-z]+[0-9]+)([a-z]+))(/[0-9a-z]*)?$', xcall)
if m:
stat = 4 # whole call
call = m.group(1)
pfx = m.group(2)
sfx = m.group(3)
m = re.match(r'(([0-9]+[a-z]+)([0-9]+))(/[0-9a-z]*)?$', xcall)
if m:
stat = 4 # whole call
call = m.group(1)
pfx = m.group(2)
sfx = m.group(3)
if (stat == 4) & (rept > ''):
stat = 0
m = re.match(r'[0-9a-zA-Z]+[0-9a-zA-Z ]*$', rept)
if m:
stat = 5 # complete qso
if len(xcall) > 12: stat = 0 # limit lengths
if len(pfx) > 5: stat = 0
if len(sfx) > 3: stat = 0
if tm: # if forced time exists
if len(tm) < 7: # it must be complete
stat = 0
# print "stat[%s] time[%s] pfx[%s] sfx[%s] call[%s] xcall[%s] rpt[%s]"%\
# (stat,tm,pfx,sfx,call,xcall,rept)
return (stat, tm, pfx, sfx, call, xcall, rept)
def dupck(self, wcall, band):
"""check for duplicate call on this band"""
dummy, dummy, dummy, sfx, call, xcall, dummy = self.qparse(wcall)
if gd.getv('contst').upper() == "VHF":
return xcall in self.sfx2call(sfx, band) # vhf contest
return call in self.sfx2call(sfx, band) # field day
# Added function to test against participants like dupes
# Added function to test against call and gota call like dupes
def partck(self, wcall):
""" check for participants to act as dupes in this event"""
dummy, dummy, dummy, dummy, call, xcall, dummy = self.qparse(wcall)
l = []
for i in participants.values():