-
Notifications
You must be signed in to change notification settings - Fork 7
/
FDLog_Enhanced.py
4848 lines (4540 loc) · 189 KB
/
FDLog_Enhanced.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
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/python3
# Added by Art Miller KC7SDA May/5/2017
# tkinter errors in linux are fixed by running "sudo apt-get install python3-tk" - Scott Hibbs KD4SIR 01Dec2023
import tkinter
import os
import time
import sys
import re
import _thread
import threading
import socket
import hashlib
import random
import sqlite3
from tkinter import END, NORMAL, DISABLED, Toplevel, Frame, Label, Entry, Button, \
W, EW, E, NONE, NSEW, NS, StringVar, Radiobutton, Tk, Menu, Menubutton, Text, Scrollbar, \
Checkbutton, RAISED, IntVar, Listbox
# Current version 2023_Beta 4.0.0 03Dec2023 (Contestant Awareness)
# Thanks to David (github.com/B1QUAD) 2022 for help with the python 3 version.
# Main program starts about line 4323
# all history moved to release.txt file
prog = 'FDLog_Enhanced v2023_Beta 4.0.0 03Dec2023\n\n' \
'Forked with thanks from FDLog by Alan Biocca (W6AKB) Copyright 1984-2017 \n' \
'FDLog_Enhanced by Scott A Hibbs (KD4SIR) Copyright 2013-2023. \n' \
'FDLog_Enhanced is under the GNU Public License v2 without warranty. \n'
about = """
FDLog_Enhanced can be found on https://github.com/scotthibbs/FDLog_Enhanced
Forked with thanks from FDLog by Alan Biocca (W6AKB) Copyright 1984-2017
Previous code contributors were:
Eric WD6CMU, Steve KA6S, Glenn WB6W, Frank WB6MRQ and others
FDLog_Enhanced by Scott A Hibbs (KD4SIR) Copyright 2013-2023.
Copyright also shared with Code Contributors:
Art Miller KC7SDA 2019 Curtis E. Mills WE7U 2019
David (github.com/B1QUAD) 2022 ChatGPTv3.5 2023
"""
# Known Bug List
#
# some foreign call signs 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_Enhanced.py').read()
h = hashlib.md5()
t = t.encode()
h.update(t)
print(" FDLog_Enhanced Fingerprint", h.hexdigest())
def ival(s):
"""return value of leading int"""
r = 0
if s != "":
mm = re.match(r' *(-?\d*)', s)
if mm and mm.group(1):
r = int(mm.group(1))
return r
class ClockClass:
"""Keeping time with update, calib, and adjust functions"""
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 __init__(self):
pass
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 == str.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"""
# numbers adjusted from ChatGPTv3.5 conversation.
rate = 0.1 # delta seconds each second
# thus the clock offset will be adjusted by a maximum of (rate) seconds each second.
threshold = 0.01 # adjust if error is greaater than this threshold
# previously .001 (one hundreth of a second) changed to a tenth of a second 30Nov2023 Scott Hibbs KD4SIR
adj = self.adjusta
if abs(adj) < threshold:
return
if adj > rate:
adj = rate
elif adj < -rate:
adj = -rate + 0.05 # This so it doesn't kick back and forth - 30Nov2023 Scott KD4SIR
# ChatGPT3.5 recommended "...0.05 # small positive offset to prevent oscillations" - ChatGPTv3.5
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, "difference is:", self.adjusta)
def initialize():
# code cleanup and modify (refactor), added wfd support Art Miller KC7SDA 2019
kinp = "" # keyboard input
anscount = "" # 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 anscount != "1":
kinp = str.lower(str.strip(sys.stdin.readline())[:1])
if kinp == "y":
anscount = "1"
if kinp == "n":
anscount = '1'
if anscount != "1":
print("Press Y or N please")
if kinp == "y":
# Field Day or VHF contest
anscount = ""
print("Which contest is this?")
print("F = FD, W = WFD, and V = VHF")
while anscount != "1":
kinp = str.lower(str.strip(sys.stdin.readline())[:1])
if kinp == "f":
anscount = "1"
if kinp == "w":
anscount = "1"
if kinp == "v":
anscount = '1'
if anscount != "1":
print("Press F, W or V please")
if kinp == "f":
kfd = 1 # used later to skip grid square question.
globDb.put('contst', "FD")
qdb.globalshare('contst', "FD") # global to db
renew_title()
print("Have a nice Field Day!")
if kinp == "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 kinp == "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?")
kinp = str.strip(sys.stdin.readline())
while kinp == "":
print("Please type the NAME of your club or group")
kinp = str.strip(sys.stdin.readline())
globDb.put('grpnam', kinp)
qdb.globalshare('grpnam', kinp) # global to db
renew_title()
print(kinp, "is a nice name.")
# Club Call
# Fixed lower case so Club and GOTA it would match dupe check - Scott Hibbs 18Jun2022
print("What will be your club call?")
kinp = str.strip(sys.stdin.readline())
kinp = kinp.lower()
while kinp == "":
print("Please type the club call.")
kinp = str.strip(sys.stdin.readline())
kinp = kinp.lower()
globDb.put('fdcall', kinp)
qdb.globalshare('fdcall', kinp) # global to db
renew_title()
print(kinp, "will be the club call.")
# Gota Call
if kfd == 1:
print("What will be your GOTA call?")
kinp = str.strip(sys.stdin.readline())
kinp = kinp.lower()
while kinp == "":
print("Please type the GOTA call. (if none type none)")
kinp = str.strip(sys.stdin.readline())
kinp = kinp.lower()
else:
globDb.put('gcall', kinp)
qdb.globalshare('gcall', kinp) # global to db
renew_title()
print(kinp, "will be the GOTA call.")
# Class
print("What will be your class? (like 2A)")
kinp = str.strip(sys.stdin.readline())
while kinp == "":
print("Please type the class.")
kinp = str.strip(sys.stdin.readline())
else:
globDb.put('class', kinp)
qdb.globalshare('class', kinp) # global to db
renew_title()
print(kinp, "will be the class.")
# Section
print("What will be your section? (like IN-Indiana)")
kinp = str.strip(sys.stdin.readline())
while kinp == "":
print("Please type the section (like KY-Kentucky).")
kinp = str.strip(sys.stdin.readline())
else:
globDb.put('sect', kinp)
qdb.globalshare('sect', kinp) # global to db
renew_title()
print(kinp, "will be the section.")
if kfd == 0:
# grid square
print("What will be your grid square? (if none type none)")
kinp = str.strip(sys.stdin.readline())
while kinp == "":
print("Please type the grid square. (For FD type none)")
kinp = str.strip(sys.stdin.readline())
kinp = kinp.upper() # changed the init so the grid square will be caps -Art Miller KC7SDA 2019
else:
globDb.put('grid', kinp)
qdb.globalshare('grid', kinp) # global to db
renew_title()
print(kinp, "will be the grid.")
if kfd != 2:
# questions for vhf and fd, skip for wfd
# Public Place
anscount = ""
print("Will the location be in a public place?")
print("Y = yes and N = no")
while anscount != "1":
kinp = str.lower(str.strip(sys.stdin.readline())[:1])
if kinp == "y":
anscount = "1"
if kinp == "n":
anscount = '1'
if anscount == "":
print("Press Y or N please")
if kinp == "y":
globDb.put('public', "A public location")
qdb.globalshare('public', "A public location") # global to db
renew_title()
print("Enjoy the public place.")
if kinp == "n":
globDb.put('public', "")
qdb.globalshare('public', "") # global to db
renew_title()
print("maybe next year...")
# Info Booth
anscount = ""
print("Will you have an info booth?")
print("Y = yes and N = no")
while anscount != "1":
kinp = str.lower(str.strip(sys.stdin.readline())[:1])
if kinp == "y":
anscount = "1"
if kinp == "n":
anscount = '1'
if anscount == "":
print("Press Y or N please")
if kinp == "y":
globDb.put('infob', "1")
qdb.globalshare('infob', "1") # global to db
renew_title()
print("Love information tables!")
if kinp == "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
anscount = ""
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 anscount != "1":
kinp = str.lower(str.strip(sys.stdin.readline())[:1])
if kinp == "y":
anscount = "1"
if kinp == "n":
anscount = '1'
if anscount == "":
print("Press Y or N please")
if kinp == "y":
globDb.put('tmast', node)
qdb.globalshare('tmast', node) # global to db
renew_title()
print("Time travels to you!")
if kinp == "n":
pass
return
def exin(op):
"""extract Contestant or logger initials"""
r = ""
corlinit = re.match(r'([a-z\d]{2,3})', op)
if corlinit:
r = corlinit.group(1)
return r
def fntcourier10():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Courier"
fontsize = 10
fdfont = typeface, fontsize
redrawall()
def fntcourier11():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Courier"
fontsize = 11
fdfont = typeface, fontsize
redrawall()
def fntcourier12():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Courier"
fontsize = 12
fdfont = typeface, fontsize
redrawall()
def fntcourier13():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Courier"
fontsize = 13
fdfont = typeface, fontsize
redrawall()
def fntcourier14():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Courier"
fontsize = 14
fdfont = typeface, fontsize
redrawall()
def fntconsolas10():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Consolas"
fontsize = 10
fdfont = typeface, fontsize
redrawall()
def fntconsolas11():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Consolas"
fontsize = 11
fdfont = typeface, fontsize
redrawall()
def fntconsolas12():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Consolas"
fontsize = 12
fdfont = typeface, fontsize
redrawall()
def fntconsolas13():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Consolas"
fontsize = 13
fdfont = typeface, fontsize
redrawall()
def fntconsolas14():
""" Font menu selection to change the font and size"""
# Added by Scott Hibbs KD4SIR 09Aug2022
global typeface, fontsize, fdfont
typeface = "Consolas"
fontsize = 14
fdfont = typeface, fontsize
redrawall()
def redrawall():
""" Used by Font menu selections to redraw all the elements again """
# Added by Scott Hibbs KD4SIR 09Aug2022
global fdfont
lblnet.config(font=fdfont)
lblnode.config(font=fdfont)
bandbuttons(f1)
bandset(band)
opmb.config(font=fdfont)
opmu.config(font=fdfont)
opds.config(font=fdfont)
opdsu.config(font=fdfont)
logmb.config(font=fdfont)
logmu.config(font=fdfont)
logds.config(font=fdfont)
logdsu.config(font=fdfont)
pwrmb.config(font=fdfont)
pwrmu.config(font=fdfont)
pwrnt.config(font=fdfont)
powlbl.config(font=fdfont)
powcb.config(font=fdfont)
redrawbutton.config(font=fdfont)
extrabutton.config(font=fdfont)
renew_title()
logwredraw()
topper()
class SQDB:
"""SQL database upgrade"""
# sqlite3.connect(":memory:", check_same_thread = False)
# I found this online to correct thread errors with sql locking to one thread only.
# Scott Hibbs 7/5/2015
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 - Scott Hibbs 7/17/2015
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
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)
sqdb1 = sqlite3.connect(self.dbPath) # connect to the database
# self.sqdb.row_factory = sqlite3.Row # namedtuple_factory
curs = sqdb1.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?
sqdb1.commit() # do the commit
if n.band == '*QST':
print(("QST\a " + n.rept + " -" + n.logr)) # The "\a" will emit the beep sound for QST
class QsoDb:
""" This is the database class for QSOs. """
def __init__(self):
self.seq = None
byid = {} # qso database by src.seq
bysfx = {} # call list by suffix.band
hiseq = {} # high sequence number by node
lock = threading.RLock() # sharing lock
@staticmethod
def new(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 = open(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 from text"""
(dummy, self.src, self.seq, self.date, self.band, self.call, self.rept, self.powr, self.oper,
self.logr, dummy) = str.split(line, '|')
self.seq = int(self.seq)
self.dispatch('logf')
@staticmethod
def loadfile():
""" Used to load the log file"""
# global sqdb # setup sqlite database connection
print("Loading Log File")
icounter, s, log = 0, 0, []
sqdb = SQDB() # type: 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)
icounter += 1
except ValueError as ee:
print(" error, item skipped: ", ee)
print(" in:", ln)
s += 1
# sqdb.log(r)
# push a copy from the file into the
# database (temporary for transition)
if icounter == 0 and s == 1:
print("Log file not found, must be new")
initialize() # Set up routine - Scott Hibbs 7/26/2015
else:
print(" ", icounter, "Records Loaded,", s, "Errors")
if icounter == 0:
initialize()
def cleanlog(self):
"""return clean filtered dictionaries of the log"""
d, cdict, gdict = {}, {}, {}
fdstart, fdend = gd.getv('fdstrt'), gd.getv('fdend')
self.lock.acquire()
for index in list(self.byid.values()): # copy, index by node, sequence
strsrcseq = "%s|%s" % (index.src, index.seq)
d[strsrcseq] = index
self.lock.release()
for index in list(d.keys()): # process deletes
if index in d:
iv = d[index]
if iv.rept[:5] == "*del:":
dummy, st, sn, dummy = iv.rept.split(':') # extract deleted id
strsrcseq = "%s|%s" % (st, sn)
if strsrcseq in list(d.keys()):
# print iv.rept,; iv.pr()
del (d[strsrcseq]) # delete it
# else: print "del target missing",iv.rept
del (d[index])
for index in list(d.keys()): # filter time window
iv = d[index]
if iv.date < fdstart or iv.date > fdend:
# print "discarding out of date range",iv.date,iv.src,iv.seq
del (d[index])
for index in list(d.values()): # re-index by call-band
dummy, dummy, dummy, dummy, call1, dummy, dummy = self.qparse(index.call) # extract call (not /...)
strsrcseq = "%s-%s" % (call1, index.band)
# filter out noncontest entries
if ival(index.powr) == 0 and index.band[0] != '*':
continue
if index.band == 'off':
continue
if index.band[0] == '*':
continue # rm special msgs
if index.src == 'gotanode':
gdict[strsrcseq] = index # gota is separate dup space
else:
cdict[strsrcseq] = index
return d, cdict, gdict # Deletes processed, fully Cleaned
# by id, call-bnd, gota by call-bnd
@staticmethod
def prlogln(s):
"""convert log item to display format"""
# note that a lot of functions read data by location 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 the log, in time order"""
llist = self.filterlog("")
for strii in llist:
print(strii)
def pradif(self):
"""print clean log in adif format"""
pgm = "FDLog_Enhanced (https://github.com/scotthibbs/FDLog_Enhanced)"
print("<PROGRAMID:%d>%s" % (len(pgm), pgm))
dummy, n, strgg = self.cleanlog()
for iii in list(n.values()) + list(strgg.values()):
dat = "20%s" % iii.date[0:6]
tim = iii.date[7:11]
cal = iii.call
bnd = "%sm" % iii.band[:-1]
mod = iii.band[-1:]
if mod == 'p':
mod = 'SSB'
elif mod == 'c':
mod = 'CW'
elif mod == 'd':
mod = 'RTTY'
com = iii.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 filterlog(self, filt):
"""list filtered (by bandm) log in time order, nondup valid q's only"""
somelocallist2 = []
dummy, n, gg = self.cleanlog()
for i6 in list(n.values()) + list(gg.values()):
if filt == "" or re.match('%s$' % filt, i6.band):
somelocallist2.append(i6.prlogln(i6))
somelocallist2.sort()
return somelocallist2
def filterlog2(self, filt):
"""list filtered (by bandm) log in time order, including special msgs"""
somelocallist3 = []
mm, dummy, dummy = self.cleanlog()
for i7 in list(mm.values()):
if filt == "" or re.match('%s$' % filt, i7.band):
somelocallist3.append(i7.prlogln(i7))
somelocallist3.sort()
return somelocallist3
def filterlog3(self, filt):
"""list filtered (by mode) log in time order, including special msgs"""
# Added by Scott Hibbs KD4SIR 05Aug2022
somelocallist3z = []
mmz, dummy, dummy = self.cleanlog()
for i7z in list(mmz.values()):
if filt in i7z.band:
somelocallist3z.append(i7z.prlogln(i7z))
somelocallist3z.sort()
return somelocallist3z
def filterlogst(self, filt):
"""list filtered (by nod) log in time order, including special msgs"""
somelocallist4 = []
mmm, dummy, dummy = self.cleanlog()
for i8 in list(mmm.values()):
if re.match('%s$' % filt, i8.src):
somelocallist4.append(i8.prlogln(i8))
somelocallist4.sort()
return somelocallist4
def qsl(self, time1, call3, bandmod, report):
"""log a qsl"""
return self.postnewinfo(time1, call3, bandmod, report)
def qst(self, msg):
"""put a qst in database + log"""
return self.postnewinfo(now(), '', '*QST', msg)
def globalshare(self, name1, value):
"""put global var set in db + log"""
return self.postnewinfo(now(), name1, '*set', value)
def postnewinfo(self, time2, call4, bandmod, report):
"""post new locally generated info"""
# Added tmob so that we can count time inactive - Scott Hibbs KD4SIR 09Aug2022
global tmob
tmob = now()
return self.postnew(time2, call4, bandmod, report, exin(operator),
exin(logger), power)
def postnew(self, time3, call5, 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 = time3, call5, bandmod, report, oper, logr, powr
s.seq = -1
return s.dispatch('user')
def qdelete(self, nod, seq, reason):
"""remove a Qso by creating delete record"""
global node
# print "del",nod,seq
a, dummy, dummy = self.cleanlog()
k3 = "%s|%s" % (nod, seq)
if k3 in a and a[k3].band[0] != '*': # only visible qso records
tm, call6, bandmod = a[k3].date, a[k3].call, a[k3].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(), call6, bandmod, rept, exin(operator), exin(logger), 0
s.seq = -1
s.dispatch('user')
txtbillb.insert(END, " DELETE Successful %s %s %s\n" % (tm, call6, bandmod))
topper()
logw.config(state=NORMAL)
logw.delete(0.1, END)
logw.insert(END, "\n")
# This Redraws 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.
# Scott Hibbs KD4SIR - 03Jul2018
# Fixed so that it wasn't printing in all blue - Scott Hibbs KD4SIR 31Jul2022
# i9.prlogln(i9) gives the line of the log output.
for i9 in list(a.values()):
if i9.seq == seq:
continue
else:
if node in i9.prlogln(i9):
logw.insert(END, i9.prlogln(i9), "b")
logw.insert(END, "\n")
else:
logw.insert(END, i9.prlogln(i9))
logw.insert(END, "\n")
logw.config(state=DISABLED)
else:
txtbillb.insert(END, " DELETE Ignored [%s,%s] Not Found\n" % (nod, seq))
topper()
def udelete(self, nod, seq, reason):
"""remove a user by creating delete record"""
# Added by Scott Hibbs KD4SIR 22Aug2022
global node
a, dummy, dummy = self.cleanlog()
k5 = "%s|%s" % (nod, seq)
if k5 in a: # check if in log
tm, call6, bandmod = a[k5].date, a[k5].call, a[k5].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(), call6, bandmod, rept, exin(operator), exin(logger), 0
s.seq = -1
s.dispatch('udelete')
txtbillb.insert(END, " DELETE Successful %s %s %s\n" % (tm, call6, bandmod))
topper()
logw.config(state=NORMAL)
logw.delete(0.1, END)
logw.insert(END, "\n")
# This Redraws 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.
# Scott Hibbs KD4SIR - 03Jul2018
# Fixed so that it wasn't printing in all blue - Scott Hibbs KD4SIR 31Jul2022
# i9.prlogln(i9) is the line of the log output that was read.
for i9 in list(a.values()):
if i9.seq == seq:
continue
else:
if node in i9.prlogln(i9):
logw.insert(END, i9.prlogln(i9), "b")
logw.insert(END, "\n")
else:
logw.insert(END, i9.prlogln(i9))
logw.insert(END, "\n")
logw.config(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"""
# src is the reason this was called.
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: # r was set to self.todb() so always true
self.pr() # prints the q record object
if src != 'logf':
self.tolog()
if src == 'user':
net.bc_qsomsg(self.src, self.seq)
if self.band == '*set':
# oper is initials of person at the node;
# call is p:initials of new person;
# rept is "initials, name, call, age, title" of new person
# self.src is the node in the log entry?
if src == 'udelete':
net.bc_qsomsg(self.src, self.seq)
else:
m5 = gd.setv(r.call, r.rept, r.date)
if not m5:
r = None
else:
self.logdup()
return r # remember r is self.todb()
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, [], []
# qso per band, power per band, qso per operator, qso per logger, qso per station, total qsos,
# score points, max power, cw qsos, digital qsos, phone qsos, qso per gota operator, gota qsos,
# natural power, satelite
dummy, c1, g3 = self.cleanlog() # by id, call-bnd, gota by call-bnd
for i10 in list(c1.values()) + list(g3.values()):
if re.search('sat', i10.band):
sat.append(i10)
if 'n' in i10.powr:
nat.append(i10)
# stop ignoring above 100 q's per oper per new gota rules. - Alan Biocca (W6AKB) Jun2005
# GOTA q's stop counting over 400 (500 in 2009)
if i10.src == 'gotanode': # analyze gota limits
qpgop[i10.oper] = qpgop.get(i10.oper, 0) + 1
qpop[i10.oper] = qpop.get(i10.oper, 0) + 1
qplg[i10.logr] = qplg.get(i10.logr, 0) + 1
qpst[i10.src] = qpst.get(i10.src, 0) + 1
if gotaq >= 500:
continue # stop over 500 total
gotaq += 1
tq += 1
score += 1
if 'c' in i10.band:
cwq += 1
score += 1
qpb['gotac'] = qpb.get('gotac', 0) + 1
ppb['gotac'] = max(ppb.get('gotac', 0), ival(i10.powr))
if 'd' in i10.band:
digq += 1
score += 1
qpb['gotad'] = qpb.get('gotad', 0) + 1
ppb['gotad'] = max(ppb.get('gotad', 0), ival(i10.powr))
if 'p' in i10.band:
fonq += 1
qpb['gotap'] = qpb.get('gotap', 0) + 1
ppb['gotap'] = max(ppb.get('gotap', 0), ival(i10.powr))
continue
qpb[i10.band] = qpb.get(i10.band, 0) + 1
ppb[i10.band] = max(ppb.get(i10.band, 0), ival(i10.powr))
maxp = max(maxp, ival(i10.powr))
qpop[i10.oper] = qpop.get(i10.oper, 0) + 1
qplg[i10.logr] = qplg.get(i10.logr, 0) + 1
qpst[i10.src] = qpst.get(i10.src, 0) + 1
score += 1
tq += 1
if 'c' in i10.band:
score += 1 # extra cw and dig points
cwq += 1
if 'd' in i10.band:
score += 1
digq += 1
if 'p' in i10.band:
fonq += 1
return qpb, ppb, qpop, qplg, qpst, tq, score, maxp, cwq, digq, fonq, qpgop, gotaq, nat, sat
def statussofar(self):
""" .ba command band status station on, q/band, xx needs upgd"""
# This function from 152i
qpb, tmlq, dummy = {}, {}, {}
# qso per band, time since last qso,
self.lock.acquire()
for i11 in list(self.byid.values()): # reading qso database by src.seq
if ival(i11.powr) < 1:
continue
if i11.band == 'off':
continue
v = 1
if i11.rept[:5] == '*del:':
v = -1
qpb[i11.band] = qpb.get(i11.band, 0) + v # num q's
tmlq[i11.band] = max(tmlq.get(i11.band, ''), i11.date) # time of last (latest) q
self.lock.release()
print()
print("Stations this node is hearing:")
# scan for stations on bands
for s in list(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----- Min last heard")
for t in list(net.si.nodinfo.values()):
dummy, dummy, age1 = d.get(t.nod, ('', '', 9999))
if age1 > 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, end=' ')
for m3 in 'cdp':
bm1 = "%s%s" % (b, m3)
t2 = tmlq.get(bm1, '') # time since last Q minutes
# if t2 == '':
# tdif = ''
# else:
# tdif = int(tmsub(t1, t2) / 60.)
# tmin = tdif % 60