deduplicate additional trade statistics (#1326)

This commit is contained in:
woodser 2024-10-13 08:31:59 -04:00 committed by GitHub
parent cda610fdfd
commit a6c178c058
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -120,22 +120,18 @@ public class TradeStatisticsManager {
// collect duplicated trades // collect duplicated trades
Set<TradeStatistics3> duplicates = new HashSet<TradeStatistics3>(); Set<TradeStatistics3> duplicates = new HashSet<TradeStatistics3>();
Set<TradeStatistics3> deduplicates = new HashSet<TradeStatistics3>(); Set<TradeStatistics3> deduplicates = new HashSet<TradeStatistics3>();
Set<TradeStatistics3> usedAsDuplicate = new HashSet<TradeStatistics3>();
for (TradeStatistics3 tradeStatistic : earlyTrades) { for (TradeStatistics3 tradeStatistic : earlyTrades) {
TradeStatistics3 fuzzyDuplicate = findFuzzyDuplicate(tradeStatistic, deduplicates, usedAsDuplicate); TradeStatistics3 fuzzyDuplicate = findFuzzyDuplicate(tradeStatistic, deduplicates);
if (fuzzyDuplicate == null) deduplicates.add(tradeStatistic); if (fuzzyDuplicate == null) deduplicates.add(tradeStatistic);
else { else duplicates.add(tradeStatistic);
duplicates.add(tradeStatistic);
usedAsDuplicate.add(fuzzyDuplicate);
}
} }
// remove duplicated trades // remove duplicated trades
tradeStats.removeAll(duplicates); tradeStats.removeAll(duplicates);
} }
private TradeStatistics3 findFuzzyDuplicate(TradeStatistics3 tradeStatistics, Set<TradeStatistics3> set, Set<TradeStatistics3> excluded) { private TradeStatistics3 findFuzzyDuplicate(TradeStatistics3 tradeStatistics, Set<TradeStatistics3> set) {
return set.stream().filter(e -> !excluded.contains(e)).filter(e -> isFuzzyDuplicate(tradeStatistics, e)).findFirst().orElse(null); return set.stream().filter(e -> isFuzzyDuplicate(tradeStatistics, e)).findFirst().orElse(null);
} }
private boolean isFuzzyDuplicate(TradeStatistics3 tradeStatistics1, TradeStatistics3 tradeStatistics2) { private boolean isFuzzyDuplicate(TradeStatistics3 tradeStatistics1, TradeStatistics3 tradeStatistics2) {