Use BM repeaters to filter for real repeaters
This commit is contained in:
parent
71be66c5b4
commit
9a08f34e72
4 changed files with 39 additions and 2 deletions
|
|
@ -10,5 +10,6 @@ WORKDIR /app
|
|||
COPY --from=builder /build/dmrmap .
|
||||
COPY static/ ./static/
|
||||
COPY rptrs.json .
|
||||
COPY bmrptrs.json .
|
||||
EXPOSE 8080
|
||||
CMD ["./dmrmap"]
|
||||
|
|
|
|||
2
bmrptrs.json
Normal file
2
bmrptrs.json
Normal file
File diff suppressed because one or more lines are too long
3
main.go
3
main.go
|
|
@ -9,13 +9,14 @@ import (
|
|||
func main() {
|
||||
dbPath := envOr("DB_PATH", "data/repeaters.db")
|
||||
jsonPath := envOr("JSON_PATH", "rptrs.json")
|
||||
bmrptrsPath := envOr("BMRPTRS_PATH", "bmrptrs.json")
|
||||
addr := envOr("LISTEN_ADDR", ":8080")
|
||||
|
||||
if err := os.MkdirAll("data", 0755); err != nil {
|
||||
log.Fatalf("Failed to create data directory: %v", err)
|
||||
}
|
||||
|
||||
if err := seedDatabase(dbPath, jsonPath); err != nil {
|
||||
if err := seedDatabase(dbPath, jsonPath, bmrptrsPath); err != nil {
|
||||
log.Fatalf("Failed to seed database: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
35
seed.go
35
seed.go
|
|
@ -32,7 +32,35 @@ type rawData struct {
|
|||
Rptrs []rawRepeater `json:"rptrs"`
|
||||
}
|
||||
|
||||
func seedDatabase(dbPath, jsonPath string) error {
|
||||
type bmRepeater struct {
|
||||
ID int `json:"ID"`
|
||||
Call string `json:"Call"`
|
||||
Owner string `json:"Owner"`
|
||||
}
|
||||
|
||||
func loadBMRepeaters(path string) map[string]bool {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Printf("Warning: could not open BM repeaters file %s: %v", path, err)
|
||||
return map[string]bool{}
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var rptrs []bmRepeater
|
||||
if err := json.NewDecoder(f).Decode(&rptrs); err != nil {
|
||||
log.Printf("Warning: could not decode BM repeaters file %s: %v", path, err)
|
||||
return map[string]bool{}
|
||||
}
|
||||
|
||||
set := make(map[string]bool, len(rptrs))
|
||||
for _, r := range rptrs {
|
||||
set[strings.ToUpper(strings.TrimSpace(r.Call))] = true
|
||||
}
|
||||
log.Printf("Loaded %d BM repeater callsigns from %s", len(set), path)
|
||||
return set
|
||||
}
|
||||
|
||||
func seedDatabase(dbPath, jsonPath, bmrptrsPath string) error {
|
||||
db, err := openDB(dbPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open db: %w", err)
|
||||
|
|
@ -63,6 +91,8 @@ func seedDatabase(dbPath, jsonPath string) error {
|
|||
return fmt.Errorf("decode json: %w", err)
|
||||
}
|
||||
|
||||
bmSet := loadBMRepeaters(bmrptrsPath)
|
||||
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
return fmt.Errorf("begin tx: %w", err)
|
||||
|
|
@ -97,6 +127,9 @@ func seedDatabase(dbPath, jsonPath string) error {
|
|||
if isHotspot(r.Offset, r.City, r.MapInfo, r.Callsign, r.Country, r.Trustee) {
|
||||
hotspot = 1
|
||||
hotspots++
|
||||
} else if network == "Brandmeister" && len(bmSet) > 0 && !bmSet[strings.ToUpper(strings.TrimSpace(r.Callsign))] {
|
||||
hotspot = 1
|
||||
hotspots++
|
||||
}
|
||||
if _, err := stmt.Exec(r.ID, r.Callsign, freq, band, lat, lng,
|
||||
r.City, r.State, r.Country, r.ColorCode, r.Offset,
|
||||
|
|
|
|||
Loading…
Reference in a new issue