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.

126 lines
2.7 KiB

4 years ago
package main
import (
4 years ago
"fmt"
"github.com/jnovack/flag"
log "github.com/sirupsen/logrus"
4 years ago
// "strings"
// "strconv"
// "time"
4 years ago
"os"
"bufio"
"runtime"
4 years ago
// "github.com/mmcloughlin/geohash"
// "github.com/tzneal/ham-go/dxcc"
4 years ago
"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")
}
}
4 years ago
func eatline(lines chan string, results chan wsjtx.Result) {
for {
select {
case line := <- lines :
result, parsed := wsjtx.ScanLine(line)
if parsed {
results <- result
}
}
}
return
}
func eatfile(results chan wsjtx.Result) {
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++ {
go eatline(lines, results)
}
i := 0
for scanner.Scan() {
i++
if i % 1000000 == 0 {
log.Infof("%d lines parsed..", i)
}
lines <- scanner.Text()
}
filein.Close()
log.Info("done.. eatfile")
return
}
4 years ago
func main(){
_ , err := os.Stat(pathout)
if !os.IsNotExist(err) {
log.Fatalf("file %s already exists..", pathout)
}
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)
results := make(chan wsjtx.Result,runtime.NumCPU())
4 years ago
4 years ago
go eatfile(results)
4 years ago
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)
}
4 years ago
}
}
writer.Flush()
fileout.Close()
4 years ago
log.Info("done.. main")
4 years ago
}