Follow-up on stats aggregation (#96)

* fix some comments from Jerrey

Signed-off-by: zhiqiand <zhiqian@fb.com>

* fix some comments

Signed-off-by: zhiqiand <zhiqian@fb.com>

Signed-off-by: zhiqiand <zhiqian@fb.com>
This commit is contained in:
zhiqiand
2022-10-10 15:59:04 -07:00
committed by GitHub
parent 033d93beff
commit dd2b485b00
2 changed files with 18 additions and 38 deletions

View File

@@ -8,7 +8,6 @@
package com.facebook.openwifirrm.modules;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -271,7 +270,7 @@ public class Modeler implements Runnable {
State stateModel = gson.fromJson(state, State.class);
dataModel.latestStates.computeIfAbsent(
device.serialNumber,
k -> Collections.synchronizedList(new LinkedList<>())
k -> new LinkedList<>()
).add(stateModel);
logger.debug(
"Device {}: added initial state from uCentralGw",
@@ -307,10 +306,11 @@ public class Modeler implements Runnable {
List<State> latestStatesList = dataModel.latestStates
.computeIfAbsent(
record.serialNumber,
k -> Collections
.synchronizedList(new LinkedList<>())
k -> new LinkedList<>()
);
if (latestStatesList.size() >= params.stateBufferSize) {
while (
latestStatesList.size() >= params.stateBufferSize
) {
latestStatesList.remove(0);
}
latestStatesList.add(stateModel);

View File

@@ -169,48 +169,28 @@ public class AggregatedState {
this.radio = new Radio(radioInfo);
}
@Override
public int hashCode() {
return Objects.hash(bssid, station, radio);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AggregatedState other = (AggregatedState) obj;
return bssid == other.bssid && station == other.station &&
connected == other.connected && inactive == other.inactive && rssi
.equals(other.rssi) &&
rxBytes == other.rxBytes && rxBytes == other.rxPackets &&
Objects.equals(rxRate, other.rxRate) &&
txBytes == other.txBytes && txDuration == other.txDuration &&
txFailed == other.txFailed && txPackets == other.txPackets &&
Objects.equals(txRate, other.txRate) &&
txRetries == other.txRetries && ackSignal == other.ackSignal &&
ackSignalAvg == other.ackSignalAvg &&
Objects.equals(radio, other.radio);
/**
* Check whether the passed-in AggregatedState and this one match for aggregation.
* If the two match in bssid, station and radio. Then they could be aggregated.
*
* @param state the reference AggregatedState with which to check with.
* @return boolean return true if the two matches for aggregation.
*/
public boolean matchesForAggregation(AggregatedState state) {
return bssid == state.bssid && station == state.station &&
Objects.equals(radio, state.radio);
}
/**
* Add an AggregatedState to this AggregatedState. Succeed only when the two
* matches in hashCode.
* match for aggregation.
*
* @param state input AggregatedState
* @return boolean true if the two matches in bssid, station, channel,
* @return boolean true if the two match in bssid, station, channel,
* channel_width and tx_power
*/
public boolean add(AggregatedState state) {
if (hashCode() == state.hashCode()) {
if (matchesForAggregation(state)) {
this.rssi.addAll(state.rssi);
this.rxRate.add(state.rxRate);
this.txRate.add(state.txRate);