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);
}
}
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));
}
}
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);
}
});
}
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();
}
}
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();
}
});
}
Aggregations