Skip to content

Commit 2d7c3a6

Browse files
committed
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.
1 parent aa36db8 commit 2d7c3a6

4 files changed

Lines changed: 33 additions & 23 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: 12 additions & 12 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,7 +150,7 @@ 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)
@@ -165,8 +167,7 @@ class DataManagerTest {
165167
val staleEntries: Set<WiFiDetail> = makeMoreWiFiDetails().toSet()
166168
whenever(timeGraphCache.active()).thenReturn(staleEntries)
167169
// execute
168-
val actual = fixture.newSeries(currentDetails)
169-
// validate: current entries must be present, stale entries must NOT leak in
170+
val actual = fixture.newSeries(currentDetails, falsePredicate)
170171
assertThat(actual).containsAll(currentDetails)
171172
assertThat(actual).doesNotContainAnyElementsOf(staleEntries)
172173
verify(timeGraphCache).active()
@@ -183,8 +184,7 @@ class DataManagerTest {
183184
whenever(graphViewWrapper.differenceSeries(currentDetails))
184185
.thenReturn(listOf(staleEntry))
185186
// execute
186-
fixture.adjustData(graphViewWrapper, currentDetails)
187-
// validate: stale entries must NOT receive floor data points
187+
fixture.adjustData(graphViewWrapper, currentDetails, falsePredicate)
188188
verify(graphViewWrapper, never()).appendToSeries(
189189
eq(staleEntry),
190190
any(),

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)