#!/usr/bin/env python3 # # SM0KBD 240902 v0.1: First version # # Copyright Thomas Nilsson, 2024 # Released under GNU GPLv3 import tkinter as tk from tkinter import ttk from tkinter.filedialog import askopenfilename import string import re def check_line(line): global CW_QSO global SSB_QSO global FM_QSO global MGM_QSO global Other_QSO global Unknown_QSO global QSO_total selector = line[:5] if QSOline.match(selector): QSO_total = QSO_total + 1 x = line.rsplit(";") # Some log programs uses an empty string # Make it unknown if x[3] == '': x[3] = 0 # Find the mode match int(x[3]): case 3,4,5,8,9,10,11: Other_QSO = Other_QSO + 1 return line case 2: CW_QSO = CW_QSO + 1 return line case 1: SSB_QSO = SSB_QSO + 1 return line case 6: FM_QSO = FM_QSO + 1 return line case 7: MGM_QSO = MGM_QSO + 1 return line case _: Unknown_QSO = Unknown_QSO + 1 return line def calculate(edi): # Check if input file has been selected if not 'edi_files' in globals(): tk.messagebox.showerror(title="Files missing", message="No input files selected!") return 0 # To be able to handle almost all formats, open the file as Latin-1 edi_file = open(edi, "r", newline=None, encoding="latin-1") for line in edi_file: line = check_line(line) edi_file.close() return 0 def statistics(): global CW_QSO global SSB_QSO global FM_QSO global MGM_QSO global Other_QSO global Unknown_QSO global QSO_total total_number_of_records = CW_QSO + SSB_QSO + FM_QSO + MGM_QSO + Other_QSO + Unknown_QSO # Check if any QSO records are found if total_number_of_records == 0: tk.messagebox.showerror(title="No QSO records", message="No QSO records found!") return 0 # Do the calculations CW = CW_QSO / total_number_of_records SSB = SSB_QSO / total_number_of_records FM = FM_QSO / total_number_of_records MGM = MGM_QSO / total_number_of_records Other = Other_QSO / total_number_of_records Unknown = Unknown_QSO / total_number_of_records # The following is a raw dump for exporting into spreadsheets print("Raw figures below:") print(str(CW_QSO) + "\n" + str(SSB_QSO) + "\n" + str(FM_QSO) + "\n" + str(MGM_QSO) + "\n" + str(Other_QSO) + "\n" + str(Unknown_QSO) + "\n" + str(total_number_of_records)) status_text = "Distribution:\nCW: {:.1%}\nSSB: {:.1%}\nFM: {:.1%}\nMGM: {:.1%}\nOther: {:.1%}\nUnknown: {:.1%}\nof a total of {:d} QSO".format(CW, SSB, FM, MGM, Other, Unknown, QSO_total ) tk.messagebox.showinfo(title="Statistics", message=status_text) return 0 def reset(): global CW_QSO global SSB_QSO global FM_QSO global MGM_QSO global Other_QSO global Unknown_QSO global QSO_total global edi_files # Set all global variables to 0 or empty string. CW_QSO = 0 SSB_QSO = 0 FM_QSO = 0 MGM_QSO = 0 Other_QSO = 0 Unknown_QSO = 0 QSO_total = 0 edi_files = '' return 0 def iterate_files(): global edi_files for edi in edi_files: print("Checking " + edi[edi.rfind("/")+1:] + "\n") status = calculate(edi) status = statistics() return 0 def selectfiles(): # Handle the input EDI files selection global edi_files edi_files = askopenfilename(multiple=True, filetypes=(("EDI","*edi"),("All","*"),)) QSOline = re.compile(r"\d{5}") reset() # Build a simple interface root = tk.Tk() root.geometry("400x150") root.title("NAC EDI Statistics compiler") frame = ttk.Frame(root) frame.pack() label = ttk.Label(frame, text = "Run mode statistics on a set of EDI files", borderwidth=1, justify=tk.CENTER, padding= 5) button1 = ttk.Button(frame, text = "Select edi-files to run statistics on", command = selectfiles) button1.pack(padx=5, pady=5) button2 = ttk.Button(frame, text = "Calculate", command = iterate_files) button2.pack(padx=5, pady=5) button3 = ttk.Button(frame, text = "Reset", command = reset) button3.pack(padx=5, pady=5) button4 = ttk.Button(frame, text = "Exit", command = lambda: root.quit()) button4.pack(padx=5, pady=5) root.mainloop()