From c268cc46cb40b5605b7279f96cd340d62d22fe4e Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 15 Dec 2022 17:46:47 -0500 Subject: [PATCH] Add new average bsq price after historical data Signed-off-by: HenrikJannsen --- .../accounting/BurningManAccountingService.java | 15 +++++++++++---- .../dao/burnbsq/burningman/BurningManView.java | 3 --- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/burningman/accounting/BurningManAccountingService.java b/core/src/main/java/bisq/core/dao/burningman/accounting/BurningManAccountingService.java index 46b61a5092..67a2380e19 100644 --- a/core/src/main/java/bisq/core/dao/burningman/accounting/BurningManAccountingService.java +++ b/core/src/main/java/bisq/core/dao/burningman/accounting/BurningManAccountingService.java @@ -67,13 +67,14 @@ public class BurningManAccountingService implements DaoSetupService { public static final int EARLIEST_BLOCK_HEIGHT = Config.baseCurrencyNetwork().isRegtest() ? 111 : 656035; public static final int EARLIEST_DATE_YEAR = 2020; public static final int EARLIEST_DATE_MONTH = 10; + public static final int HIST_BSQ_PRICE_LAST_DATE_YEAR = 2022; + public static final int HIST_BSQ_PRICE_LAST_DATE_MONTH = 10; private final BurningManAccountingStoreService burningManAccountingStoreService; private final BurningManPresentationService burningManPresentationService; private final TradeStatisticsManager tradeStatisticsManager; private final Preferences preferences; - @Getter private final Map averageBsqPriceByMonth = new HashMap<>(getHistoricalAverageBsqPriceByMonth()); @Getter private final Map balanceModelByBurningManName = new HashMap<>(); @@ -161,6 +162,12 @@ public class BurningManAccountingService implements DaoSetupService { return getBlocks().stream().filter(block -> block.getHeight() == height).findAny(); } + public Map getAverageBsqPriceByMonth() { + getAverageBsqPriceByMonth(new Date(), HIST_BSQ_PRICE_LAST_DATE_YEAR, HIST_BSQ_PRICE_LAST_DATE_MONTH) + .forEach((key, value) -> averageBsqPriceByMonth.put(new Date(key.getTime()), Price.valueOf("BSQ", value.getValue()))); + return averageBsqPriceByMonth; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Delegates @@ -210,7 +217,7 @@ public class BurningManAccountingService implements DaoSetupService { }); } - private Map getAverageBsqPriceByMonth(Date from, int toYear, int toMonth) { + private Map getAverageBsqPriceByMonth(Date from, int backToYear, int backToMonth) { Map averageBsqPriceByMonth = new HashMap<>(); Calendar calendar = new GregorianCalendar(); calendar.setTime(from); @@ -218,7 +225,7 @@ public class BurningManAccountingService implements DaoSetupService { int month = calendar.get(Calendar.MONTH); do { for (; month >= 0; month--) { - if (year == toYear && month == toMonth) { + if (year == backToYear && month == backToMonth) { break; } Date date = DateUtil.getStartOfMonth(year, month); @@ -227,7 +234,7 @@ public class BurningManAccountingService implements DaoSetupService { } year--; month = 11; - } while (year >= toYear); + } while (year >= backToYear); return averageBsqPriceByMonth; } diff --git a/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/burningman/BurningManView.java b/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/burningman/BurningManView.java index 5b21909474..16594e8fe6 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/burningman/BurningManView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/burningman/BurningManView.java @@ -635,12 +635,9 @@ public class BurningManView extends ActivatableView implements } Map averageBsqPriceByMonth = burningManAccountingService.getAverageBsqPriceByMonth(); - long ts = System.currentTimeMillis(); balanceEntryObservableList.setAll(balanceEntries.stream() .map(balanceEntry -> new BalanceEntryItem(balanceEntry, averageBsqPriceByMonth, bsqFormatter, btcFormatter)) .collect(Collectors.toList())); - // 108869: 617 - 1878, 640-1531 - log.error("balanceEntryObservableList setAll took {} ms size={}", System.currentTimeMillis() - ts, balanceEntryObservableList.size()); } else { balanceEntryObservableList.clear(); }