Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shortcut list #3695

Merged
merged 8 commits into from
Dec 17, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@

import bisq.network.p2p.P2PService;

import bisq.common.util.Tuple2;
import bisq.common.util.Tuple4;
import bisq.common.util.Utilities;

import org.bitcoinj.core.Coin;
Expand Down Expand Up @@ -83,16 +81,8 @@

import javafx.util.Callback;

import java.text.DateFormat;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -218,15 +208,15 @@ public void onKeysAdded(List<ECKey> keys) {
};

keyEventEventHandler = event -> {
// Not intended to be public to users as the feature is not well tested
if (Utilities.isAltOrCtrlPressed(KeyCode.R, event)) {
if (revertTxColumn.isVisible()) {
confidenceColumn.getStyleClass().remove("last-column");
} else {
confidenceColumn.getStyleClass().add("last-column");
}
revertTxColumn.setVisible(!revertTxColumn.isVisible());
} else if (Utilities.isAltOrCtrlPressed(KeyCode.A, event))
chimp1984 marked this conversation as resolved.
Show resolved Hide resolved
showStatisticsPopup();
}
};

exportButton.updateText(Res.get("shared.exportCSV"));
Expand Down Expand Up @@ -556,101 +546,5 @@ private void revertTransaction(String txId, @Nullable Tradable tradable) {
}
}
}

// This method is not intended for the public so we don't translate here
private void showStatisticsPopup() {
Map<Long, List<Coin>> map = new HashMap<>();
Map<String, Tuple4<Date, Integer, Integer, Integer>> dataByDayMap = new HashMap<>();
displayedTransactions.forEach(item -> {
Coin amountAsCoin = item.getAmountAsCoin();
List<Coin> amounts;
long key = amountAsCoin.getValue();
if (!map.containsKey(key)) {
amounts = new ArrayList<>();
map.put(key, amounts);
} else {
amounts = map.get(key);
}
amounts.add(amountAsCoin);

DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US);
String day = dateFormatter.format(item.getDate());

// TODO fee is dynamic now
Coin txFee = Coin.valueOf(20_000);
Coin createOfferFee = Coin.valueOf(50_000);
Coin takeOfferFee = Coin.valueOf(100_000);

if (!dataByDayMap.containsKey(day)) {
int numOffers = 0;
int numTrades = 0;
if (amountAsCoin.compareTo(createOfferFee.subtract(txFee)) == 0)
numOffers++;
else if (amountAsCoin.compareTo(takeOfferFee.subtract(txFee)) == 0)
numTrades++;

dataByDayMap.put(day, new Tuple4<>(item.getDate(), 1, numOffers, numTrades));
} else {
Tuple4<Date, Integer, Integer, Integer> tuple = dataByDayMap.get(day);
int prev = tuple.second;
int numOffers = tuple.third;
int numTrades = tuple.fourth;
if (amountAsCoin.compareTo(createOfferFee.subtract(txFee)) == 0)
numOffers++;
else if (amountAsCoin.compareTo(takeOfferFee.subtract(txFee)) == 0)
numTrades++;

dataByDayMap.put(day, new Tuple4<>(tuple.first, ++prev, numOffers, numTrades));
}
});

StringBuilder stringBuilder = new StringBuilder();
map.forEach((key, value) -> {
// This is not intended for the public so we don't translate here
stringBuilder.append("No. of transactions for amount ").
append(formatter.formatCoinWithCode(Coin.valueOf(key))).
append(": ").
append(value.size()).
append("\n");
});

List<Tuple4<String, Date, Integer, Tuple2<Integer, Integer>>> sortedDataByDayList = dataByDayMap.entrySet().stream().
map(e -> {
Tuple4<Date, Integer, Integer, Integer> data = e.getValue();
return new Tuple4<>(e.getKey(), data.first, data.second, new Tuple2<>(data.third, data.fourth));
}).sorted((o1, o2) -> o2.second.compareTo(o1.second))
.collect(Collectors.toList());
StringBuilder transactionsByDayStringBuilder = new StringBuilder();
StringBuilder offersStringBuilder = new StringBuilder();
StringBuilder tradesStringBuilder = new StringBuilder();
StringBuilder allStringBuilder = new StringBuilder();
// This is not intended for the public so we don't translate here
allStringBuilder.append(Res.get("shared.date")).append(";").append("Offers").append(";").append("Trades").append("\n");
sortedDataByDayList.forEach(tuple4 -> {
offersStringBuilder.append(tuple4.fourth.first).append(",");
tradesStringBuilder.append(tuple4.fourth.second).append(",");
allStringBuilder.append(tuple4.first).append(";").append(tuple4.fourth.first).append(";").append(tuple4.fourth.second).append("\n");
transactionsByDayStringBuilder.append("\n").
append(tuple4.first).
append(": ").
append(tuple4.third).
append(" (Offers: ").
append(tuple4.fourth.first).
append(" / Trades: ").
append(tuple4.fourth.second).
append(")");
});
// This is not intended for the public so we don't translate here
String message = stringBuilder.toString() + "\nNo. of transactions by day:" + transactionsByDayStringBuilder.toString();
new Popup().headLine("Statistical info")
.information(message)
.actionButtonText("Copy")
.onAction(() -> Utilities.copyToClipboard(message +
"\n\nCSV (Offers):\n" + offersStringBuilder.toString() +
"\n\nCSV (Trades):\n" + tradesStringBuilder.toString() +
"\n\nCSV (all):\n" + allStringBuilder.toString()))
.show();
}

}