From d360de5d6ff792522236b70aafafadcc5e351fc6 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sun, 9 Jun 2024 20:10:27 -0400 Subject: [PATCH] Changed time interval cutoff. --- .../module/TotalAssetsGraphModule.java | 31 +++---------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/andrewlalis/perfin/view/component/module/TotalAssetsGraphModule.java b/src/main/java/com/andrewlalis/perfin/view/component/module/TotalAssetsGraphModule.java index ceff061..4d7ff28 100644 --- a/src/main/java/com/andrewlalis/perfin/view/component/module/TotalAssetsGraphModule.java +++ b/src/main/java/com/andrewlalis/perfin/view/component/module/TotalAssetsGraphModule.java @@ -3,7 +3,6 @@ package com.andrewlalis.perfin.view.component.module; import com.andrewlalis.perfin.data.AccountRepository; import com.andrewlalis.perfin.data.TimestampRange; import com.andrewlalis.perfin.data.TransactionRepository; -import com.andrewlalis.perfin.data.util.ColorUtil; import com.andrewlalis.perfin.model.Profile; import com.andrewlalis.perfin.model.Transaction; import javafx.application.Platform; @@ -13,9 +12,11 @@ import javafx.scene.chart.*; import javafx.scene.control.ChoiceBox; import javafx.scene.layout.Pane; -import java.time.*; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; @@ -86,28 +87,6 @@ public class TotalAssetsGraphModule extends DashboardModule { if (savedTimeRangeLabel != null && Arrays.stream(TIME_RANGE_OPTIONS).anyMatch(o -> o.name().equals(savedTimeRangeLabel))) { timeRangeChoiceBox.getSelectionModel().select(savedTimeRangeLabel); } - - // TODO: Extract logic below. - totalAssetDataPoints.clear(); - String[] dateLabels = new String[12]; - double[] values = new double[12]; - CompletableFuture[] futures = new CompletableFuture[12]; - for (int i = 0; i < 12; i++) { - final int idx = i; - Instant timestamp = Instant.now().minus((12 - i - 1) * 30, ChronoUnit.DAYS); - dateLabels[i] = LocalDate.from(timestamp.atZone(ZoneId.systemDefault())).toString(); - futures[i] = Profile.getCurrent().dataSource().getCombinedAccountBalances(timestamp) - .thenAccept(moneyValues -> { - values[idx] = moneyValues.getFirst().amount().doubleValue(); - }); - } - CompletableFuture.allOf(futures).thenRun(() -> { - List> dataPoints = new ArrayList<>(12); - for (int i = 0; i < 12; i++) { - dataPoints.add(new XYChart.Data<>(dateLabels[i], values[i])); - } - Platform.runLater(() -> totalAssetDataPoints.addAll(dataPoints)); - }); } private void renderChart() { @@ -120,7 +99,7 @@ public class TotalAssetsGraphModule extends DashboardModule { getSelectedTimestampRange().thenAccept(range -> { Duration rangeDuration = Duration.between(range.start(), range.end()); - boolean useMonths = rangeDuration.dividedBy(Duration.ofDays(1)) > 90; + boolean useMonths = rangeDuration.dividedBy(Duration.ofDays(1)) > 365; List> dataFutures = new ArrayList<>();