Search in sources :

Example 16 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.

the class PerformanceIndex method exportTo.

private void exportTo(File file, Predicate<Integer> filter) throws IOException {
    CSVStrategy strategy = new CSVStrategy(';', '"', CSVStrategy.COMMENTS_DISABLED, CSVStrategy.ESCAPE_DISABLED, false, false, false, false);
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
        CSVPrinter printer = new CSVPrinter(writer);
        printer.setStrategy(strategy);
        printer.println(new String[] { // 
        Messages.CSVColumn_Date, // 
        Messages.CSVColumn_Value, // 
        Messages.CSVColumn_InboundTransferals, // 
        Messages.CSVColumn_OutboundTransferals, // 
        Messages.CSVColumn_DeltaInPercent, Messages.CSVColumn_CumulatedPerformanceInPercent });
        for (int ii = 0; ii < totals.length; ii++) {
            if (!filter.test(ii))
                continue;
            printer.print(dates[ii].toString());
            printer.print(Values.Amount.format(totals[ii]));
            printer.print(Values.Amount.format(inboundTransferals[ii]));
            printer.print(Values.Amount.format(outboundTransferals[ii]));
            printer.print(Values.Percent.format(delta[ii]));
            printer.print(Values.Percent.format(accumulated[ii]));
            printer.println();
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) FileOutputStream(java.io.FileOutputStream) CSVStrategy(org.apache.commons.csv.CSVStrategy) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 17 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.

the class TreeViewerCSVExporter method writeToFile.

@Override
protected void writeToFile(File file) throws IOException {
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
        CSVPrinter printer = new CSVPrinter(writer);
        printer.setStrategy(STRATEGY);
        ITreeContentProvider provider = (ITreeContentProvider) viewer.getContentProvider();
        int depth = depth(provider);
        int columnCount = viewer.getTree().getColumnCount();
        ILabelProvider[] labels = new ILabelProvider[columnCount];
        extractLabelProvider(labels);
        // write header
        String label = viewer.getTree().getColumn(0).getText();
        for (int ii = 0; ii < depth; ii++) // $NON-NLS-1$
        printer.print(label + " " + (ii + 1));
        for (int ii = 1; ii < columnCount; ii++) printer.print(viewer.getTree().getColumn(ii).getText());
        printer.println();
        // write body
        LinkedList<String> path = new LinkedList<>();
        for (Object element : provider.getElements(null)) {
            writeLine(printer, provider, labels, depth, path, element);
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) LinkedList(java.util.LinkedList)

Example 18 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.

the class AktienfreundeNetExporter method exportAllTransactions.

/**
 * Export all transactions in 'aktienfreunde.net' Format
 */
public void exportAllTransactions(File file, Client client) throws IOException {
    // collect transactions
    List<? extends Transaction> transactions = Stream.concat(client.getAccounts().stream(), client.getPortfolios().stream()).flatMap(// 
    l -> l.getTransactions().stream()).sorted(// 
    new Transaction.ByDate()).collect(Collectors.toList());
    // write to file
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
        CSVPrinter printer = new CSVPrinter(writer);
        printer.setStrategy(CSVExporter.STRATEGY);
        writeHeader(printer);
        // only buy/sell/dividend transactions
        for (Transaction t : transactions) {
            if (t instanceof AccountTransaction)
                writeDividend(printer, (AccountTransaction) t);
            else if (t instanceof PortfolioTransaction)
                writeBuySell(printer, (PortfolioTransaction) t);
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 19 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.

the class CSVExporter method exportPortfolioTransactions.

public void exportPortfolioTransactions(File file, Portfolio portfolio) throws IOException {
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
        CSVPrinter printer = new CSVPrinter(writer);
        printer.setStrategy(STRATEGY);
        printer.println(new String[] { // 
        Messages.CSVColumn_Date, // 
        Messages.CSVColumn_Type, // 
        Messages.CSVColumn_Value, // 
        Messages.CSVColumn_TransactionCurrency, // 
        Messages.CSVColumn_GrossAmount, // 
        Messages.CSVColumn_CurrencyGrossAmount, // 
        Messages.CSVColumn_ExchangeRate, // 
        Messages.CSVColumn_Fees, // 
        Messages.CSVColumn_Taxes, // 
        Messages.CSVColumn_Shares, // 
        Messages.CSVColumn_ISIN, // 
        Messages.CSVColumn_WKN, // 
        Messages.CSVColumn_TickerSymbol, // 
        Messages.CSVColumn_SecurityName, Messages.CSVColumn_Note });
        for (PortfolioTransaction t : portfolio.getTransactions()) {
            printer.print(t.getDateTime().toString());
            printer.print(t.getType().toString());
            printer.print(Values.Amount.format(t.getType().isLiquidation() ? -t.getAmount() : t.getAmount()));
            printer.print(t.getCurrencyCode());
            // gross amount
            Optional<Unit> grossAmount = t.getUnit(Unit.Type.GROSS_VALUE);
            if (grossAmount.isPresent()) {
                Money forex = grossAmount.get().getForex();
                printer.print(Values.Amount.format(forex.getAmount()));
                printer.print(forex.getCurrencyCode());
                printer.print(Values.ExchangeRate.format(grossAmount.get().getExchangeRate()));
            } else {
                // $NON-NLS-1$
                printer.print("");
                // $NON-NLS-1$
                printer.print("");
                // $NON-NLS-1$
                printer.print("");
            }
            printer.print(Values.Amount.format(t.getUnitSum(Unit.Type.FEE).getAmount()));
            printer.print(Values.Amount.format(t.getUnitSum(Unit.Type.TAX).getAmount()));
            printer.print(Values.Share.format(t.getShares()));
            printSecurityInfo(printer, t);
            printer.print(escapeNull(t.getNote()));
            printer.println();
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) Money(name.abuchen.portfolio.money.Money) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Unit(name.abuchen.portfolio.model.Transaction.Unit) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 20 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.

the class CSVExporter method exportSecurityPrices.

public void exportSecurityPrices(File file, Security security) throws IOException {
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
        CSVPrinter printer = new CSVPrinter(writer);
        printer.setStrategy(STRATEGY);
        printer.println(new String[] { Messages.CSVColumn_Date, Messages.CSVColumn_Quote });
        for (SecurityPrice p : security.getPrices()) {
            printer.print(p.getDate().toString());
            printer.print(Values.Quote.format(p.getValue()));
            printer.println();
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

CSVPrinter (org.apache.commons.csv.CSVPrinter)75 IOException (java.io.IOException)26 CSVFormat (org.apache.commons.csv.CSVFormat)21 OutputStreamWriter (java.io.OutputStreamWriter)18 StringWriter (java.io.StringWriter)15 ArrayList (java.util.ArrayList)15 Writer (java.io.Writer)13 FileOutputStream (java.io.FileOutputStream)12 Test (org.junit.Test)11 FileWriter (java.io.FileWriter)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 BufferedWriter (java.io.BufferedWriter)7 PrintWriter (java.io.PrintWriter)5 JSONArray (org.json.JSONArray)5 File (java.io.File)4 Map (java.util.Map)4 Word (ai.elimu.model.content.Word)3 Path (java.nio.file.Path)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 Letter (ai.elimu.model.content.Letter)2