You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

152 lines
3.3 KiB

4 years ago
package main
import (
4 years ago
"fmt"
"github.com/jnovack/flag"
log "github.com/sirupsen/logrus"
// "strings"
// "strconv"
// "time"
4 years ago
"os"
"bufio"
"runtime"
"sync"
// "github.com/mmcloughlin/geohash"
// "github.com/tzneal/ham-go/dxcc"
"github.com/denzs/wsjtx-dashboards/shared/wsjtx"
4 years ago
)
var station string
var pathin string
var pathout string
var trace bool
func usage() {
fmt.Printf("Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
func init() {
flag.StringVar(&pathin, "in", "", "path to wsjt-x ALL.txt")
flag.StringVar(&pathout, "out", "", "path to csv outfile")
flag.StringVar(&station, "station", "localstation", "your callsign or wsjtx instance identifier")
flag.BoolVar(&trace, "trace", false, "log every line... yes really ;)")
flag.Parse()
if pathin == "" || pathout == "" {
usage()
os.Exit(1)
}
formatter := &log.TextFormatter{
FullTimestamp: true,
}
log.SetFormatter(formatter)
if trace {
log.SetLevel(log.TraceLevel)
log.Info("trace logging enabled")
} else {
log.Info("normal logging enabled")
}
_ , err := os.Stat(pathout)
if !os.IsNotExist(err) {
log.Fatalf("file %s already exists..", pathout)
}
4 years ago
}
func eatline(id int, lines chan string, results chan wsjtx.Result, wg *sync.WaitGroup) {
defer wg.Done()
log.Infof("worker %d.. starting..", id)
loop:
4 years ago
for {
select {
case line, more := <- lines :
if more {
result, parsed := wsjtx.ScanLine(line)
if parsed {
results <- result
}
} else {
log.Infof("eatline worker[%d]: resultchan seems down.. going home..", id)
break loop
4 years ago
}
}
}
log.Infof("worker %d.. done!", id)
4 years ago
return
}
func eatfile(results chan wsjtx.Result, done chan bool) {
var wg sync.WaitGroup
4 years ago
log.Info("starting eating file, please wait..")
filein, err := os.Open(pathin)
if err != nil {
log.Fatal(err)
}
scanner := bufio.NewScanner(filein)
lines := make(chan string,runtime.NumCPU())
for w := 0; w <= runtime.NumCPU(); w++ {
wg.Add(1)
go eatline(w, lines, results, &wg)
4 years ago
}
i := 0
for scanner.Scan() {
i++
if i % 1000000 == 0 {
log.Infof("%d lines read..", i)
4 years ago
}
log.Info("line: ", scanner.Text())
4 years ago
lines <- scanner.Text()
}
log.Info("sending children to bed..")
close(lines)
wg.Wait()
log.Info("children are in bed now! ;)")
4 years ago
filein.Close()
done <- true
4 years ago
log.Info("done.. eatfile")
return
}
4 years ago
func main(){
fileout, err := os.OpenFile(pathout,os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
log.Fatal(err)
}
4 years ago
writer := bufio.NewWriter(fileout)
4 years ago
results := make(chan wsjtx.Result,runtime.NumCPU())
done := make(chan bool)
4 years ago
go eatfile(results, done)
4 years ago
loop:
4 years ago
for {
select {
case result := <- results :
_, err := writer.WriteString(fmt.Sprintf("\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%d\",\n", result.Timestamp.Format("2006-01-02 15:04:05"), station, result.Call, result.Band, result.Ent.Continent, result.Mode, result.Ent.Entity, result.GeoHash, result.Signal, result.Rx))
if err != nil {
log.Warn(err)
}
case <- done :
break loop
4 years ago
}
}
writer.Flush()
fileout.Close()
4 years ago
log.Info("done.. main")
4 years ago
}