-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
106 lines (99 loc) · 2.87 KB
/
main.go
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
package main
import (
"fmt"
"github.com/Matir/adifparser"
"io"
"log"
"math"
"os"
"strconv"
)
func main() {
reader := adifparser.NewADIFReader(os.Stdin)
records := make([]adifparser.ADIFRecord, 0)
qsoPoints := 0
for rec, err := reader.ReadRecord(); err != io.EOF; {
if err != nil {
log.Fatalf("%v", err)
}
if rec == nil {
continue
}
records = append(records, rec)
call := safeGet(rec, "call")
mode := safeGet(rec, "mode")
if mode == "SSB" {
log.Printf("%v QSO with %v is worth 1 point", mode, call)
qsoPoints += 1
} else if mode == "MFSK" {
log.Printf("%v QSO with %v is worth 2 points", mode, call)
qsoPoints += 2
}
rec, err = reader.ReadRecord()
}
log.Printf("Read %d records", reader.RecordCount())
bandModeMultiplier := 2
powerMultiplier := 4
bonusPoints := 4500
totalScore := qsoPoints*powerMultiplier*bandModeMultiplier + bonusPoints
outputCabrillo(totalScore, records)
}
func outputCabrillo(totalScore int, records []adifparser.ADIFRecord) {
fmt.Println("START-OF-LOG: 3.0")
fmt.Println("Created-By: K0SWE adi2cbr v0.1")
fmt.Println("CONTEST: WFD")
fmt.Println("CALLSIGN: K0SWE")
fmt.Println("LOCATION: Westminster, CO, USA")
fmt.Println("ARRL-SECTION: CO")
fmt.Println("CATEGORY: 1O")
fmt.Println("CATEGORY-POWER: QRP")
fmt.Println("SOAPBOX: 1,500 points for not using commercial power")
fmt.Println("SOAPBOX: 1,500 points for setting up outdoors")
fmt.Println("SOAPBOX: 1,500 points for setting up away from home")
fmt.Println("SOAPBOX: BONUS Total 4,500")
fmt.Printf("CLAIMED-SCORE: %d\n", totalScore)
fmt.Println("OPERATORS: K0SWE")
fmt.Println("NAME: Chris Keller")
fmt.Println("ADDRESS: 5526 W 118th Ave")
fmt.Println("ADDRESS-CITY: Westminster")
fmt.Println("ADDRESS-STATE: CO")
fmt.Println("ADDRESS-POSTALCODE: 80020")
fmt.Println("ADDRESS-COUNTRY: United States")
fmt.Println("EMAIL: xylo04@gmail.com")
for _, rec := range records {
if rec == nil {
log.Print("Skipping over a nil record")
continue
}
freqStr := safeGet(rec, "freq")
mode := safeGet(rec, "mode")
call := safeGet(rec, "call")
qsoDate := safeGet(rec, "qso_date")
timeOn := safeGet(rec, "time_on")
class := safeGet(rec, "class")
arrlSect := safeGet(rec, "arrl_sect")
freq, err := strconv.ParseFloat(freqStr, 64)
if err != nil {
log.Fatalf("error converting %v to a float: %v", freqStr, err)
}
freq = math.Round(freq * 1000)
switch mode {
case "SSB":
mode = "PH"
case "MFSK":
mode = "DI"
}
qsoDate = qsoDate[0:4] + "-" + qsoDate[4:6] + "-" + qsoDate[6:8]
timeOn = timeOn[0:4]
fmt.Printf("QSO: %6d %-2v %v %v K0SWE 1O CO %-6v %-3v %-3v\n",
int(freq), mode, qsoDate, timeOn, call, class, arrlSect)
}
fmt.Println("END-OF-LOG:")
}
func safeGet(rec adifparser.ADIFRecord, key string) string {
value, err := rec.GetValue(key)
if err != nil {
log.Fatalf("error getting %v from adif: %v", key, err)
}
return value
}