Skip to content

Commit f071df0

Browse files
fix: Filtered SSIDs persist in time graph legend (#610)
* test: add failing tests for filtered SSIDs persisting in time graph * fix: exclude filtered-out SSIDs from time graph cache and new series The DataManager now uses the Predicate to determine which difference-series entries and active cache entries are legitimate (temporarily out of range) vs filtered out. This prevents filtered SSIDs from persisting in the time graph legend after a filter is applied. --------- Co-authored-by: VREM Software Development <vremsoftwaredevelopment@gmail.com>
1 parent dcdd006 commit f071df0

4 files changed

Lines changed: 70 additions & 19 deletions

File tree

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/timegraph/DataManager.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.vrem.wifianalyzer.wifi.graphutils.MAX_SCAN_COUNT
2525
import com.vrem.wifianalyzer.wifi.graphutils.MIN_Y
2626
import com.vrem.wifianalyzer.wifi.graphutils.MIN_Y_OFFSET
2727
import com.vrem.wifianalyzer.wifi.model.WiFiDetail
28+
import com.vrem.wifianalyzer.wifi.predicate.Predicate
2829

2930
@OpenClass
3031
internal class DataManager(
@@ -37,34 +38,42 @@ internal class DataManager(
3738
graphViewWrapper: GraphViewWrapper,
3839
wiFiDetails: List<WiFiDetail>,
3940
levelMax: Int,
41+
predicate: Predicate,
4042
): Set<WiFiDetail> {
4143
val inOrder: Set<WiFiDetail> = wiFiDetails.toSet()
4244
inOrder.forEach { addData(graphViewWrapper, it, levelMax) }
43-
adjustData(graphViewWrapper, inOrder)
45+
adjustData(graphViewWrapper, inOrder, predicate)
4446
xValue++
4547
if (scanCount < MAX_SCAN_COUNT) {
4648
scanCount++
4749
}
4850
if (scanCount == 2) {
4951
graphViewWrapper.setHorizontalLabelsVisible(true)
5052
}
51-
return newSeries(inOrder)
53+
return newSeries(inOrder, predicate)
5254
}
5355

5456
fun adjustData(
5557
graphViewWrapper: GraphViewWrapper,
5658
wiFiDetails: Set<WiFiDetail>,
59+
predicate: Predicate,
5760
) {
58-
graphViewWrapper.differenceSeries(wiFiDetails).forEach {
59-
val dataPoint = GraphDataPoint(xValue, MIN_Y + MIN_Y_OFFSET)
60-
val drawBackground = it.wiFiAdditional.wiFiConnection.connected
61-
graphViewWrapper.appendToSeries(it, dataPoint, scanCount, drawBackground)
62-
timeGraphCache.add(it)
63-
}
61+
graphViewWrapper
62+
.differenceSeries(wiFiDetails)
63+
.filter { predicate(it) }
64+
.forEach {
65+
val dataPoint = GraphDataPoint(xValue, MIN_Y + MIN_Y_OFFSET)
66+
val drawBackground = it.wiFiAdditional.wiFiConnection.connected
67+
graphViewWrapper.appendToSeries(it, dataPoint, scanCount, drawBackground)
68+
timeGraphCache.add(it)
69+
}
6470
timeGraphCache.clear()
6571
}
6672

67-
fun newSeries(wiFiDetails: Set<WiFiDetail>): Set<WiFiDetail> = wiFiDetails.plus(timeGraphCache.active())
73+
fun newSeries(
74+
wiFiDetails: Set<WiFiDetail>,
75+
predicate: Predicate,
76+
): Set<WiFiDetail> = wiFiDetails.plus(timeGraphCache.active().filter { predicate(it) })
6877

6978
fun addData(
7079
graphViewWrapper: GraphViewWrapper,

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/timegraph/TimeGraphView.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ internal class TimeGraphView(
7070
graphViewWrapper,
7171
wiFiDetails,
7272
MainContext.INSTANCE.settings.graphMaximumY(),
73+
predicate,
7374
)
7475
graphViewWrapper.removeSeries(newSeries)
7576
graphViewWrapper.updateLegend(MainContext.INSTANCE.settings.timeGraphLegend())

app/src/test/kotlin/com/vrem/wifianalyzer/wifi/timegraph/DataManagerTest.kt

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import com.vrem.wifianalyzer.wifi.model.WiFiIdentifier
3333
import com.vrem.wifianalyzer.wifi.model.WiFiSecurity
3434
import com.vrem.wifianalyzer.wifi.model.WiFiSignal
3535
import com.vrem.wifianalyzer.wifi.model.WiFiWidth
36+
import com.vrem.wifianalyzer.wifi.predicate.falsePredicate
37+
import com.vrem.wifianalyzer.wifi.predicate.truePredicate
3638
import org.assertj.core.api.Assertions.assertThat
3739
import org.junit.Test
3840
import org.junit.runner.RunWith
@@ -59,7 +61,7 @@ class DataManagerTest {
5961
// setup
6062
assertThat(fixture.xValue).isEqualTo(0)
6163
// execute
62-
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
64+
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
6365
// validate
6466
assertThat(fixture.xValue).isEqualTo(1)
6567
}
@@ -69,7 +71,7 @@ class DataManagerTest {
6971
// setup
7072
assertThat(fixture.scanCount).isEqualTo(0)
7173
// execute
72-
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
74+
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
7375
// validate
7476
assertThat(fixture.scanCount).isEqualTo(1)
7577
}
@@ -80,7 +82,7 @@ class DataManagerTest {
8082
val wiFiDetails = makeWiFiDetails()
8183
val wiFiDetailsSet = wiFiDetails.toSet()
8284
// execute
83-
fixture.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y)
85+
fixture.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y, truePredicate)
8486
// validate
8587
wiFiDetailsSet.forEach {
8688
verify(graphViewWrapper).newSeries(it)
@@ -93,7 +95,7 @@ class DataManagerTest {
9395
// setup
9496
fixture.scanCount = MAX_SCAN_COUNT
9597
// execute
96-
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
98+
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
9799
// validate
98100
assertThat(fixture.scanCount).isEqualTo(MAX_SCAN_COUNT)
99101
}
@@ -103,7 +105,7 @@ class DataManagerTest {
103105
// setup
104106
fixture.scanCount = 1
105107
// execute
106-
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
108+
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
107109
// validate
108110
assertThat(fixture.scanCount).isEqualTo(2)
109111
verify(graphViewWrapper).setHorizontalLabelsVisible(true)
@@ -112,7 +114,7 @@ class DataManagerTest {
112114
@Test
113115
fun addSeriesDoesNotSetHorizontalLabelsVisible() {
114116
// execute
115-
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y)
117+
fixture.addSeriesData(graphViewWrapper, listOf(), MAX_Y, truePredicate)
116118
// validate
117119
verify(graphViewWrapper, never()).setHorizontalLabelsVisible(true)
118120
}
@@ -127,7 +129,7 @@ class DataManagerTest {
127129
val dataPoint = GraphDataPoint(xValue, MIN_Y + MIN_Y_OFFSET)
128130
whenever(graphViewWrapper.differenceSeries(wiFiDetails)).thenReturn(difference)
129131
// execute
130-
fixture.adjustData(graphViewWrapper, wiFiDetails)
132+
fixture.adjustData(graphViewWrapper, wiFiDetails, truePredicate)
131133
// validate
132134
difference.forEach {
133135
verify(graphViewWrapper).appendToSeries(
@@ -148,13 +150,52 @@ class DataManagerTest {
148150
val moreWiFiDetails: Set<WiFiDetail> = makeMoreWiFiDetails().toSet()
149151
whenever(timeGraphCache.active()).thenReturn(moreWiFiDetails)
150152
// execute
151-
val actual = fixture.newSeries(wiFiDetails)
153+
val actual = fixture.newSeries(wiFiDetails, truePredicate)
152154
// validate
153155
assertThat(actual).containsAll(wiFiDetails)
154156
assertThat(actual).containsAll(moreWiFiDetails)
155157
verify(timeGraphCache).active()
156158
}
157159

160+
@Test
161+
fun newSeriesShouldNotIncludeActiveCacheEntriesNotInCurrentWiFiDetails() {
162+
// Expected: newSeries includes currentDetails and only those active cache
163+
// entries that satisfy the given predicate. Entries from timeGraphCache.active()
164+
// that do not match the predicate (e.g. filtered-out SSIDs) must be excluded.
165+
// setup
166+
val currentDetails: Set<WiFiDetail> = makeWiFiDetails().toSet()
167+
val staleEntries: Set<WiFiDetail> = makeMoreWiFiDetails().toSet()
168+
whenever(timeGraphCache.active()).thenReturn(staleEntries)
169+
// execute
170+
val actual = fixture.newSeries(currentDetails, falsePredicate)
171+
assertThat(actual).containsAll(currentDetails)
172+
assertThat(actual).doesNotContainAnyElementsOf(staleEntries)
173+
verify(timeGraphCache).active()
174+
}
175+
176+
@Test
177+
fun adjustDataShouldNotAppendToStaleCacheEntriesNotInCurrentDetails() {
178+
// Expected: adjustData only appends floor data points and increments the
179+
// TimeGraphCache counter for differenceSeries entries that satisfy the
180+
// given predicate. Entries that do not match must be left untouched.
181+
// setup
182+
val currentDetails: Set<WiFiDetail> = makeWiFiDetails().toSet()
183+
val staleEntry: WiFiDetail = makeWiFiDetail("SSID4")
184+
whenever(graphViewWrapper.differenceSeries(currentDetails))
185+
.thenReturn(listOf(staleEntry))
186+
// execute
187+
fixture.adjustData(graphViewWrapper, currentDetails, falsePredicate)
188+
verify(graphViewWrapper, never()).appendToSeries(
189+
eq(staleEntry),
190+
any(),
191+
any(),
192+
any(),
193+
)
194+
// validate: stale entries must NOT be added to the time graph cache
195+
verify(timeGraphCache, never()).add(staleEntry)
196+
verify(timeGraphCache).clear()
197+
}
198+
158199
@Test
159200
fun addDataToExistingSeries() {
160201
// setup

app/src/test/kotlin/com/vrem/wifianalyzer/wifi/timegraph/TimeGraphViewTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class TimeGraphViewTest {
7070
val wiFiData = WiFiData(wiFiDetails, WiFiConnection.EMPTY)
7171
val predicate: Predicate = truePredicate
7272
doReturn(predicate).whenever(fixture).predicate(settings)
73-
whenever(dataManager.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y)).thenReturn(newSeries)
73+
whenever(dataManager.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y, predicate)).thenReturn(newSeries)
7474
whenever(settings.sortBy()).thenReturn(SortBy.SSID)
7575
whenever(settings.timeGraphLegend()).thenReturn(GraphLegend.LEFT)
7676
whenever(settings.wiFiBand()).thenReturn(WiFiBand.GHZ2)
@@ -80,7 +80,7 @@ class TimeGraphViewTest {
8080
fixture.update(wiFiData)
8181
// validate
8282
verify(fixture).predicate(settings)
83-
verify(dataManager).addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y)
83+
verify(dataManager).addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y, predicate)
8484
verify(graphViewWrapper).removeSeries(newSeries)
8585
verify(graphViewWrapper).updateLegend(GraphLegend.LEFT)
8686
verify(graphViewWrapper).visibility(View.VISIBLE)

0 commit comments

Comments
 (0)