- Timestamp:
- 11/29/15 16:59:52 (9 years ago)
- 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 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.ComponentModel; 26 using System.Drawing; 25 27 using System.Globalization; 26 28 using System.IO; … … 35 37 where ImportType : DataAnalysisImportType { 36 38 39 public event ProgressChangedEventHandler ProgressChanged; 37 40 38 41 public TData ImportData(string path, ImportType type, DataAnalysisCSVFormat csvFormat) { 39 42 TableFileParser csvFileParser = new TableFileParser(); 43 long fileSize = new FileInfo(path).Length; 44 csvFileParser.ProgressChanged += (sender, e) => { 45 OnProgressChanged(e / (double)fileSize); 46 }; 40 47 csvFileParser.Parse(path, csvFormat.NumberFormatInfo, csvFormat.DateTimeFormatInfo, csvFormat.Separator, csvFormat.VariableNamesAvailable); 41 48 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)); 42 55 } 43 56 -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/TableFileParser.cs
r13413 r13414 30 30 31 31 namespace HeuristicLab.Problems.Instances.DataAnalysis { 32 public class TableFileParser {32 public class TableFileParser : Progress<long> { // reports the number of bytes read 33 33 private const int BUFFER_SIZE = 65536; 34 34 // char used to symbolize whitespaces (no missing values can be handled with whitespaces) … … 310 310 private set { currentLine = value; } 311 311 } 312 public long BytesRead { 313 get; 314 private set; 315 } 316 312 317 313 318 public Tokenizer(StreamReader reader, NumberFormatInfo numberFormatInfo, DateTimeFormatInfo dateTimeFormatInfo, char separator) { … … 322 327 if (!reader.EndOfStream) { 323 328 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 } 324 336 int i = 0; 325 337 foreach (var tok in Split(CurrentLine)) { … … 449 461 rowValues.Add(row); 450 462 } 463 464 OnReport(tokenizer.BytesRead); 451 465 } 452 466 }
Note: See TracChangeset
for help on using the changeset viewer.