better match dxcc

This commit is contained in:
Gregory Salaun 2024-11-06 15:07:36 +07:00
parent 861a5ff14b
commit 10f936838f
10 changed files with 123 additions and 116 deletions

BIN
FlexDXCluster.exe~ Normal file

Binary file not shown.

View File

@ -149,7 +149,7 @@ func (c *TCPClient) ReadLine() {
Log.Info("Start receiving spots") Log.Info("Start receiving spots")
} }
go ProcessTelnetSpot(spotRe, message, c.SpotChanToFlex, c.SpotChanToHTTPServer, c.Countries) ProcessTelnetSpot(spotRe, message, c.SpotChanToFlex, c.SpotChanToHTTPServer, c.Countries)
// Send the spot message to TCP server // Send the spot message to TCP server
if len(c.TCPServer.Clients) > 0 { if len(c.TCPServer.Clients) > 0 {

View File

@ -1,7 +1,7 @@
general: general:
delete_log_file_at_start: true delete_log_file_at_start: true
log_to_file: true log_to_file: true
log_level: INFO # INFO or DEBUG or WARN log_level: DEBUG # INFO or DEBUG or WARN
httpserver: true # not in use for now httpserver: true # not in use for now
telnetserver: true # not in use for now telnetserver: true # not in use for now
flexradiospot: true # not in use for now flexradiospot: true # not in use for now
@ -13,7 +13,7 @@ cluster:
port: 7300 port: 7300
login: xv9q login: xv9q
skimmer: true skimmer: true
ft8: false ft8: true
ft4: false ft4: false
command: #SET/NOFILTER command: #SET/NOFILTER
login_prompt: "Please enter your call:" login_prompt: "Please enter your call:"

View File

@ -1918,7 +1918,7 @@
<EndDate>2007-12-31T23:59:59Z</EndDate> <EndDate>2007-12-31T23:59:59Z</EndDate>
</CountryPrefix> </CountryPrefix>
<CountryPrefix> <CountryPrefix>
<PrefixList>^OE.*</PrefixList> <PrefixList>^OE.*|^4U1A$</PrefixList>
<StartDate>2007-12-31T23:59:59Z</StartDate> <StartDate>2007-12-31T23:59:59Z</StartDate>
<EndDate xsi:nil="true" /> <EndDate xsi:nil="true" />
</CountryPrefix> </CountryPrefix>
@ -4883,33 +4883,6 @@
</CountryPrefix> </CountryPrefix>
</CountryPrefixList> </CountryPrefixList>
</Country> </Country>
<Country>
<ArrlPrefix>OK/D</ArrlPrefix>
<Comment />
<Continent>EU</Continent>
<CountryName>Czechoslovakia</CountryName>
<CqZone>15</CqZone>
<CqZoneList>
<int>15</int>
</CqZoneList>
<Dxcc>218</Dxcc>
<ItuZone>28</ItuZone>
<IaruRegion>1</IaruRegion>
<ItuZoneList>
<int>28</int>
</ItuZoneList>
<Latitude>50.1</Latitude>
<Longitude>15.5</Longitude>
<Active>false</Active>
<CountryTag />
<CountryPrefixList>
<CountryPrefix>
<PrefixList>^OK.*|^OL.*|^OM.*</PrefixList>
<StartDate xsi:nil="true" />
<EndDate>1992-12-31T23:59:59Z</EndDate>
</CountryPrefix>
</CountryPrefixList>
</Country>
<Country> <Country>
<ArrlPrefix>CR8/D</ArrlPrefix> <ArrlPrefix>CR8/D</ArrlPrefix>
<Comment /> <Comment />
@ -6510,7 +6483,7 @@
<EndDate>1992-02-29T23:59:59Z</EndDate> <EndDate>1992-02-29T23:59:59Z</EndDate>
</CountryPrefix> </CountryPrefix>
<CountryPrefix> <CountryPrefix>
<PrefixList>^F.*|^HW.*|^HX.*|^HY.*|^TH.*|^TM.*|^TP.*|^TQ.*|^TV.*|^TW.*</PrefixList> <PrefixList>^F1.*|^F2.*|^F3.*|^F4.*|^F5.*|^F6.*|^F7.*|^F8.*|^HW.*|^HX.*|^HY.*|^TH.*|^TM.*|^TP.*|^TQ.*|^TV.*|^TW.*</PrefixList>
<StartDate>1992-02-29T23:59:59Z</StartDate> <StartDate>1992-02-29T23:59:59Z</StartDate>
<EndDate xsi:nil="true" /> <EndDate xsi:nil="true" />
</CountryPrefix> </CountryPrefix>
@ -8147,48 +8120,6 @@
</CountryPrefix> </CountryPrefix>
</CountryPrefixList> </CountryPrefixList>
</Country> </Country>
<Country>
<ArrlPrefix>I5</ArrlPrefix>
<Comment />
<Continent>AF</Continent>
<CountryName>Italian Somali</CountryName>
<CqZone>38</CqZone>
<CqZoneList>
<int>38</int>
</CqZoneList>
<Dxcc>115</Dxcc>
<ItuZone>47</ItuZone>
<IaruRegion>1</IaruRegion>
<ItuZoneList>
<int>47</int>
</ItuZoneList>
<Latitude>2.1</Latitude>
<Longitude>45.4</Longitude>
<Active>false</Active>
<CountryTag />
<CountryPrefixList>
<CountryPrefix>
<PrefixList>^MD4.*|^MS4.*</PrefixList>
<StartDate>1947-03-01T00:00:00Z</StartDate>
<EndDate>1949-12-31T23:59:59Z</EndDate>
</CountryPrefix>
<CountryPrefix>
<PrefixList>^MS4.*</PrefixList>
<StartDate>1949-12-31T23:59:59Z</StartDate>
<EndDate>1950-02-01T00:00:00Z</EndDate>
</CountryPrefix>
<CountryPrefix>
<PrefixList>^I5.*|^MS4.*</PrefixList>
<StartDate>1950-02-01T00:00:00Z</StartDate>
<EndDate>1950-12-31T23:59:59Z</EndDate>
</CountryPrefix>
<CountryPrefix>
<PrefixList>^I5.*</PrefixList>
<StartDate>1950-12-31T23:59:59Z</StartDate>
<EndDate>1960-06-30T23:59:59Z</EndDate>
</CountryPrefix>
</CountryPrefixList>
</Country>
<Country> <Country>
<ArrlPrefix>I</ArrlPrefix> <ArrlPrefix>I</ArrlPrefix>
<Comment /> <Comment />
@ -14929,38 +14860,6 @@
</CountryPrefix> </CountryPrefix>
</CountryPrefixList> </CountryPrefixList>
</Country> </Country>
<Country>
<ArrlPrefix>CN2</ArrlPrefix>
<Comment />
<Continent>AF</Continent>
<CountryName>Tangier</CountryName>
<CqZone>33</CqZone>
<CqZoneList>
<int>33</int>
</CqZoneList>
<Dxcc>264</Dxcc>
<ItuZone>37</ItuZone>
<IaruRegion>1</IaruRegion>
<ItuZoneList>
<int>37</int>
</ItuZoneList>
<Latitude>35.7</Latitude>
<Longitude>-5.8</Longitude>
<Active>false</Active>
<CountryTag />
<CountryPrefixList>
<CountryPrefix>
<PrefixList>^CN2.*|^EK1.*|^EK4.*</PrefixList>
<StartDate xsi:nil="true" />
<EndDate>1952-02-01T00:00:00Z</EndDate>
</CountryPrefix>
<CountryPrefix>
<PrefixList>^CN2.*|^EK1.*|^EK4.*|^KT1.*|^WT1.*</PrefixList>
<StartDate>1952-02-01T00:00:00Z</StartDate>
<EndDate>1960-06-30T23:59:59Z</EndDate>
</CountryPrefix>
</CountryPrefixList>
</Country>
<Country> <Country>
<ArrlPrefix>5H</ArrlPrefix> <ArrlPrefix>5H</ArrlPrefix>
<Comment /> <Comment />

View File

@ -242,7 +242,7 @@ func (r *FlexDXClusterRepository) GetSpotters() []Spotter {
sList := []Spotter{} sList := []Spotter{}
rows, err := r.db.Query("select spotter, count(*) as occurences from spots group by spotter order by occurences desc, spotter limit 7") rows, err := r.db.Query("select spotter, count(*) as occurences from spots group by spotter order by occurences desc, spotter limit 15")
if err != nil { if err != nil {
r.Log.Error(err) r.Log.Error(err)

View File

@ -83,6 +83,7 @@ func (fc *FlexClient) StartFlexClient() {
Log.Infof("Found: %s with Nick: %s, Version: %s, Serial: %s - using IP: %s", d.Model, d.NickName, d.Version, d.Serial, d.IP) Log.Infof("Found: %s with Nick: %s, Version: %s, Serial: %s - using IP: %s", d.Model, d.NickName, d.Version, d.Serial, d.IP)
} else { } else {
Log.Errorln("Could not discover any FlexRadio on the network, please provide an IP address in the config file.") Log.Errorln("Could not discover any FlexRadio on the network, please provide an IP address in the config file.")
fc.StartFlexClient()
} }
} else if Cfg.Flex.IP != "" { } else if Cfg.Flex.IP != "" {
fc.Address = Cfg.Flex.IP fc.Address = Cfg.Flex.IP

View File

@ -52,7 +52,7 @@ func main() {
cfg := NewConfig(cfgPath) cfg := NewConfig(cfgPath)
log := NewLog() log := NewLog()
log.Info("config loaded.") log.Info("Running FlexDXCluster version 0.1")
log.Infof("Callsign: %s", cfg.SQLite.Callsign) log.Infof("Callsign: %s", cfg.SQLite.Callsign)
DeleteDatabase("./flex.sqlite", log) DeleteDatabase("./flex.sqlite", log)

54
spot.go
View File

@ -144,6 +144,11 @@ func (spot *TelnetSpot) GetBand() {
if spot.Mode == "SSB" { if spot.Mode == "SSB" {
spot.Mode = "LSB" spot.Mode = "LSB"
} }
case strings.HasPrefix(spot.Frequency, "5."):
spot.Band = "60M"
if spot.Mode == "SSB" {
spot.Mode = "LSB"
}
case strings.HasPrefix(spot.Frequency, "7"): case strings.HasPrefix(spot.Frequency, "7"):
spot.Band = "40M" spot.Band = "40M"
if spot.Mode == "SSB" { if spot.Mode == "SSB" {
@ -181,6 +186,11 @@ func (spot *TelnetSpot) GetBand() {
if spot.Mode == "SSB" { if spot.Mode == "SSB" {
spot.Mode = "USB" spot.Mode = "USB"
} }
case strings.HasPrefix(spot.Frequency, "50"):
spot.Band = "6M"
if spot.Mode == "SSB" {
spot.Mode = "USB"
}
default: default:
spot.Band = "N/A" spot.Band = "N/A"
} }
@ -198,9 +208,35 @@ func (spot *TelnetSpot) GuessMode() {
if freqInt >= 1800 && freqInt <= 1840 { if freqInt >= 1800 && freqInt <= 1840 {
spot.Mode = "CW" spot.Mode = "CW"
} }
if freqInt >= 1840 && freqInt <= 1840 { if freqInt >= 1840 && freqInt <= 1844 {
spot.Mode = "FT8"
}
case "80M":
if freqInt >= 3500 && freqInt < 3568 {
spot.Mode = "CW" spot.Mode = "CW"
} }
if freqInt >= 3568 && freqInt < 3573 {
spot.Mode = "FT4"
}
if freqInt >= 3573 && freqInt < 3580 {
spot.Mode = "FT8"
}
if freqInt >= 3580 && freqInt < 3600 {
spot.Mode = "CW"
}
if freqInt >= 3600 && freqInt <= 3800 {
spot.Mode = "LSB"
}
case "60M":
if freqInt >= 5351.5 && freqInt < 5354 {
spot.Mode = "CW"
}
if freqInt >= 5354 && freqInt < 5366 {
spot.Mode = "LSB"
}
if freqInt >= 5366 && freqInt <= 5266.5 {
spot.Mode = "FT8"
}
case "40M": case "40M":
if freqInt >= 7000 && freqInt < 7045.5 { if freqInt >= 7000 && freqInt < 7045.5 {
spot.Mode = "CW" spot.Mode = "CW"
@ -311,6 +347,22 @@ func (spot *TelnetSpot) GuessMode() {
if freqInt >= 29000 && freqInt <= 29700 { if freqInt >= 29000 && freqInt <= 29700 {
spot.Mode = "FM" spot.Mode = "FM"
} }
case "6M":
if freqInt >= 50000 && freqInt < 50100 {
spot.Mode = "CW"
}
if freqInt >= 50100 && freqInt < 50313 {
spot.Mode = "USB"
}
if freqInt >= 50313 && freqInt < 50320 {
spot.Mode = "FT8"
}
if freqInt >= 50320 && freqInt < 50400 {
spot.Mode = "USB"
}
if freqInt >= 50400 && freqInt < +52000 {
spot.Mode = "FM"
}
} }
} }

View File

@ -103,7 +103,7 @@
<div class="font-bold text-gray-700 text-center text-4xl text-red-800" id="spotCount" hx-get="/spotscount" hx-trigger="every 1s" hx-swap="innerHTML"></div> <div class="font-bold text-gray-700 text-center text-4xl text-red-800" id="spotCount" hx-get="/spotscount" hx-trigger="every 1s" hx-swap="innerHTML"></div>
</div> </div>
<div class="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700 ml-4 mr-2" style="height: 17rem;"> <div class="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700 ml-4 mr-2" style="height: 34rem;">
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">Top Spotters</h5> <h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">Top Spotters</h5>
<div class="font-normal text-gray-700 dark:text-gray-400" id="spotters" hx-get="/spotters" hx-trigger="every 1s" hx-swap="innerHTML"></div> <div class="font-normal text-gray-700 dark:text-gray-400" id="spotters" hx-get="/spotters" hx-trigger="every 1s" hx-swap="innerHTML"></div>
</div> </div>

67
xml.go
View File

@ -5,6 +5,8 @@ import (
"io" "io"
"os" "os"
"regexp" "regexp"
"strings"
"unicode/utf8"
) )
type Countries struct { type Countries struct {
@ -43,15 +45,24 @@ type CountryPrefix struct {
EndDate string `xml:"EndDate"` EndDate string `xml:"EndDate"`
} }
type DXCC struct {
Callsign string
CountryName string
DXCC string
RegEx string
RegExSplit []string
RegExCharacters int
Ended bool
}
func LoadCountryFile() Countries { func LoadCountryFile() Countries {
// Open our xmlFile // Open our xmlFile
xmlFile, err := os.Open("country.xml") xmlFile, err := os.Open("country.xml")
// if we os.Open returns an error then handle it // if we os.Open returns an error then handle it
if err != nil { if err != nil {
Log.Errorln(err) os.Exit(1)
} }
Log.Debugln("Successfully loaded country.xml")
// defer the closing of our xmlFile so that we can parse it later on // defer the closing of our xmlFile so that we can parse it later on
defer xmlFile.Close() defer xmlFile.Close()
@ -65,14 +76,58 @@ func LoadCountryFile() Countries {
} }
func GetDXCC(dxCall string, Countries Countries) string { func GetDXCC(dxCall string, Countries Countries) string {
DXCCList := []DXCC{}
d := DXCC{}
// Get all the matching DXCC for current callsign
for i := 0; i < len(Countries.Countries); i++ { for i := 0; i < len(Countries.Countries); i++ {
// for j := 0; j < len(Countries.Countries[i].CountryPrefixList.CountryPrefixList); j++ {
regExp := regexp.MustCompile(Countries.Countries[i].CountryPrefixList.CountryPrefixList[len(Countries.Countries[i].CountryPrefixList.CountryPrefixList)-1].PrefixList) regExp := regexp.MustCompile(Countries.Countries[i].CountryPrefixList.CountryPrefixList[len(Countries.Countries[i].CountryPrefixList.CountryPrefixList)-1].PrefixList)
match := regExp.FindStringSubmatch(dxCall) match := regExp.FindStringSubmatch(dxCall)
if len(match) != 0 { if len(match) != 0 {
return Countries.Countries[i].Dxcc
d = DXCC{
Callsign: dxCall,
CountryName: Countries.Countries[i].CountryName,
DXCC: Countries.Countries[i].Dxcc,
RegEx: Countries.Countries[i].CountryPrefixList.CountryPrefixList[len(Countries.Countries[i].CountryPrefixList.CountryPrefixList)-1].PrefixList,
} }
// }
if Countries.Countries[i].CountryPrefixList.CountryPrefixList[len(Countries.Countries[i].CountryPrefixList.CountryPrefixList)-1].EndDate == "" {
d.Ended = false
} else {
d.Ended = true
} }
return ""
DXCCList = append(DXCCList, d)
}
}
for i := 0; i < len(DXCCList); i++ {
DXCCList[i].RegExSplit = strings.Split(DXCCList[i].RegEx, "|")
for j := 0; j < len(DXCCList[i].RegExSplit); j++ {
regExp := regexp.MustCompile(DXCCList[i].RegExSplit[j])
matched := regExp.FindStringSubmatch(dxCall)
if len(matched) > 0 {
DXCCList[i].RegExCharacters = utf8.RuneCountInString(DXCCList[i].RegExSplit[j])
}
}
}
DXCCMatch := DXCCList[0]
higherMatch := DXCCList[0].RegExCharacters
if len(DXCCList) > 1 {
for i := 0; i < len(DXCCList); i++ {
if DXCCList[i].RegExCharacters > higherMatch && !DXCCList[i].Ended {
DXCCMatch = DXCCList[i]
higherMatch = DXCCList[i].RegExCharacters
}
}
} else {
DXCCMatch = DXCCList[0]
}
return DXCCMatch.DXCC
} }