// Returns a negative number on error public static int TryCollectData(string filename, ref EvalueStorage Evalue, int fileNum, bool freshRun) { Stopwatch sw = new Stopwatch(); sw.Start(); // If we already have the file cached, we don't neeed to recollect the data if (!freshRun) { return(0); } try { Evalue = CollectData(filename); } catch (IndexOutOfRangeException) { MessageBox.Show("Fil: " + filename + " er ikke i det korekte format", "File " + filename + " format error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(-fileNum); } catch (IOException) { MessageBox.Show("Fil: " + filename + " er i brug af et andet program", "File " + filename + " IO error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(-fileNum); } sw.Stop(); Console.WriteLine("TryCollectData {0} at time: {1}", filename, sw.Elapsed); return(0); }
public static EvalueStorage CollectData(string filename) { EvalueStorage EvalueStore = new EvalueStorage(filename); string[] dataLines = File.ReadAllLines(filename); for (int i = 0; i < dataLines.Count(); i++) { string dataLine = dataLines[i]; T Evalue = new T(); Evalue.Init(dataLine); EvalueStore.PutProperty(Evalue); } return(EvalueStore); }
// Apply filters for a regular file public EvalueStorage ApplyFilters(List <Evalue> evalueList) { IEnumerable <Evalue> filteredList = evalueList; filteredList = ErIUdbudFilter(filteredList); filteredList = YearFilter(filteredList); filteredList = KomNrFilter(filteredList); filteredList = EjdNrFilter(filteredList); filteredList = HandelsprisFilter(filteredList); filteredList = EvalueFilter(filteredList); // Create the storage class EvalueStorage filteredStorage = new EvalueStorage(); // Fill it foreach (Evalue prop in filteredList) { filteredStorage.PutProperty(prop); } return(filteredStorage); }
public static string BuildOutputString(EvalueStorage firstFile, EvalueStorage secondFile) { // Just get the header from a new instance string output = new T().Header(); Random rand = new Random(); List <int> randoms = new List <int>(); int i = 0; // randoms < firstFile and secondFile to make sure we have enough properties to test. while (i < 5 && randoms.Count() < firstFile.Length() && randoms.Count() < secondFile.Length()) { int randIndex = rand.Next(secondFile.Length()); // If we already used this property if (randoms.Contains(randIndex)) { continue; } // we should probably get the second ejendom first, // since this one is filtered Evalue secondEjendom = secondFile.Evalues[randIndex]; Evalue firstEjendom = firstFile.GetProperty( secondEjendom.KomNr, secondEjendom.EjdNr); // If secondFile did not contain the property if (firstEjendom == null) { continue; } output += firstEjendom.ToCsv() + "\n" + secondEjendom.ToCsv() + "\n\n"; randoms.Add(randIndex); i++; } // Only get properties that are "i udbud" List <Evalue> ScndIUdbud = secondFile.Evalues.Where(ejd => ejd.ErIUdbud == 1).ToList(); // Just force it to 5, so we only get 5 where ErIUdbud == 1 if (i != 5) { i = 5; } // i should be 5 at this point, so we get 5 more properties here while (i < 10 && randoms.Count() < ScndIUdbud.Count()) { int randIndex = rand.Next(ScndIUdbud.Count); // If we already used this property we skip it // (we haven't necessarily used it, but chances are, // that this case won't be hit a lot anyway) if (randoms.Contains(randIndex)) { continue; } Evalue Ejendom = ScndIUdbud[randIndex]; output += Ejendom.ToCsv() + "\n"; randoms.Add(randIndex); i++; } return(output); }
private async void BackgroundWorker_DoWorkAsync(object sender, DoWorkEventArgs e) { Task <int> firstFileTask; Task <int> secondFileTask; int error = 0; bool freshRun = true; if (!firstRun) { freshRun = freshRunCheck.Checked || // Even if it's just one file that changed, // We still run fresh just in case. firstFile.Filename != FirstFilename.Text || secondFile.Filename != SecondFilename.Text; } if (RadioBEC.Checked) { Stopwatch sw = new Stopwatch(); sw.Start(); firstFileTask = Task.Run(() => EvalueTest <EvalueBEC> .TryCollectData( FirstFilename.Text, ref firstFile, 1, freshRun)); secondFileTask = Task.Run(() => EvalueTest <EvalueBEC> .TryCollectData( SecondFilename.Text, ref secondFile, 1, freshRun)); error += await firstFileTask; error += await secondFileTask; sw.Stop(); Console.WriteLine("Loading files: {0}", sw.Elapsed); //error += EvalueTest<EvalueBEC>.TryCollectData(FirstFilename.Text, // ref firstFile, 1, freshRun); //error += EvalueTest<EvalueBEC>.TryCollectData(SecondFilename.Text, // ref secondFile, 2, freshRun); } else if (RadioLSB.Checked) { Stopwatch sw = new Stopwatch(); sw.Start(); firstFileTask = Task.Run(() => EvalueTest <EvalueLSB> .TryCollectData( FirstFilename.Text, ref firstFile, 1, freshRun)); secondFileTask = Task.Run(() => EvalueTest <EvalueLSB> .TryCollectData( SecondFilename.Text, ref secondFile, 1, freshRun)); error += await firstFileTask; error += await secondFileTask; sw.Stop(); Console.WriteLine("Loading files: {0}", sw.Elapsed); //error += EvalueTest<EvalueLSB>.TryCollectData(FirstFilename.Text, // ref firstFile, 1, freshRun); //error += EvalueTest<EvalueLSB>.TryCollectData(SecondFilename.Text, // ref secondFile, 2, freshRun); } if (error == 0) { Stopwatch sw = new Stopwatch(); sw.Start(); EvalueStorage filterSecondFile = filterForm.Filter.ApplyFilters(secondFile.Evalues); sw.Stop(); Console.WriteLine("Filter file: {0}", sw.Elapsed); if (StatCheck.Checked || GraphCheck.Checked) { sw = new Stopwatch(); sw.Start(); Statistic stat = new Statistic(firstFile, filterSecondFile); List <StatisticProperty> statList = stat.BuildStats(); List <StatisticProperty> filteredStats = filterForm.Filter.ApplyFilters(statList); var statBuilder = Task.Run(() => TaskStat(stat, filteredStats)); var graphBuilder = Task.Run(() => TaskGraph(filteredStats)); // These two will be 0 on success and -1 if the stats or graph // wasn't created. It does not really seem relevant to check for now. int statRes = await statBuilder; int graphRes = await graphBuilder; sw.Stop(); Console.WriteLine("Stat and Graph: {0}", sw.Elapsed); } if (TestCheck.Checked) { sw = new Stopwatch(); sw.Start(); string output = "Linjeantal fil 1;" + firstFile.Length() + "\nLinjeantal fil 2;" + secondFile.Length() + "\n\n"; if (RadioLSB.Checked) { output += EvalueTest <EvalueLSB> .BuildOutputString( firstFile, filterSecondFile); } else { output += EvalueTest <EvalueBEC> .BuildOutputString( firstFile, filterSecondFile); } File.WriteAllText(OutputFilename.Text, output); Process.Start(OutputFilename.Text); sw.Stop(); Console.WriteLine("Test fil: {0}", sw.Elapsed); } MessageBox.Show("Filen blev lavet", "File created successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Invoke((MethodInvoker) delegate { FormPanel.Enabled = true; freshRunCheck.Visible = true; }); firstRun = false; }
public Statistic(EvalueStorage firstFile, EvalueStorage secondFile) { FirstFile = firstFile; SecondFile = secondFile; }