Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13414


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
Files:
3 edited

Legend:

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

    r12012 r13414  
    2222using System;
    2323using System.IO;
     24using System.Threading.Tasks;
    2425using System.Windows.Forms;
    2526using HeuristicLab.MainForm;
     
    4445      if (importTypeDialog.ShowDialog() == DialogResult.OK) {
    4546        IRegressionProblemData instance = null;
    46         try {
    47           instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType, importTypeDialog.CSVFormat);
    48         } catch (IOException ex) {
    49           ErrorWhileParsing(ex);
    50           return;
    51         }
    52         try {
    53           GenericConsumer.Load(instance);
    54           instancesComboBox.SelectedIndex = -1;
    55         } catch (IOException ex) {
    56           ErrorWhileLoading(ex, importTypeDialog.Path);
    57         }
     47
     48        Task.Factory.StartNew(() => {
     49          var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
     50          // lock active view and show progress bar
     51          IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
     52
     53          try {
     54            var progress = mainForm.AddOperationProgressToContent(activeView.Content, "Loading problem instance.");
     55
     56            Content.ProgressChanged += (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };
     57
     58            instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType, importTypeDialog.CSVFormat);
     59          } catch (IOException ex) {
     60            ErrorWhileParsing(ex);
     61            mainForm.RemoveOperationProgressFromContent(activeView.Content);
     62            return;
     63          }
     64          try {
     65            GenericConsumer.Load(instance);
     66            instancesComboBox.SelectedIndex = -1;
     67          } catch (IOException ex) {
     68            ErrorWhileLoading(ex, importTypeDialog.Path);
     69          } finally {
     70            mainForm.RemoveOperationProgressFromContent(activeView.Content);
     71          }
     72        });
    5873      }
    5974    }
  • 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.