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

Group burned BSQ by day #3157

Merged
Merged
Changes from all commits
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 @@ -82,6 +82,7 @@
public class SupplyView extends ActivatableView<GridPane, Void> implements DaoStateListener {

private static final String MONTH = "month";
private static final String DAY = "day";

private final DaoFacade daoFacade;
private DaoStateService daoStateService;
Expand Down Expand Up @@ -113,6 +114,7 @@ private SupplyView(DaoFacade daoFacade,
public void initialize() {

ADJUSTERS.put(MONTH, TemporalAdjusters.firstDayOfMonth());
ADJUSTERS.put(DAY, TemporalAdjusters.ofDateAdjuster(d -> d));

createSupplyIncreasedInformation();
createSupplyReducedInformation();
Expand Down Expand Up @@ -161,7 +163,7 @@ private void createSupplyIncreasedInformation() {


seriesBSQIssued = new XYChart.Series<>();
createChart(seriesBSQIssued, Res.get("dao.factsAndFigures.supply.issued"));
createChart(seriesBSQIssued, Res.get("dao.factsAndFigures.supply.issued"), "MMM uu");
}

private void createSupplyReducedInformation() {
Expand All @@ -173,7 +175,7 @@ private void createSupplyReducedInformation() {
Res.get("dao.factsAndFigures.supply.invalidTxs"), Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;

seriesBSQBurnt = new XYChart.Series<>();
createChart(seriesBSQBurnt, Res.get("dao.factsAndFigures.supply.burnt"));
createChart(seriesBSQBurnt, Res.get("dao.factsAndFigures.supply.burnt"), "d MMM");
}

private void createSupplyLockedInformation() {
Expand All @@ -193,7 +195,8 @@ private void createSupplyLockedInformation() {
Res.get("dao.factsAndFigures.supply.totalConfiscatedAmount")).second;
}

private void createChart(XYChart.Series<Number, Number> series, String seriesLabel) {
@SuppressWarnings("unchecked")
private void createChart(XYChart.Series<Number, Number> series, String seriesLabel, String datePattern) {
NumberAxis xAxis = new NumberAxis();
xAxis.setForceZeroInRange(false);
xAxis.setAutoRanging(true);
Expand All @@ -205,7 +208,7 @@ private void createChart(XYChart.Series<Number, Number> series, String seriesLab
public String toString(Number timestamp) {
LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(timestamp.longValue(),
0, OffsetDateTime.now(ZoneId.systemDefault()).getOffset());
return localDateTime.format(DateTimeFormatter.ofPattern("MMM uu", GlobalSettings.getLocale()));
return localDateTime.format(DateTimeFormatter.ofPattern(datePattern, GlobalSettings.getLocale()));
}

@Override
Expand Down Expand Up @@ -296,15 +299,15 @@ private void updateCharts() {
Set<Tx> burntTxs = new HashSet<>(daoStateService.getBurntFeeTxs());
burntTxs.addAll(daoStateService.getInvalidTxs());

Map<LocalDate, List<Tx>> burntBsqByMonth = burntTxs.stream()
Map<LocalDate, List<Tx>> burntBsqByDay = burntTxs.stream()
.sorted(Comparator.comparing(Tx::getTime))
.collect(Collectors.groupingBy(item -> new Date(item.getTime()).toLocalDate()
.with(ADJUSTERS.get(MONTH))));
.with(ADJUSTERS.get(DAY))));

List<XYChart.Data<Number, Number>> updatedBurntBsq = burntBsqByMonth.keySet().stream()
List<XYChart.Data<Number, Number>> updatedBurntBsq = burntBsqByDay.keySet().stream()
.map(date -> {
ZonedDateTime zonedDateTime = date.atStartOfDay(ZoneId.systemDefault());
return new XYChart.Data<Number, Number>(zonedDateTime.toInstant().getEpochSecond(), burntBsqByMonth.get(date)
return new XYChart.Data<Number, Number>(zonedDateTime.toInstant().getEpochSecond(), burntBsqByDay.get(date)
.stream()
.mapToDouble(Tx::getBurntBsq)
.sum()
Expand Down