Add new average bsq price after historical data

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2022-12-15 17:46:47 -05:00 committed by Christoph Atteneder
parent 1b182743a2
commit c268cc46cb
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
2 changed files with 11 additions and 7 deletions

View File

@ -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<Date, Price> averageBsqPriceByMonth = new HashMap<>(getHistoricalAverageBsqPriceByMonth());
@Getter
private final Map<String, BalanceModel> balanceModelByBurningManName = new HashMap<>();
@ -161,6 +162,12 @@ public class BurningManAccountingService implements DaoSetupService {
return getBlocks().stream().filter(block -> block.getHeight() == height).findAny();
}
public Map<Date, Price> 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<Date, Price> getAverageBsqPriceByMonth(Date from, int toYear, int toMonth) {
private Map<Date, Price> getAverageBsqPriceByMonth(Date from, int backToYear, int backToMonth) {
Map<Date, Price> 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;
}

View File

@ -635,12 +635,9 @@ public class BurningManView extends ActivatableView<ScrollPane, Void> implements
}
Map<Date, Price> 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();
}