Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/29/15 16:59:52 (9 years ago)
Author:
gkronber
Message:

#2071: added progress reporting when importing regression problem data from csv files.

Location:
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/DataAnalysisInstanceProvider.cs

    r12012 r13414  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.ComponentModel;
     26using System.Drawing;
    2527using System.Globalization;
    2628using System.IO;
     
    3537    where ImportType : DataAnalysisImportType {
    3638
     39    public event ProgressChangedEventHandler ProgressChanged;
    3740
    3841    public TData ImportData(string path, ImportType type, DataAnalysisCSVFormat csvFormat) {
    3942      TableFileParser csvFileParser = new TableFileParser();
     43      long fileSize = new FileInfo(path).Length;
     44      csvFileParser.ProgressChanged += (sender, e) => {
     45        OnProgressChanged(e / (double)fileSize);
     46      };
    4047      csvFileParser.Parse(path, csvFormat.NumberFormatInfo, csvFormat.DateTimeFormatInfo, csvFormat.Separator, csvFormat.VariableNamesAvailable);
    4148      return ImportData(path, type, csvFileParser);
     49    }
     50
     51    protected virtual void OnProgressChanged(double d) {
     52      var handler = ProgressChanged;
     53      if (handler != null)
     54        handler(this, new ProgressChangedEventArgs((int)(100*d), null));
    4255    }
    4356
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/TableFileParser.cs

    r13413 r13414  
    3030
    3131namespace HeuristicLab.Problems.Instances.DataAnalysis {
    32   public class TableFileParser {
     32  public class TableFileParser : Progress<long> { // reports the number of bytes read
    3333    private const int BUFFER_SIZE = 65536;
    3434    // char used to symbolize whitespaces (no missing values can be handled with whitespaces)
     
    310310        private set { currentLine = value; }
    311311      }
     312      public long BytesRead {
     313        get;
     314        private set;
     315      }
     316
    312317
    313318      public Tokenizer(StreamReader reader, NumberFormatInfo numberFormatInfo, DateTimeFormatInfo dateTimeFormatInfo, char separator) {
     
    322327        if (!reader.EndOfStream) {
    323328          CurrentLine = reader.ReadLine();
     329          try {
     330            BytesRead = reader.BaseStream.Position;
     331          } catch (IOException) {
     332            BytesRead += CurrentLine.Length + 2; // guess
     333          } catch (NotSupportedException) {
     334            BytesRead += CurrentLine.Length + 2;
     335          }
    324336          int i = 0;
    325337          foreach (var tok in Split(CurrentLine)) {
     
    449461          rowValues.Add(row);
    450462        }
     463
     464        OnReport(tokenizer.BytesRead);
    451465      }
    452466    }
Note: See TracChangeset for help on using the changeset viewer.