Replace the 2 deviation maps with one with DeviationInfo as value

DeviationInfo carries deviation and deviationSeverity
This commit is contained in:
chimp1984 2020-10-26 20:42:10 -05:00
parent 3a9b3c97e1
commit 44d9efd735
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
4 changed files with 45 additions and 15 deletions

View File

@ -0,0 +1,32 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.network.p2p.inventory.model;
import lombok.Value;
@Value
public class DeviationInfo {
private final Double deviation;
private final DeviationSeverity deviationSeverity;
public DeviationInfo(Double deviation, DeviationSeverity deviationSeverity) {
this.deviation = deviation;
this.deviationSeverity = deviationSeverity;
}
}

View File

@ -37,8 +37,7 @@ public class RequestInfo {
@Setter
private String errorMessage;
private final Map<InventoryItem, Double> deviationMap = new HashMap<>();
private final Map<InventoryItem, DeviationSeverity> deviationSeverityMap = new HashMap<>();
private final Map<InventoryItem, DeviationInfo> deviationInfoMap = new HashMap<>();
public RequestInfo(long requestStartTime) {
this.requestStartTime = requestStartTime;

View File

@ -20,6 +20,7 @@ package bisq.inventory;
import bisq.core.network.p2p.inventory.GetInventoryRequestManager;
import bisq.core.network.p2p.inventory.model.Average;
import bisq.core.network.p2p.inventory.model.DeviationInfo;
import bisq.core.network.p2p.inventory.model.DeviationSeverity;
import bisq.core.network.p2p.inventory.model.InventoryItem;
import bisq.core.network.p2p.inventory.model.RequestInfo;
@ -183,12 +184,11 @@ public class InventoryMonitor implements SetupListener {
List.of(InventoryItem.values()).forEach(inventoryItem -> {
String value = requestInfo.getValue(inventoryItem);
Double deviation = inventoryItem.getDeviation(averageValues, value);
requestInfo.getDeviationMap().put(inventoryItem, deviation);
DeviationSeverity deviationSeverity = inventoryItem.getDeviationSeverity(deviation,
requestInfoListByNode.values(),
value,
finalDaoStateChainHeight);
requestInfo.getDeviationSeverityMap().put(inventoryItem, deviationSeverity);
requestInfo.getDeviationInfoMap().put(inventoryItem, new DeviationInfo(deviation, deviationSeverity));
});
inventoryWebServer.onNewRequestInfo(requestInfoListByNode, requestCounter);

View File

@ -17,6 +17,7 @@
package bisq.inventory;
import bisq.core.network.p2p.inventory.model.DeviationInfo;
import bisq.core.network.p2p.inventory.model.DeviationSeverity;
import bisq.core.network.p2p.inventory.model.InventoryItem;
import bisq.core.network.p2p.inventory.model.RequestInfo;
@ -336,14 +337,12 @@ public class InventoryWebServer {
}
String deviationAsPercentString = "";
if (requestInfo.getDeviationMap().containsKey(inventoryItem)) {
Double deviation = requestInfo.getDeviationMap().get(inventoryItem);
deviationAsPercentString = getDeviationAsPercentString(deviation);
}
DeviationSeverity deviationSeverity = DeviationSeverity.OK;
if (requestInfo.getDeviationSeverityMap().containsKey(inventoryItem)) {
deviationSeverity = requestInfo.getDeviationSeverityMap().get(inventoryItem);
if (requestInfo.getDeviationInfoMap().containsKey(inventoryItem)) {
DeviationInfo deviationInfo = requestInfo.getDeviationInfoMap().get(inventoryItem);
deviationAsPercentString = getDeviationAsPercentString(deviationInfo.getDeviation());
deviationSeverity = deviationInfo.getDeviationSeverity();
}
List<RequestInfo> requestInfoList = map.get(seedNode);
@ -354,13 +353,13 @@ public class InventoryWebServer {
if (requestInfoList != null) {
for (int i = 0; i < requestInfoList.size(); i++) {
RequestInfo reqInfo = requestInfoList.get(i);
Map<InventoryItem, DeviationSeverity> deviationSeverityMap = reqInfo.getDeviationSeverityMap();
Map<InventoryItem, DeviationInfo> deviationInfoMap = reqInfo.getDeviationInfoMap();
Map<InventoryItem, String> inventory = reqInfo.getInventory();
if (inventory != null &&
inventory.containsKey(inventoryItem) &&
deviationSeverityMap.containsKey(inventoryItem) &&
deviationSeverityMap.get(inventoryItem) != DeviationSeverity.OK) {
DeviationSeverity devSeverity = reqInfo.getDeviationSeverityMap().get(inventoryItem);
deviationInfoMap.containsKey(inventoryItem) &&
deviationInfoMap.get(inventoryItem).getDeviationSeverity() != DeviationSeverity.OK) {
DeviationSeverity devSeverity = deviationInfoMap.get(inventoryItem).getDeviationSeverity();
if (devSeverity == DeviationSeverity.WARN) {
warningsAtRequestNumber.add(i + 1);
} else if (devSeverity == DeviationSeverity.ALERT) {