Skip to content

Commit

Permalink
fix the multis calculation in the band summary
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed Jul 27, 2023
1 parent d3e7baa commit 0f2c65e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 23 deletions.
16 changes: 9 additions & 7 deletions core/bandmap/bandmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"
"time"

"github.com/ftl/conval"
"github.com/ftl/hamradio/callsign"
"golang.org/x/exp/slices"

Expand Down Expand Up @@ -33,7 +34,7 @@ type DupeChecker interface {

type Callinfo interface {
GetInfo(callsign.Callsign, core.Band, core.Mode, []string) core.Callinfo
GetValue(callsign.Callsign, core.Band, core.Mode, []string) (int, int)
GetValue(callsign.Callsign, core.Band, core.Mode, []string) (int, int, map[conval.Property]string)
}

type Bandmap struct {
Expand Down Expand Up @@ -610,7 +611,7 @@ func (l *Entries) CleanOut(maximumAge time.Duration, now time.Time) {
for i, e := range l.entries {
e.Index = i
oldPoints, oldMultis := e.Info.Points, e.Info.Multis
e.Info.Points, e.Info.Multis = l.callinfo.GetValue(e.Call, e.Band, e.Mode, []string{})
e.Info.Points, e.Info.Multis, e.Info.MultiValues = l.callinfo.GetValue(e.Call, e.Band, e.Mode, []string{})
updated := e.updated || (oldPoints != e.Info.Points) || (oldMultis != e.Info.Multis)
e.updated = false
l.entries[i] = e
Expand All @@ -630,7 +631,7 @@ func (l *Entries) addToSummary(entry *Entry) {
summary = core.BandSummary{Band: entry.Band}
}
summary.Points += entry.Info.Points
summary.Multis += entry.Info.Multis
summary.AddMultiValues(entry.Info.MultiValues)
l.summaries[entry.Band] = summary
}

Expand All @@ -654,8 +655,9 @@ func (l *Entries) Bands(active, visible core.Band) []core.BandSummary {
maxPoints = summary.Points
maxPointsIndex = i
}
if summary.Multis > maxMultis {
maxMultis = summary.Multis
multis := summary.Multis()
if multis > maxMultis {
maxMultis = multis
maxMultisIndex = i
}
}
Expand Down Expand Up @@ -759,6 +761,6 @@ type nullCallinfo struct{}
func (n *nullCallinfo) GetInfo(callsign.Callsign, core.Band, core.Mode, []string) core.Callinfo {
return core.Callinfo{}
}
func (n *nullCallinfo) GetValue(callsign.Callsign, core.Band, core.Mode, []string) (int, int) {
return 0, 0
func (n *nullCallinfo) GetValue(callsign.Callsign, core.Band, core.Mode, []string) (int, int, map[conval.Property]string) {
return 0, 0, nil
}
10 changes: 5 additions & 5 deletions core/callinfo/callinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type DupeChecker interface {

// Valuer provides the points and multis of a QSO based on the given information.
type Valuer interface {
Value(callsign callsign.Callsign, entity dxcc.Prefix, band core.Band, mode core.Mode, exchange []string) (points, multis int)
Value(callsign callsign.Callsign, entity dxcc.Prefix, band core.Band, mode core.Mode, exchange []string) (points, multis int, multiValues map[conval.Property]string)
}

// ExchangeFilter clears the exchange values that cannot be predicted (RST, serial).
Expand Down Expand Up @@ -153,7 +153,7 @@ func (c *Callinfo) GetInfo(call callsign.Callsign, band core.Band, mode core.Mod
filteredExchange := c.exchangeFilter.FilterExchange(result.PredictedExchange)
result.ExchangeText = strings.Join(filteredExchange, " ")

result.Points, result.Multis = c.valuer.Value(call, entity, band, mode, exchange)
result.Points, result.Multis, result.MultiValues = c.valuer.Value(call, entity, band, mode, exchange)

return result
}
Expand Down Expand Up @@ -193,10 +193,10 @@ func joinAvailableValues(values ...string) string {
return strings.Join(availableValues, ", ")
}

func (c *Callinfo) GetValue(call callsign.Callsign, band core.Band, mode core.Mode, exchange []string) (points, multis int) {
func (c *Callinfo) GetValue(call callsign.Callsign, band core.Band, mode core.Mode, exchange []string) (points, multis int, multiValues map[conval.Property]string) {
entity, found := c.findDXCCEntity(call.String())
if !found {
return 0, 0
return 0, 0, nil
}
return c.valuer.Value(call, entity, band, mode, exchange)
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (c *Callinfo) showSupercheck(s string) {

var points, multis int
if entityFound {
points, multis = c.valuer.Value(annotatedCallsign.Callsign, entity, c.lastBand, c.lastMode, predictedExchange)
points, multis, _ = c.valuer.Value(annotatedCallsign.Callsign, entity, c.lastBand, c.lastMode, predictedExchange)
}

annotatedCallsign.Duplicate = duplicate
Expand Down
37 changes: 30 additions & 7 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,16 +805,38 @@ type BandmapFrame struct {
}

type BandSummary struct {
Band Band
Points int
Multis int
Band Band
Points int
MultiValues map[conval.Property]map[string]bool

MaxPoints bool
MaxMultis bool
Active bool
Visible bool
}

func (s *BandSummary) AddMultiValues(values map[conval.Property]string) {
if s.MultiValues == nil {
s.MultiValues = make(map[conval.Property]map[string]bool)
}
for property, value := range values {
propertyValues, ok := s.MultiValues[property]
if !ok {
propertyValues = make(map[string]bool)
}
propertyValues[value] = true
s.MultiValues[property] = propertyValues
}
}

func (s *BandSummary) Multis() int {
result := 0
for _, values := range s.MultiValues {
result += len(values)
}
return result
}

type BandmapEntry struct {
Index int
Label string
Expand All @@ -840,10 +862,11 @@ type Callinfo struct {
PredictedExchange []string
ExchangeText string

Worked bool // already worked on another band/mode, but does not count as duplicate
Duplicate bool // counts as duplicate
Points int
Multis int
Worked bool // already worked on another band/mode, but does not count as duplicate
Duplicate bool // counts as duplicate
Points int
Multis int
MultiValues map[conval.Property]string
}

// frequencies within this distance to an entry's frequency will be recognized as "in proximity"
Expand Down
4 changes: 2 additions & 2 deletions core/score/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (c *Counter) emitScoreUpdated(score core.Score) {
}
}

func (c *Counter) Value(callsign callsign.Callsign, entity dxcc.Prefix, band core.Band, mode core.Mode, exchange []string) (points, multis int) {
func (c *Counter) Value(callsign callsign.Callsign, entity dxcc.Prefix, band core.Band, mode core.Mode, exchange []string) (points, multis int, multiValues map[conval.Property]string) {
continent, country, _, _ := toConvalDXCCEntity(entity)
convalQSO := conval.QSO{
TheirCall: callsign,
Expand All @@ -227,7 +227,7 @@ func (c *Counter) Value(callsign callsign.Callsign, entity dxcc.Prefix, band cor
}
qsoScore := c.counter.Probe(convalQSO)

return qsoScore.Points, qsoScore.Multis
return qsoScore.Points, qsoScore.Multis, qsoScore.MultiValues
}

func (c *Counter) toConvalQSO(qso core.QSO) conval.QSO {
Expand Down
4 changes: 3 additions & 1 deletion core/score/score_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ func TestConvalCounter(t *testing.T) {
entity, ok := myTestEntity.Find("dl1aaa")
require.True(t, ok)

points, multis := counter.Value(callsign.MustParse("dl1aaa"), entity, core.Band80m, core.ModeCW, []string{})
points, multis, multiValues := counter.Value(callsign.MustParse("dl1aaa"), entity, core.Band80m, core.ModeCW, []string{})

assert.Equal(t, 1, points, "points")
assert.Equal(t, 1, multis, "multis")
assert.Equal(t, 1, len(multiValues), "multiValues len")
assert.Equal(t, "DL1", multiValues[conval.WPXPrefixProperty], "multiValues value")
}

func TestAdd(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ui/spotsView.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (v *spotsView) updateBand(button *gtk.Button, band core.BandSummary) {

child, _ = grid.GetChildAt(1, 1)
multis := child.(*gtk.Label)
multis.SetText(fmt.Sprintf("%dM", band.Multis))
multis.SetText(fmt.Sprintf("%dM", band.Multis()))

if band.MaxPoints {
style.AddClass(&points.Widget, maxValueClass)
Expand Down

0 comments on commit 0f2c65e

Please sign in to comment.