Search in sources :

Example 1 with ConsumerPriceIndex

use of name.abuchen.portfolio.model.ConsumerPriceIndex in project portfolio by buchen.

the class DestatisCPIFeed method getConsumerPriceIndices.

@Override
public List<ConsumerPriceIndex> getConsumerPriceIndices() throws IOException {
    try {
        disableCertificateValidation();
        URL url = new URL(// $NON-NLS-1$
        "https://www.destatis.de/DE/ZahlenFakten/GesamtwirtschaftUmwelt/Preise/Verbraucherpreisindizes/Tabellen_/VerbraucherpreiseKategorien.html");
        Lexer lexer = new Lexer(url.openConnection());
        List<ConsumerPriceIndex> prices = new Visitor().visit(lexer);
        if (prices.isEmpty())
            throw new IOException(Messages.MsgResponseContainsNoIndices);
        return prices;
    } catch (ParserException e) {
        throw new IOException(e);
    }
}
Also used : ParserException(org.htmlparser.util.ParserException) Lexer(org.htmlparser.lexer.Lexer) ConsumerPriceIndex(name.abuchen.portfolio.model.ConsumerPriceIndex) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with ConsumerPriceIndex

use of name.abuchen.portfolio.model.ConsumerPriceIndex in project portfolio by buchen.

the class DestatisCPIFeedTest method testParsingHtml.

@Test
public void testParsingHtml() throws IOException, ParserException {
    try (Scanner scanner = new Scanner(getClass().getResourceAsStream("response_destatis.txt"), "UTF-8")) {
        String html = scanner.useDelimiter("\\A").next();
        Lexer lexer = new Lexer(html);
        List<ConsumerPriceIndex> prices = new DestatisCPIFeed.Visitor().visit(lexer);
        assertThat(prices.size(), equalTo(19 * /* years in file */
        12 + 6));
        ConsumerPriceIndex p = prices.get(5);
        assertThat(p.getYear(), equalTo(2012));
        assertThat(p.getMonth(), equalTo(Month.JANUARY.getValue()));
        assertThat(p.getIndex(), equalTo(11150));
    }
}
Also used : Scanner(java.util.Scanner) Lexer(org.htmlparser.lexer.Lexer) ConsumerPriceIndex(name.abuchen.portfolio.model.ConsumerPriceIndex) Test(org.junit.Test)

Example 3 with ConsumerPriceIndex

use of name.abuchen.portfolio.model.ConsumerPriceIndex in project portfolio by buchen.

the class ConsumerPriceIndexListView method createTopTable.

@Override
protected void createTopTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    indices = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnEditingSupport.prepare(indices);
    ShowHideColumnHelper support = new ShowHideColumnHelper(// $NON-NLS-1$
    ConsumerPriceIndexListView.class.getSimpleName() + "@bottom", // $NON-NLS-1$
    getPreferenceStore(), // $NON-NLS-1$
    indices, layout);
    Column column = new Column(Messages.ColumnYear, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return String.valueOf(((ConsumerPriceIndex) element).getYear());
        }
    });
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnViewerSorter.create(ConsumerPriceIndex.class, "year", "month").attachTo(column, SWT.DOWN);
    // $NON-NLS-1$
    new ValueEditingSupport(ConsumerPriceIndex.class, "year", Values.Year).addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnMonth, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            int month = ((ConsumerPriceIndex) element).getMonth();
            return Month.of(month).getDisplayName(TextStyle.FULL, Locale.getDefault());
        }
    });
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnViewerSorter.create(ConsumerPriceIndex.class, "month", "year").attachTo(column);
    // $NON-NLS-1$
    new MonthEditingSupport(ConsumerPriceIndex.class, "month").addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnIndex, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return Values.Index.format(((ConsumerPriceIndex) element).getIndex());
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(ConsumerPriceIndex.class, "index").attachTo(column);
    // $NON-NLS-1$
    new ValueEditingSupport(ConsumerPriceIndex.class, "index", Values.Index).addListener(this).attachTo(column);
    support.addColumn(column);
    support.createColumns();
    indices.getTable().setHeaderVisible(true);
    indices.getTable().setLinesVisible(true);
    indices.setContentProvider(ArrayContentProvider.getInstance());
    indices.setInput(getClient().getConsumerPriceIndices());
    indices.refresh();
    hookContextMenu(indices.getTable(), new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            fillContextMenu(manager);
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IMenuListener(org.eclipse.jface.action.IMenuListener) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) MonthEditingSupport(name.abuchen.portfolio.ui.util.viewers.MonthEditingSupport) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) ConsumerPriceIndex(name.abuchen.portfolio.model.ConsumerPriceIndex) Column(name.abuchen.portfolio.ui.util.viewers.Column) IMenuManager(org.eclipse.jface.action.IMenuManager) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 4 with ConsumerPriceIndex

use of name.abuchen.portfolio.model.ConsumerPriceIndex in project portfolio by buchen.

the class ConsumerPriceIndexListView method refreshChart.

private void refreshChart() {
    try {
        chart.suspendUpdate(true);
        for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
        if (getClient().getConsumerPriceIndices() == null || getClient().getConsumerPriceIndices().isEmpty())
            return;
        List<ConsumerPriceIndex> indices = new ArrayList<ConsumerPriceIndex>(getClient().getConsumerPriceIndices());
        Collections.sort(indices, new ConsumerPriceIndex.ByDate());
        LocalDate[] dates = new LocalDate[indices.size()];
        double[] cpis = new double[indices.size()];
        int ii = 0;
        for (ConsumerPriceIndex index : indices) {
            dates[ii] = LocalDate.of(index.getYear(), index.getMonth(), 1);
            cpis[ii] = (double) index.getIndex() / Values.Index.divider();
            ii++;
        }
        chart.addDateSeries(dates, cpis, Colors.CPI, Messages.LabelConsumerPriceIndex);
        chart.adjustRange();
    } finally {
        chart.suspendUpdate(false);
        chart.redraw();
    }
}
Also used : ConsumerPriceIndex(name.abuchen.portfolio.model.ConsumerPriceIndex) ArrayList(java.util.ArrayList) ISeries(org.swtchart.ISeries) LocalDate(java.time.LocalDate)

Example 5 with ConsumerPriceIndex

use of name.abuchen.portfolio.model.ConsumerPriceIndex in project portfolio by buchen.

the class ConsumerPriceIndexListView method fillContextMenu.

private void fillContextMenu(IMenuManager manager) {
    manager.add(new Action(Messages.ConsumerPriceIndexMenuDelete) {

        @Override
        public void run() {
            ConsumerPriceIndex index = (ConsumerPriceIndex) ((IStructuredSelection) indices.getSelection()).getFirstElement();
            if (index == null)
                return;
            getClient().removeConsumerPriceIndex(index);
            markDirty();
            indices.setInput(getClient().getConsumerPriceIndices());
            refreshChart();
        }
    });
    manager.add(new Action(Messages.ConsumerPriceIndexMenuAdd) {

        @Override
        public void run() {
            ConsumerPriceIndex index = new ConsumerPriceIndex();
            LocalDate now = LocalDate.now();
            index.setYear(now.getYear());
            index.setMonth(now.getMonthValue());
            getClient().addConsumerPriceIndex(index);
            markDirty();
            indices.setInput(getClient().getConsumerPriceIndices());
            indices.editElement(index, 0);
            refreshChart();
        }
    });
}
Also used : Action(org.eclipse.jface.action.Action) ConsumerPriceIndex(name.abuchen.portfolio.model.ConsumerPriceIndex) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LocalDate(java.time.LocalDate)

Aggregations

ConsumerPriceIndex (name.abuchen.portfolio.model.ConsumerPriceIndex)7 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 Lexer (org.htmlparser.lexer.Lexer)2 URL (java.net.URL)1 Scanner (java.util.Scanner)1 CPIFeed (name.abuchen.portfolio.online.CPIFeed)1 DestatisCPIFeed (name.abuchen.portfolio.online.DestatisCPIFeed)1 Column (name.abuchen.portfolio.ui.util.viewers.Column)1 MonthEditingSupport (name.abuchen.portfolio.ui.util.viewers.MonthEditingSupport)1 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)1 ValueEditingSupport (name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport)1 Interval (name.abuchen.portfolio.util.Interval)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 Action (org.eclipse.jface.action.Action)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1