Skip to content

Commit 078c62f

Browse files
committed
mark all relevant entries as worked
1 parent 41a4cf5 commit 078c62f

File tree

3 files changed

+103
-10
lines changed

3 files changed

+103
-10
lines changed

core/bandmap/entries.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ func (e *Entry) update() {
128128
if lastHeard.Before(s.Time) {
129129
lastHeard = s.Time
130130
}
131-
if e.Source != core.WorkedSpot && source.Priority() > s.Source.Priority() {
131+
if source.Priority() > s.Source.Priority() {
132132
source = s.Source
133133
}
134134
}
135135

136136
e.updated = frequencyUpdated || (lastHeard != e.LastHeard) || (source != e.Source)
137137
e.LastHeard = lastHeard
138-
e.Source = source
138+
if e.Source != core.WorkedSpot {
139+
e.Source = source
140+
}
139141
e.SpotCount = len(e.spots)
140142
if e.SpotCount < spotValidThreshold && e.Quality == core.ValidSpotQuality {
141143
e.Quality = core.UnknownSpotQuality
@@ -283,9 +285,26 @@ func (l *Entries) findIndexForInsert(entry *Entry) int {
283285
}
284286

285287
func (l *Entries) MarkAsWorked(call callsign.Callsign, band core.Band, mode core.Mode) {
286-
// TODO: implement
287-
// find relevant entries
288-
// set entry.Source = core.WorkedSpot
288+
for _, e := range l.entries {
289+
match := true
290+
if call != e.Call {
291+
match = false
292+
}
293+
if band != core.NoBand && band != e.Band {
294+
match = false
295+
}
296+
if mode != core.NoMode && mode != e.Mode {
297+
match = false
298+
}
299+
300+
if !match {
301+
continue
302+
}
303+
304+
e.Source = core.WorkedSpot
305+
e.update()
306+
l.notifier.emitEntryUpdated(e.BandmapEntry)
307+
}
289308
}
290309

291310
func (l *Entries) CleanOut(maximumAge time.Duration, now time.Time, weights core.BandmapWeights) {

core/bandmap/entries_test.go

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,14 @@ func TestEntries_CleanOutOldEntries(t *testing.T) {
394394
entries.Add(core.Spot{Call: callsign.MustParse("dl1abc"), Frequency: 3535000, Time: now.Add(-30 * time.Minute)}, now, defaultWeights)
395395
entries.Add(core.Spot{Call: callsign.MustParse("dl1abc"), Frequency: 3535000, Time: now.Add(-10 * time.Minute)}, now, defaultWeights)
396396
entries.Add(core.Spot{Call: callsign.MustParse("dl2abc"), Frequency: 3535500, Time: now.Add(-10 * time.Hour)}, now, defaultWeights)
397+
entries.Add(core.Spot{Source: core.WorkedSpot, Call: callsign.MustParse("dl3abc"), Frequency: 3535500, Time: now.Add(-50 * time.Hour)}, now, defaultWeights)
397398

398-
assert.Equal(t, 2, entries.Len())
399-
assert.Equal(t, "DL2ABC", entries.entries[0].Call.String())
400-
assert.Equal(t, "DL1ABC", entries.entries[1].Call.String())
401-
assert.Equal(t, 3, entries.entries[1].Len())
402-
assert.Equal(t, now.Add(-10*time.Minute), entries.entries[1].LastHeard)
399+
assert.Equal(t, 3, entries.Len())
400+
assert.Equal(t, "DL3ABC", entries.entries[0].Call.String())
401+
assert.Equal(t, "DL2ABC", entries.entries[1].Call.String())
402+
assert.Equal(t, "DL1ABC", entries.entries[2].Call.String())
403+
assert.Equal(t, 3, entries.entries[2].Len())
404+
assert.Equal(t, now.Add(-10*time.Minute), entries.entries[2].LastHeard)
403405

404406
entries.CleanOut(30*time.Minute, now, defaultWeights)
405407

@@ -512,6 +514,76 @@ func TestFilterSlice(t *testing.T) {
512514
assert.Equal(t, []int{1, 5, 2, 3, 4}, output)
513515
}
514516

517+
func TestEntries_MarkAsWorked(t *testing.T) {
518+
tt := []struct {
519+
band core.Band
520+
mode core.Mode
521+
expected []core.SpotType
522+
}{
523+
{
524+
band: core.NoBand,
525+
mode: core.NoMode,
526+
expected: []core.SpotType{
527+
core.WorkedSpot,
528+
core.WorkedSpot,
529+
core.WorkedSpot,
530+
core.UnknownSpot,
531+
core.WorkedSpot,
532+
},
533+
},
534+
{
535+
band: core.Band20m,
536+
mode: core.NoMode,
537+
expected: []core.SpotType{
538+
core.WorkedSpot,
539+
core.WorkedSpot,
540+
core.UnknownSpot,
541+
core.UnknownSpot,
542+
core.UnknownSpot,
543+
},
544+
},
545+
{
546+
band: core.Band20m,
547+
mode: core.ModeCW,
548+
expected: []core.SpotType{
549+
core.UnknownSpot,
550+
core.WorkedSpot,
551+
core.UnknownSpot,
552+
core.UnknownSpot,
553+
core.UnknownSpot,
554+
},
555+
},
556+
}
557+
558+
for _, tc := range tt {
559+
t.Run(string(tc.band)+" "+string(tc.mode), func(t *testing.T) {
560+
now := time.Now()
561+
entries := NewEntries(&Notifier{}, countAllEntries)
562+
563+
// the entries will be sorted by band and time
564+
entries.Add(core.Spot{Call: callsign.MustParse("dl1abc"), Band: core.Band20m, Frequency: 14114000, Mode: core.ModeSSB, Time: now.Add(-11 * time.Minute)}, now, defaultWeights)
565+
entries.Add(core.Spot{Call: callsign.MustParse("dl1abc"), Band: core.Band20m, Frequency: 14014000, Mode: core.ModeCW, Time: now.Add(-10 * time.Minute)}, now, defaultWeights)
566+
entries.Add(core.Spot{Call: callsign.MustParse("dl1abc"), Band: core.Band40m, Frequency: 7073000, Time: now.Add(-30 * time.Minute)}, now, defaultWeights)
567+
entries.Add(core.Spot{Call: callsign.MustParse("dl2abc"), Band: core.Band80m, Frequency: 3535500, Time: now.Add(-12 * time.Hour)}, now, defaultWeights)
568+
entries.Add(core.Spot{Call: callsign.MustParse("dl1abc"), Band: core.Band80m, Frequency: 3535000, Time: now.Add(-1 * time.Hour)}, now, defaultWeights)
569+
570+
entries.MarkAsWorked(callsign.MustParse("dl1abc"), tc.band, tc.mode)
571+
572+
for i, spotType := range tc.expected {
573+
assert.Equal(t, spotType, entries.entries[i].Source, "entry #%d", i)
574+
}
575+
576+
for _, e := range entries.entries {
577+
e.update()
578+
}
579+
580+
for i, spotType := range tc.expected {
581+
assert.Equal(t, spotType, entries.entries[i].Source, "entry #%d", i)
582+
}
583+
})
584+
}
585+
}
586+
515587
type testEntryListener struct {
516588
added []core.BandmapEntry
517589
updated []core.BandmapEntry

core/core.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ const (
801801
SkimmerSpot SpotType = "skimmer"
802802
RBNSpot SpotType = "rbn"
803803
ClusterSpot SpotType = "cluster"
804+
UnknownSpot SpotType = ""
804805

805806
maxSpotTypePriority = 10
806807
)
@@ -811,6 +812,7 @@ var spotTypePriorities = map[SpotType]int{
811812
SkimmerSpot: 2,
812813
RBNSpot: 3,
813814
ClusterSpot: 4,
815+
UnknownSpot: maxSpotTypePriority,
814816
}
815817

816818
func (t SpotType) Priority() int {

0 commit comments

Comments
 (0)