Search in sources :

Example 1 with CacheKey

use of name.abuchen.portfolio.ui.util.CacheKey in project portfolio by buchen.

the class AbstractTradesWidget method getUpdateTask.

@Override
public Supplier<TradeDetailsView.Input> getUpdateTask() {
    Interval interval = get(ReportingPeriodConfig.class).getReportingPeriod().toInterval(LocalDate.now());
    ClientFilter clientFilter = get(ClientFilterConfig.class).getSelectedFilter();
    CacheKey key = new CacheKey(TradeCollector.class, clientFilter, interval);
    return () -> {
        TradeDetailsView.Input input = (TradeDetailsView.Input) getDashboardData().getCache().computeIfAbsent(key, k -> {
            Client filteredClient = clientFilter.filter(getClient());
            TradeCollector collector = new TradeCollector(filteredClient, getDashboardData().getCurrencyConverter());
            List<Trade> trades = new ArrayList<>();
            List<TradeCollectorException> errors = new ArrayList<>();
            getClient().getSecurities().forEach(s -> {
                try {
                    trades.addAll(collector.collect(s));
                } catch (TradeCollectorException error) {
                    errors.add(error);
                }
            });
            return new TradeDetailsView.Input(interval, trades, errors);
        });
        return new TradeDetailsView.Input(input.getInterval(), input.getTrades().stream().filter(getFilter(interval)).collect(Collectors.toList()), input.getErrors());
    };
}
Also used : TradeDetailsView(name.abuchen.portfolio.ui.views.trades.TradeDetailsView) ArrayList(java.util.ArrayList) Trade(name.abuchen.portfolio.snapshot.trades.Trade) Input(name.abuchen.portfolio.ui.views.trades.TradeDetailsView.Input) Input(name.abuchen.portfolio.ui.views.trades.TradeDetailsView.Input) TradeCollectorException(name.abuchen.portfolio.snapshot.trades.TradeCollectorException) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) Client(name.abuchen.portfolio.model.Client) TradeCollector(name.abuchen.portfolio.snapshot.trades.TradeCollector) CacheKey(name.abuchen.portfolio.ui.util.CacheKey) Interval(name.abuchen.portfolio.util.Interval)

Example 2 with CacheKey

use of name.abuchen.portfolio.ui.util.CacheKey in project portfolio by buchen.

the class DataSeriesCache method lookup.

public PerformanceIndex lookup(DataSeries series, Interval reportingPeriod) {
    // Every data series is cached separately except the for the client. The
    // client data series are created out of the same PerformanceIndex
    // instance, e.g. accumulated and delta performance.
    // $NON-NLS-1$
    String uuid = series.getType() == DataSeries.Type.CLIENT ? "$client$" : series.getUUID();
    CacheKey key = new CacheKey(uuid, reportingPeriod);
    // #computeIfAbsent leads to a ConcurrentMapModificdation b/c #calculate
    // might call #lookup to calculate other cache entries
    PerformanceIndex result = cache.get(key);
    if (result != null)
        return result;
    result = calculate(series, reportingPeriod);
    cache.put(key, result);
    return result;
}
Also used : CacheKey(name.abuchen.portfolio.ui.util.CacheKey) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex)

Example 3 with CacheKey

use of name.abuchen.portfolio.ui.util.CacheKey in project portfolio by buchen.

the class ActivityWidget method getUpdateTask.

@SuppressWarnings("unchecked")
@Override
public Supplier<List<TransactionPair<?>>> getUpdateTask() {
    Interval interval = get(ReportingPeriodConfig.class).getReportingPeriod().toInterval(LocalDate.now());
    ClientFilter clientFilter = get(ClientFilterConfig.class).getSelectedFilter();
    CacheKey key = new CacheKey(TransactionPair.class, clientFilter, interval);
    return () -> (List<TransactionPair<?>>) getDashboardData().getCache().computeIfAbsent(key, k -> clientFilter.filter(getClient()).getAllTransactions());
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Values(name.abuchen.portfolio.money.Values) IPlotArea(org.swtchart.IPlotArea) CacheKey(name.abuchen.portfolio.ui.util.CacheKey) IAxis(org.swtchart.IAxis) ICustomPaintListener(org.swtchart.ICustomPaintListener) LineStyle(org.swtchart.LineStyle) PlainChart(name.abuchen.portfolio.ui.util.chart.PlainChart) ISeries(org.swtchart.ISeries) TimelineChartToolTip(name.abuchen.portfolio.ui.util.chart.TimelineChartToolTip) Supplier(java.util.function.Supplier) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) ArrayList(java.util.ArrayList) Widget(name.abuchen.portfolio.model.Dashboard.Widget) PaintEvent(org.eclipse.swt.events.PaintEvent) Chart(org.swtchart.Chart) TextUtil(name.abuchen.portfolio.util.TextUtil) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) Interval(name.abuchen.portfolio.util.Interval) GridData(org.eclipse.swt.layout.GridData) UIConstants(name.abuchen.portfolio.ui.UIConstants) Pair(name.abuchen.portfolio.util.Pair) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) Dashboard(name.abuchen.portfolio.model.Dashboard) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) TransactionPair(name.abuchen.portfolio.model.TransactionPair) DecimalFormat(java.text.DecimalFormat) Collectors(java.util.stream.Collectors) IBarSeries(org.swtchart.IBarSeries) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) List(java.util.List) Position(org.swtchart.IAxis.Position) Colors(name.abuchen.portfolio.ui.util.Colors) Color(org.eclipse.swt.graphics.Color) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) YearMonth(java.time.YearMonth) SeriesType(org.swtchart.ISeries.SeriesType) Optional(java.util.Optional) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) ArrayList(java.util.ArrayList) List(java.util.List) CacheKey(name.abuchen.portfolio.ui.util.CacheKey) Interval(name.abuchen.portfolio.util.Interval)

Aggregations

CacheKey (name.abuchen.portfolio.ui.util.CacheKey)3 ArrayList (java.util.ArrayList)2 ClientFilter (name.abuchen.portfolio.snapshot.filter.ClientFilter)2 Interval (name.abuchen.portfolio.util.Interval)2 DecimalFormat (java.text.DecimalFormat)1 LocalDate (java.time.LocalDate)1 YearMonth (java.time.YearMonth)1 List (java.util.List)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Client (name.abuchen.portfolio.model.Client)1 Dashboard (name.abuchen.portfolio.model.Dashboard)1 Widget (name.abuchen.portfolio.model.Dashboard.Widget)1 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)1 TransactionPair (name.abuchen.portfolio.model.TransactionPair)1 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)1 Values (name.abuchen.portfolio.money.Values)1 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)1 Trade (name.abuchen.portfolio.snapshot.trades.Trade)1