Package org.encog.util.csv

Examples of org.encog.util.csv.ReadCSV


    validateAnalyzed();
    final PrintWriter tw = prepareOutputFile(outputFile);

    this.counts = new HashMap<String, Integer>();

    final ReadCSV csv = new ReadCSV(getInputFilename().toString(),
        isExpectInputHeaders(), getFormat());

    resetStatus();
    while (csv.next() && !shouldStop()) {
      final LoadedRow row = new LoadedRow(csv);
      updateStatus(false);
      final String key = row.getData()[targetField];
      int count;
      if (!this.counts.containsKey(key)) {
        count = 0;
      } else {
        count = this.counts.get(key);
      }

      if (count < countPer) {
        writeRow(tw, row);
        count++;
      }

      this.counts.put(key, count);
    }
    reportDone(false);
    csv.close();
    tw.close();
  }
View Full Code Here


   *
   * @param outputFile
   *            The output file to write to.
   */
  public void process(final File outputFile) {
    final ReadCSV csv = new ReadCSV(getInputFilename().toString(),
        isExpectInputHeaders(), getFormat());

    final PrintWriter tw = prepareOutputFile(outputFile);
    this.filteredCount = 0;

    resetStatus();
    while (csv.next() && !shouldStop()) {
      updateStatus(false);
      final LoadedRow row = new LoadedRow(csv);
      if (shouldProcess(row)) {
        writeRow(tw, row);
        this.filteredCount++;
      }
    }
    reportDone(false);
    tw.close();
    csv.close();
  }
View Full Code Here

    int idealCount = analyst.getScript().getNormalize().calculateOutputColumns();
   
        BasicMLData inputData = new BasicMLData(inputCount);
        BasicMLData idealData = new BasicMLData(idealCount);

    ReadCSV csv = null;
    BufferedMLDataSet buffer = new BufferedMLDataSet(file);
    buffer.beginLoad(inputCount,idealCount);

    try {
      csv = new ReadCSV(getInputFilename().toString(),
          isExpectInputHeaders(), getFormat());

      resetStatus();
      final int outputLength = this.analyst.determineTotalColumns();

      // write file contents
      while (csv.next() && !shouldStop()) {
        updateStatus(false);

        double[] output = AnalystNormalizeCSV.extractFields(
            this.analyst, this.analystHeaders, csv, outputLength,
            false);

        if (this.series.getTotalDepth() > 1) {
          output = this.series.process(output);
        }
       
        // copy the input
        int idx = 0;
        for(int i=0;i<inputData.size();i++) {
          inputData.setData(i, output[idx++]);
        }
       
        for(int i=0;i<idealData.size();i++) {
          idealData.setData(i, output[idx++]);
        }

        if (output != null) {
          buffer.add(inputData,idealData);
        }
      }
    } finally {
      reportDone(false);
      if (csv != null) {
        try {
          csv.close();
        } catch (final Exception ex) {
          EncogLogging.log(ex);
        }
      }
View Full Code Here

   *            The output file.
   */
  public void process(final File outputFile) {
    validateAnalyzed();

    final ReadCSV csv = new ReadCSV(getInputFilename().toString(),
        isExpectInputHeaders(), getFormat());
    LoadedRow row;

    final PrintWriter tw = prepareOutputFile(outputFile);

    resetStatus();
    while ((row = getNextRow(csv)) != null) {
      writeRow(tw, row);
      updateStatus(false);
    }
    reportDone(false);
    tw.close();
    csv.close();
  }
View Full Code Here

   * Read the input file.
   */
  private void readInputFile() {
    resetStatus();

    final ReadCSV csv = new ReadCSV(getInputFilename().toString(),
        isExpectInputHeaders(), getFormat());
    while (csv.next() && !shouldStop()) {
      updateStatus("Reading input file");
      final LoadedRow row = new LoadedRow(csv);
      this.data.add(row);
    }

    setColumnCount(csv.getColumnCount());

    if (isExpectInputHeaders()) {
      setInputHeadings(new String[csv.getColumnNames().size()]);
      for (int i = 0; i < csv.getColumnNames().size(); i++) {
        getInputHeadings()[i] = csv.getColumnNames().get(i);
      }
    }

    csv.close();
  }
View Full Code Here

   */
  public final void process(final File target) {
    PrintWriter tw = null;
   
    try {
      ReadCSV csv = new ReadCSV(this.getInputFilename().toString(),
          this.isExpectInputHeaders(), this.getFormat());

      tw = new PrintWriter(new FileWriter(target));

      resetStatus();
      while (csv.next() && !this.shouldStop()) {
        StringBuilder line = new StringBuilder();
        updateStatus(false);
        line.append(this.getColumnData(FileData.DATE, csv));
        line.append(" ");
        line.append(this.getColumnData(FileData.TIME, csv));
        line.append(";");
        line.append(getFormat().format(
            Double.parseDouble(this.getColumnData(FileData.OPEN,
                csv)), this.getPrecision()));
        line.append(";");
        line.append(getFormat().format(
            Double.parseDouble(this.getColumnData(FileData.HIGH,
                csv)), this.getPrecision()));
        line.append(";");
        line.append(getFormat().format(
            Double.parseDouble(this
                .getColumnData(FileData.LOW, csv)),
            this.getPrecision()));
        line.append(";");
        line.append(getFormat().format(
            Double.parseDouble(this.getColumnData(FileData.CLOSE,
                csv)), this.getPrecision()));
        line.append(";");
        line.append(getFormat().format(
            Double.parseDouble(this.getColumnData(FileData.VOLUME,
                csv)), this.getPrecision()));

        tw.println(line.toString());
      }
      reportDone(false);
      csv.close();
      tw.close();
    } catch (IOException ex) {
      throw new QuantError(ex);
    } finally {
      if( tw!=null ) {
View Full Code Here

   *            The output file.
   */
  public void process(final File outputFile) {
    validateAnalyzed();

    final ReadCSV csv = new ReadCSV(getInputFilename().toString(),
        isExpectInputHeaders(), getFormat());
    LoadedRow row;

    final PrintWriter tw = prepareOutputFile(outputFile);
    this.extension.init(csv,
        this.forwardWindowSize,
        this.backwardWindowSize);

    resetStatus();
    while ((row = getNextRow(csv)) != null) { 
      this.extension.loadRow(row);
   
      if(this.extension.isDataReady() ) {
        processRow(tw);
      }
      updateStatus(false);
    }
    reportDone(false);
    tw.close();
    csv.close();
  }
View Full Code Here

      final File output,
      final CSVFormat outputFormat, final Date from, final Date to) {
    try {
      final URL url = buildURL(ticker, from, to);
      final InputStream is = url.openStream();
      final ReadCSV csv = new ReadCSV(is, true, CSVFormat.ENGLISH);

      final PrintWriter tw = new PrintWriter(new FileWriter(output));
      tw.println(
    "date,time,open price,high price,low price,"
          + "close price,volume,adjusted price");

      while (csv.next() && !shouldStop()) {
        final Date date = csv.getDate("date");
        final double adjClose = csv.getDouble("adj close");
        final double open = csv.getDouble("open");
        final double close = csv.getDouble("close");
        final double high = csv.getDouble("high");
        final double low = csv.getDouble("low");
        final double volume = csv.getDouble("volume");

        final NumberFormat df = NumberFormat.getInstance();
        df.setGroupingUsed(false);

        final StringBuilder line = new StringBuilder();
View Full Code Here

    try {

      final InputStream is = ResourceInputStream
          .openResourceInputStream("org/encog/data/analyst.csv");
      final ReadCSV csv = new ReadCSV(is, false, CSVFormat.EG_FORMAT);

      while (csv.next()) {
        final String sectionStr = csv.get(0);
        final String nameStr = csv.get(1);
        final String typeStr = csv.get(2);

        // determine type
        PropertyType t = null;
        if ("boolean".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeBoolean;
        } else if ("real".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeDouble;
        } else if ("format".equalsIgnoreCase(typeStr)) {
          t = PropertyType.typeFormat;
        } else if ("int".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeInteger;
        } else if ("list-string".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeListString;
        } else if ("string".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeString;
        } else {
          throw new AnalystError("Unknown type constraint: "
              + typeStr);
        }

        final PropertyEntry entry = new PropertyEntry(t, nameStr,
            sectionStr);
        List<PropertyEntry> list;

        if (this.data.containsKey(sectionStr)) {
          list = this.data.get(sectionStr);
        } else {
          list = new ArrayList<PropertyEntry>();
          this.data.put(sectionStr, list);
        }

        list.add(entry);
      }

      csv.close();
      is.close();
    } catch (final IOException e) {
      throw new EncogError(e);
    }
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void rewind() {
    this.reader = new ReadCSV(this.file,this.headers,this.format);
    if( this.headerIndex.size()==0 ) {
      for(int i=0;i<this.reader.getColumnNames().size();i++) {
        this.headerIndex.put(this.reader.getColumnNames().get(i), i);
      }
    }
View Full Code Here

TOP

Related Classes of org.encog.util.csv.ReadCSV

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.