private void btnConvert_Click(object sender, EventArgs e) { if ((bgwConvert != null) && (bgwConvert.IsBusy)) { bgwConvert.CancelAsync(); return; } DoWorkEventHandler bgwConvert_DoWorkHandler = delegate(object currBGWsender, DoWorkEventArgs args) { BackgroundWorker selfWorker = currBGWsender as BackgroundWorker; DirectoryInfo dInfo = new DirectoryInfo(strLogFilesDirectory); FileInfo[] fInfoArr = dInfo.GetFiles("BcstLog-*.log"); int fInfoCounter = 0; foreach (FileInfo fInfo in fInfoArr) { if (selfWorker.CancellationPending) { break; } // считать данные, запихнуть в один timeseries } // записать данные в файлы }; RunWorkerCompletedEventHandler bgwConvert_CompletedHandler = delegate(object currBGWCompletedSender, RunWorkerCompletedEventArgs args) { ThreadSafeOperations.ToggleButtonState(btnProcessAccelerationTimeSeries, true, "CONVERT", false); }; ProgressChangedEventHandler bgwConvert_ProgressChanged = delegate(object bgwDataReaderSender, ProgressChangedEventArgs args) { ThreadSafeOperations.UpdateProgressBar(prbConvertionProgress, args.ProgressPercentage); }; ThreadSafeOperations.ToggleButtonState(btnConvert, true, "STOP", true); bgwConvert = new BackgroundWorker(); bgwConvert.WorkerSupportsCancellation = true; bgwConvert.WorkerReportsProgress = true; bgwConvert.DoWork += bgwConvert_DoWorkHandler; bgwConvert.RunWorkerCompleted += bgwConvert_CompletedHandler; bgwConvert.ProgressChanged += bgwConvert_ProgressChanged; //object[] bgwCalculateArgs = new object[] { imagesRepresentingForm }; object[] bgwConvertArgs = new object[] { }; bgwConvert.RunWorkerAsync(bgwConvertArgs); }
private void bgwCopier_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { theLogWindow = ServiceTools.LogAText(theLogWindow, "ERROR has been caught: " + Environment.NewLine + e.Error.Message + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, "ERROR has been caught: " + Environment.NewLine, true); //ThreadSafeOperations.SetTextTB(tbLog, e.Error.Message + Environment.NewLine, true); } //ThreadSafeOperations.SetTextTB(tbLog, "#007" + Environment.NewLine, true); ThreadSafeOperations.UpdateProgressBar(prbUniversalProgress, 0); theLogWindow = ServiceTools.LogAText(theLogWindow, "Finished work" + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, "Finished work" + Environment.NewLine, true); ThreadSafeOperations.ToggleButtonState(btnDoWork, true, "SELECT", false); }
// private List<bool> bgwFinished = new List<bool>(); public void CollectPositioningData() { #if DEBUG int concurrentFilesProcessingCount = 1; #else int concurrentFilesProcessingCount = 2; try { concurrentFilesProcessingCount = Convert.ToInt32(defaultProperties["MaxConcurrentFilesProcessingCount"]); } catch (Exception ex) { theLogWindow = ServiceTools.LogAText(theLogWindow, "ERROR! exception thrown: " + ex.Message + Environment.NewLine + "MaxConcurrentFilesProcessingCount value can`t be read. " + Environment.NewLine + "Using default value = " + concurrentFilesProcessingCount); } #endif theLogWindow = ServiceTools.LogAText(theLogWindow, "started on " + DateTime.UtcNow.ToString("s")); string strImagesDir = ParentForm.richTextBox1.Text; DirectoryInfo imagesDir = new DirectoryInfo(strImagesDir); if (!imagesDir.Exists) { theLogWindow = ServiceTools.LogAText(theLogWindow, "Операция не выполнена. Не найдена директория:" + Environment.NewLine + strImagesDir + Environment.NewLine, true); return; } // оказалось, что маска - case-insensitive lImagesFileInfos = new List <FileInfo>(imagesDir.GetFiles("*.jpg", SearchOption.TopDirectoryOnly)); List <FileInfo> lImagesFileInfoWithExistingSunDiskInfo = lImagesFileInfos.ConvertAll <FileInfo>(fInfoSrc => { string sunDiskInfoFileName = fInfoSrc.DirectoryName + "\\" + Path.GetFileNameWithoutExtension(fInfoSrc.FullName) + "-SunDiskInfo.xml"; if (File.Exists(sunDiskInfoFileName)) { return(fInfoSrc); } else { return(null); } }); lImagesFileInfoWithExistingSunDiskInfo.RemoveAll(fInfo => fInfo == null); theLogWindow = ServiceTools.LogAText(theLogWindow, "files already processed before: " + lImagesFileInfoWithExistingSunDiskInfo.Count); lImagesFileInfos.RemoveAll(fInfo => lImagesFileInfoWithExistingSunDiskInfo.Contains(fInfo)); int filesCountToProcess = lImagesFileInfos.Count; int filesCountAlreadyProcessed = lImagesFileInfoWithExistingSunDiskInfo.Count; lImagesFileInfos.AddRange(lImagesFileInfoWithExistingSunDiskInfo); //List<BackgroundWorker> bgwList = new List<BackgroundWorker>(); //for (int i = 0; i < 2; i++) //{ // //bgwFinished.Add(true); // //bgwList.Add(null); //} int currDataIdx = 1; foreach (FileInfo finfo in lImagesFileInfos) { //int currentBgwID = -1; while ((cbgBgwList.Count >= concurrentFilesProcessingCount) && (!hasToStopCollecting)) { Application.DoEvents(); Thread.Sleep(0); } //while ((bgwFinished.Sum(boolVal => (boolVal) ? ((int)0) : ((int)1)) == bgwFinished.Count) && (!hasToStopCollecting)) //{ // Application.DoEvents(); // Thread.Sleep(0); //} if (hasToStopCollecting) { break; } //for (int i = 0; i < concurrentFilesProcessingCount; i++) //{ theLogWindow = ServiceTools.LogAText(theLogWindow, "" + currDataIdx + " / " + filesCountToProcess + " (+ " + filesCountAlreadyProcessed + " processed before)"); theLogWindow = ServiceTools.LogAText(theLogWindow, Environment.NewLine + "starting: " + finfo.Name); //object[] BGWorker2Args = new object[] { finfo, defaultProperties, currentBgwID }; object[] BGWorker2Args = new object[] { finfo, defaultProperties }; BackgroundWorker currBgw = new BackgroundWorker(); // bgwList[currentBgwID] = currBgw; currBgw.DoWork += currBgw_DoWork; currBgw.RunWorkerCompleted += currBgw_RunWorkerCompleted; currBgw.RunWorkerAsync(BGWorker2Args); cbgBgwList.Add(finfo.FullName); if (filesCountToProcess > 0) { int progress = Convert.ToInt32(100.0d * (double)currDataIdx / (double)filesCountToProcess); ThreadSafeOperations.UpdateProgressBar(ParentForm.pbUniversalProgressBar, progress); Interlocked.Increment(ref currDataIdx); } } while (cbgBgwList.Count > 0) { Application.DoEvents(); Thread.Sleep(0); } if (hasToStopCollecting) { return; } // сохраним на будущее string strMedianPerc5StatsXMLFileName = (string)defaultProperties["DefaultMedianPerc5StatsXMLFile"]; FileInfo MedianPerc5StatsXMLFileInfo = new FileInfo(strMedianPerc5StatsXMLFileName); string strMedianPerc5StatsXMLFilePath = MedianPerc5StatsXMLFileInfo.DirectoryName; strMedianPerc5StatsXMLFilePath += (strMedianPerc5StatsXMLFilePath.Last() == '\\') ? ("") : ("\\"); string computedDeviationsXMLfilesPath = strMedianPerc5StatsXMLFilePath + "azimuth-dev-stats\\"; if (!ServiceTools.CheckIfDirectoryExists(computedDeviationsXMLfilesPath)) { theLogWindow = ServiceTools.LogAText(theLogWindow, "couldn`t locate or create directory " + computedDeviationsXMLfilesPath); return; } string computedAzimuthDeviationsXMLFile = computedDeviationsXMLfilesPath + "PreComputedSunAnglesDeviationsData.xml"; List <AngleSunDeviationCalcResult> lResList = new List <AngleSunDeviationCalcResult>(cbAnglesSunDeviationCalcResults); ServiceTools.WriteObjectToXML(lResList, computedAzimuthDeviationsXMLFile); ServiceTools.WriteDictionaryToXml(defaultProperties, defaultPropertiesXMLfileName, false); // теперь посчитаем статистику List <AngleSunDeviationCalcResult> azimuthResults = new List <AngleSunDeviationCalcResult>(lResList); List <AngleSunDeviationCalcResult> zenithResults = new List <AngleSunDeviationCalcResult>(lResList); azimuthResults.RemoveAll( azimuthSunDeviationCalcResult => ((!azimuthSunDeviationCalcResult.calculationSucceeded) || (!azimuthSunDeviationCalcResult.AzimuthDeviationCanBeComputed))); zenithResults.RemoveAll( sunDeviationCalcResult => ((!sunDeviationCalcResult.calculationSucceeded) || (!sunDeviationCalcResult.ZenithDeviationCanBeComputed))); List <double> azimuthDevValues = azimuthResults.ConvertAll <double>( azimuthSunDeviationCalcResult => azimuthSunDeviationCalcResult.computedAzimuthDeviationDeg); List <double> zenithDevValues = zenithResults.ConvertAll <double>( azimuthSunDeviationCalcResult => azimuthSunDeviationCalcResult.computedZenithDeviationDeg); ServiceTools.ExecMethodInSeparateThread(ParentForm, delegate() { HistogramDataAndProperties histAzimuthData = new HistogramDataAndProperties(DenseVector.OfEnumerable(azimuthDevValues), 100); HistogramCalcAndShowForm hAzimuthForm = new HistogramCalcAndShowForm("azimuth sun angle deviations (deg.)", defaultProperties); hAzimuthForm.HistToRepresent = histAzimuthData; hAzimuthForm.Show(); hAzimuthForm.Represent(); }); ServiceTools.ExecMethodInSeparateThread(ParentForm, delegate() { HistogramDataAndProperties histZenithData = new HistogramDataAndProperties(DenseVector.OfEnumerable(zenithDevValues), 100); HistogramCalcAndShowForm hZenithForm = new HistogramCalcAndShowForm("zenith sun angle deviations (deg.)", defaultProperties); hZenithForm.HistToRepresent = histZenithData; hZenithForm.Show(); hZenithForm.Represent(); }); ThreadSafeOperations.UpdateProgressBar(ParentForm.pbUniversalProgressBar, 0); }
private void btnPerformExport_Click(object sender, EventArgs e) { string outPath = rtbExportDestinationDirectoryPath.Text; outPath += (outPath.Last() == '\\') ? ("") : ("\\"); if (cbExportMeteoData.Checked) { //export meteo data BackgroundWorker bgwReadMeteoData = new BackgroundWorker(); bgwReadMeteoData.WorkerSupportsCancellation = false; bgwReadMeteoData.WorkerReportsProgress = true; bgwReadMeteoData.DoWork += delegate(object currBGWsender, DoWorkEventArgs args) { BackgroundWorker selfWorker = currBGWsender as BackgroundWorker; TimeSeries <MeteoData> tsMeteoData = new TimeSeries <MeteoData>(); string[] meteoDataFiles = Directory.GetFiles(Directory.GetCurrentDirectory() + "\\logs\\", "*MeteoDataLog*.nc"); int totalFilesCount = meteoDataFiles.Count(); int readFiles = 0; foreach (string meteoDataFileName in meteoDataFiles) { ThreadSafeOperations.SetText(lblStatusBar, "reading " + Path.GetFileName(meteoDataFileName), false); Dictionary <string, object> currMeteoFileData = NetCDFoperations.ReadDataFromFile(meteoDataFileName); List <MeteoData> currFileMeteoData = MeteoData.OfDenseMatrix(currMeteoFileData["MeteoData"] as DenseMatrix); List <long> currFileDatetimeLong = new List <long>(currMeteoFileData["DateTime"] as long[]); List <DateTime> currFileDatetime = currFileDatetimeLong.ConvertAll <DateTime>(longDT => new DateTime(longDT)); tsMeteoData.AddSubseriaData(currFileMeteoData, currFileDatetime, true); readFiles++; selfWorker.ReportProgress(Convert.ToInt32(100.0d * readFiles / totalFilesCount)); } args.Result = new object[] { tsMeteoData }; }; bgwReadMeteoData.ProgressChanged += delegate(object currBGWsender, ProgressChangedEventArgs args) { ThreadSafeOperations.UpdateProgressBar(prbExportProgress, args.ProgressPercentage); }; bgwReadMeteoData.RunWorkerCompleted += delegate(object currBGWsender, RunWorkerCompletedEventArgs args) { ThreadSafeOperations.UpdateProgressBar(prbExportProgress, 0); TimeSeries <MeteoData> tsMeteoData = (args.Result as object[])[0] as TimeSeries <MeteoData>; List <Tuple <DateTime, MeteoData> > lTplMeteoData = tsMeteoData.TimeStamps.Zip(tsMeteoData.DataValues, (dt, dat) => new Tuple <DateTime, MeteoData>(dt, dat)).ToList(); if (cbExportFormatCSV.Checked) { List <string> tsMeteoDataCSV = lTplMeteoData.ConvertAll <string>(tpl => tpl.Item1.ToString("o") + "," + tpl.Item2.ToCSV()); string tsMeteoDataCSVForFile = String.Join(Environment.NewLine, tsMeteoDataCSV.ToArray <string>()); ServiceTools.logToTextFile(outPath + "MeteoData.csv", "DateTime," + lTplMeteoData[0].Item2.CSVHeader() + Environment.NewLine, false, false); ServiceTools.logToTextFile(outPath + "MeteoData.csv", tsMeteoDataCSVForFile, true, false); } }; ThreadSafeOperations.SetText(lblStatusBar, "meteo data read started", false); bgwReadMeteoData.RunWorkerAsync(); } }
private void btnProcessAccelerationTimeSeries_Click(object sender, EventArgs e) { if ((bgwCalculate != null) && (bgwCalculate.IsBusy)) { bgwCalculate.CancelAsync(); return; } //simpleMultipleImagesShow imagesRepresentingForm = new simpleMultipleImagesShow(); //imagesRepresentingForm.Show(); DoWorkEventHandler bgwCalculate_DoWorkHandler = delegate(object currBGWsender, DoWorkEventArgs args) { BackgroundWorker selfWorker = currBGWsender as BackgroundWorker; //simpleMultipleImagesShow multImagesRepresentingForm = (simpleMultipleImagesShow)((args.Argument as object[])[0]); //Type theShowImagesType = multImagesRepresentingForm.GetType(); //MethodInfo thePicturePlacingMethodInfo = theShowImagesType.GetMethod("PlaceAPicture"); int imageRepresentingCounter = 0; DateTime dbgDT = new DateTime(2014, 7, 9, 9, 0, 0); dbgDT = dbgDT.AddMinutes(33); DateTime dtSeriesStart = accSubseries[0].StartTime; double tsOverallSeriesDurationMillisec = (accSubseries[accSubseries.Count - 1].EndTime - accSubseries[0].StartTime).TotalMilliseconds; string strToWrite = " fileName ; lat ; lon ; date ; time ; time(s) since start ; period(s) ; spectrum amplitude"; ServiceTools.logToTextFile(strOutputDirectory + "\\100sData-spectra-maximums.dat", strToWrite + Environment.NewLine, true); foreach (TimeSeries <double> accSubseria in accSubseries) { if (selfWorker.CancellationPending) { break; } int startindex = 0; while (true) { int endIndex; if (selfWorker.CancellationPending) { break; } TimeSeries <double> currTimeSeria = accSubseria.SubSeria(startindex, new TimeSpan(1000000000), out endIndex); //100s currTimeSeria = currTimeSeria.InterpolateSeria(new TimeSpan(500000)); currTimeSeria = currTimeSeria.ExtractDataDeviationValues(); //обработать и оценить наличие выраженных периодов Complex[] sourceSignalArray = currTimeSeria.DataRealValuesComplexArray(); Fourier.Forward(sourceSignalArray); //Transform.FourierForward(sourceSignalArray); List <Complex> FourierTransformedSignal = new List <Complex>(sourceSignalArray); List <double> FourierTransformedSignalAmplitudes = FourierTransformedSignal.ConvertAll <double>( cVal => ((double.IsNaN(cVal.Magnitude)) || (double.IsInfinity(cVal.Magnitude))) ? (0.0d) : (cVal.Magnitude)); List <double> FourierTransformedSignalPeriods = new List <double>(); for (int ind = 0; ind < FourierTransformedSignalAmplitudes.Count; ind++) { FourierTransformedSignalPeriods.Add(currTimeSeria.TotalSeriaDuration.TotalSeconds / (double)ind); } FourierTransformedSignalAmplitudes = new List <double>( FourierTransformedSignalAmplitudes.Zip <double, double, double>( FourierTransformedSignalPeriods, (amp, periodSec) => ((double.IsNaN(periodSec)) || (double.IsInfinity(periodSec))) ? (0.0d) : (amp))); FourierTransformedSignalPeriods = FourierTransformedSignalPeriods.ConvertAll <double>( dval => ((double.IsNaN(dval)) || (double.IsInfinity(dval))) ? (0.0d) : (dval)); //проанализируем этот участок - есть ли выраженные пики по амплитуде конкретных частот //найти максимум в спектре и выдать данные об этом максимуме в файл // сначала отфильтруем периоды меньше 1с - для данных по динамике судна они несущественны FourierTransformedSignalAmplitudes = new List <double>( FourierTransformedSignalAmplitudes.Zip <double, double, double>( FourierTransformedSignalPeriods, (amp, periodSec) => (periodSec <= 1.0d) ? (0.0d) : (amp))); FourierTransformedSignalPeriods = FourierTransformedSignalPeriods.ConvertAll <double>(dVal => (dVal <= 1.0d) ? (0.0d) : (dVal)); DescriptiveStatistics currAmpsStat = new DescriptiveStatistics(FourierTransformedSignalAmplitudes); List <double> lAmpsOutstanding = FourierTransformedSignalAmplitudes.ConvertAll <double>(dVal => { if (dVal / currAmpsStat.Mean >= 100.0d) { return(dVal); } return(0.0d); }); List <double> lPeriodsOutstanding = new List <double>(FourierTransformedSignalPeriods.Zip <double, double, double>(lAmpsOutstanding, (per, amp) => (amp == 0.0d) ? (0.0d) : (per))); if (lAmpsOutstanding.Sum() > 0.0d) { MultipleScatterAndFunctionsRepresentation renderer = new MultipleScatterAndFunctionsRepresentation(2048, 1536); renderer.dvScatterXSpace.Add(currTimeSeria.TimeStampsValuesSeconds); renderer.dvScatterFuncValues.Add(currTimeSeria.dvDoubleDataValues); renderer.scatterLineColors.Add(new Bgr(255, 50, 50)); renderer.scatterDrawingVariants.Add(SequencesDrawingVariants.polyline); renderer.dvScatterXSpace.Add(DenseVector.OfEnumerable(FourierTransformedSignalPeriods)); renderer.dvScatterFuncValues.Add(DenseVector.OfEnumerable(FourierTransformedSignalAmplitudes)); renderer.scatterLineColors.Add(new Bgr(50, 255, 50)); renderer.scatterDrawingVariants.Add(SequencesDrawingVariants.squares); renderer.dvScatterXSpace.Add(DenseVector.OfEnumerable(lPeriodsOutstanding)); renderer.dvScatterFuncValues.Add(DenseVector.OfEnumerable(lAmpsOutstanding)); renderer.scatterLineColors.Add(new Bgr(50, 50, 255)); renderer.scatterDrawingVariants.Add(SequencesDrawingVariants.circles); renderer.Represent(); if (strOutputDirectory != "") { double maxAmp = lAmpsOutstanding.Max(); int idx = lAmpsOutstanding.FindIndex(dval => dval == maxAmp); double maxAmpPeriod = lPeriodsOutstanding[idx]; GPSdata gpsMark = gpsSeriaData.GetMostClose(currTimeSeria.StartTime).Item2; string fName = currTimeSeria.StartTime.ToString("s").Replace(":", "-") + "-100sData-spectrum.jpg"; renderer.SaveToImage(strOutputDirectory + "\\" + fName, true); strToWrite = "" + fName + " ; "; strToWrite += gpsMark.LatDec + " ; "; strToWrite += gpsMark.LonDec + " ; "; strToWrite += currTimeSeria.StartTime.Date.ToString("yyyy-MM-dd") + " ; "; strToWrite += currTimeSeria.StartTime.ToString("HH-mm-ss") + " ; "; strToWrite += (currTimeSeria.StartTime - dtSeriesStart).TotalSeconds + " ; "; strToWrite += maxAmpPeriod.ToString() + " ; "; strToWrite += maxAmp.ToString() + " ; "; ServiceTools.logToTextFile(strOutputDirectory + "\\100sData-spectra-maximums.dat", strToWrite + Environment.NewLine, true); ThreadSafeOperations.SetText(lblStatusString, "processing: " + currTimeSeria.StartTime.ToString("s"), false); } } if ((currTimeSeria.StartTime >= dbgDT) || (currTimeSeria.EndTime >= dbgDT)) { startindex++; startindex--; } if (endIndex == accSubseria.Count - 1) { break; } Application.DoEvents(); selfWorker.ReportProgress(Convert.ToInt32(100.0d * (currTimeSeria.EndTime - dtSeriesStart).TotalMilliseconds / tsOverallSeriesDurationMillisec)); startindex += Convert.ToInt32((endIndex - startindex) / 2.0d); } } }; RunWorkerCompletedEventHandler bgwCalculate_CompletedHandler = delegate(object currBGWCompletedSender, RunWorkerCompletedEventArgs args) { ThreadSafeOperations.ToggleButtonState(btnProcessAccelerationTimeSeries, true, "Process acceleration timeseries", false); }; ProgressChangedEventHandler bgwCalculate_ProgressChanged = delegate(object bgwDataReaderSender, ProgressChangedEventArgs args) { ThreadSafeOperations.UpdateProgressBar(prbReadingProcessingData, args.ProgressPercentage); }; ThreadSafeOperations.ToggleButtonState(btnProcessAccelerationTimeSeries, true, "STOP", true); bgwCalculate = new BackgroundWorker(); bgwCalculate.WorkerSupportsCancellation = true; bgwCalculate.WorkerReportsProgress = true; bgwCalculate.DoWork += bgwCalculate_DoWorkHandler; bgwCalculate.RunWorkerCompleted += bgwCalculate_CompletedHandler; bgwCalculate.ProgressChanged += bgwCalculate_ProgressChanged; //object[] bgwCalculateArgs = new object[] { imagesRepresentingForm }; object[] bgwCalculateArgs = new object[] { }; bgwCalculate.RunWorkerAsync(bgwCalculateArgs); }
private void btnReadData_Click(object sender, EventArgs e) { strLogFilesDirectory = tbLogFilesPath.Text; if (bgwDataReader != null && bgwDataReader.IsBusy) { bgwDataReader.CancelAsync(); return; } ThreadSafeOperations.ToggleButtonState(btnReadData, true, "CANCEL", true); DoWorkEventHandler currDoWorkHandler = delegate(object currBGWsender, DoWorkEventArgs args) { BackgroundWorker selfworker = currBGWsender as BackgroundWorker; List <double> lTotalDataToAdd = new List <double>(); List <DateTime> lDateTimeList = new List <DateTime>(); DirectoryInfo dInfo = new DirectoryInfo(strLogFilesDirectory); FileInfo[] fInfoArr = dInfo.GetFiles("*AccelerometerDataLog*.nc"); int fInfoCounter = 0; foreach (FileInfo fInfo in fInfoArr) { if (selfworker.CancellationPending) { break; } fInfoCounter++; selfworker.ReportProgress(Convert.ToInt32((double)(fInfoCounter - 1) / (double)fInfoArr.Length)); ThreadSafeOperations.SetText(lblStatusString, "reading " + fInfo.FullName, false); Dictionary <string, object> dictDataLoaded = NetCDFoperations.ReadDataFromFile(fInfo.FullName); string varNameDateTime = "DateTime"; if (dictDataLoaded.Keys.Contains("DateTime")) { varNameDateTime = "DateTime"; } else if (dictDataLoaded.Keys.Contains("Datetime")) { varNameDateTime = "Datetime"; } List <long> currFileDateTimeLongTicksList = new List <long>((dictDataLoaded[varNameDateTime] as long[])); List <DateTime> currFileDateTimeList = currFileDateTimeLongTicksList.ConvertAll(longVal => new DateTime(longVal)); string varNameAccData = "AccelerometerData"; List <AccelerometerData> lAccData = AccelerometerData.OfDenseMatrix(dictDataLoaded[varNameAccData] as DenseMatrix); List <double> lAccDataToAdd = lAccData.ConvertAll <double>(acc => acc.AccMagnitude); lTotalDataToAdd.AddRange(lAccDataToAdd); lDateTimeList.AddRange(currFileDateTimeList); selfworker.ReportProgress(Convert.ToInt32((double)(fInfoCounter) / (double)fInfoArr.Length)); } accSeriaData.AddSubseriaData(lTotalDataToAdd, lDateTimeList); //теперь обработаем считанные данные ThreadSafeOperations.SetText(lblStatusString, "basic acceleration data processing...", false); accSubseries = accSeriaData.SplitWithTimeSpanCondition(dt => dt.TotalMilliseconds >= 1200); accSubseries.RemoveAll(theSeria => theSeria.TotalSeriaDuration.TotalSeconds < 100); List <double> listSeriesStats = accSubseries.ConvertAll(timeseria => timeseria.TotalSeriaDuration.TotalSeconds); DescriptiveStatistics stats = new DescriptiveStatistics(listSeriesStats); string strToShow = "Acceleration data start time: " + accSubseries[0].StartTime.ToString("s") + Environment.NewLine; strToShow += "Acceleration data end time: " + accSubseries[accSubseries.Count - 1].EndTime.ToString("s") + Environment.NewLine; strToShow += "total chunks count: " + accSubseries.Count + Environment.NewLine; strToShow += "mean chunk duration: " + stats.Mean.ToString("0.##e-00") + " s" + Environment.NewLine; strToShow += "min chunk duration: " + stats.Minimum.ToString("0.##e-00") + " s" + Environment.NewLine; strToShow += "max chunk duration: " + stats.Maximum.ToString("0.##e-00") + " s" + Environment.NewLine; strToShow += "StdDev of chunk duration: " + stats.StandardDeviation.ToString("0.##e-00") + " s" + Environment.NewLine; ThreadSafeOperations.SetTextTB(tbReportLog, strToShow, true); List <GPSdata> lTotalGPSDataToAdd = new List <GPSdata>(); List <DateTime> lGPSDateTimeList = new List <DateTime>(); dInfo = new DirectoryInfo(strLogFilesDirectory); fInfoArr = dInfo.GetFiles("*GPSDataLog*.nc"); fInfoCounter = 0; foreach (FileInfo fInfo in fInfoArr) { if (selfworker.CancellationPending) { break; } fInfoCounter++; selfworker.ReportProgress(Convert.ToInt32((double)(fInfoCounter - 1) / (double)fInfoArr.Length)); ThreadSafeOperations.SetText(lblStatusString, "reading " + fInfo.FullName, false); Dictionary <string, object> dictDataLoaded = NetCDFoperations.ReadDataFromFile(fInfo.FullName); string varNameDateTime = "DateTime"; if (dictDataLoaded.Keys.Contains("DateTime")) { varNameDateTime = "DateTime"; } else if (dictDataLoaded.Keys.Contains("Datetime")) { varNameDateTime = "Datetime"; } List <long> currFileDateTimeLongTicksList = new List <long>((dictDataLoaded[varNameDateTime] as long[])); List <DateTime> currFileDateTimeList = currFileDateTimeLongTicksList.ConvertAll(longVal => new DateTime(longVal)); string varNameGPSData = "GPSdata"; List <GPSdata> lGPSData = GPSdata.OfDenseMatrix(dictDataLoaded[varNameGPSData] as DenseMatrix); //List<double> lGPSDataToAdd = lGPSData.ConvertAll<double>(acc => acc.AccMagnitude); lTotalGPSDataToAdd.AddRange(lGPSData); lGPSDateTimeList.AddRange(currFileDateTimeList); selfworker.ReportProgress(Convert.ToInt32((double)(fInfoCounter) / (double)fInfoArr.Length)); } gpsSeriaData.AddSubseriaData(lTotalGPSDataToAdd, lGPSDateTimeList); //теперь обработаем считанные данные ThreadSafeOperations.SetText(lblStatusString, "basic GPS data processing...", false); gpsSeriaData.RemoveValues(gpsDatum => ((gpsDatum.lat == 0.0d) && (gpsDatum.lon == 0.0d))); gpsSeriaData.RemoveDuplicatedTimeStamps(); strToShow = Environment.NewLine + "GPS data start time: " + gpsSeriaData.StartTime.ToString("s") + Environment.NewLine; strToShow += "GPS data end time: " + gpsSeriaData.EndTime.ToString("s") + Environment.NewLine; ThreadSafeOperations.SetTextTB(tbReportLog, strToShow, true); }; RunWorkerCompletedEventHandler currWorkCompletedHandler = delegate(object currBGWCompletedSender, RunWorkerCompletedEventArgs args) { ThreadSafeOperations.ToggleButtonState(btnReadData, true, "Read data", true); }; ProgressChangedEventHandler bgwDataReader_ProgressChanged = delegate(object bgwDataReaderSender, ProgressChangedEventArgs args) { ThreadSafeOperations.UpdateProgressBar(prbReadingProcessingData, args.ProgressPercentage); }; bgwDataReader = new BackgroundWorker(); bgwDataReader.WorkerSupportsCancellation = true; bgwDataReader.WorkerReportsProgress = true; bgwDataReader.DoWork += currDoWorkHandler; bgwDataReader.RunWorkerCompleted += currWorkCompletedHandler; bgwDataReader.ProgressChanged += bgwDataReader_ProgressChanged; object[] BGWargs = new object[] { "", "" }; bgwDataReader.RunWorkerAsync(BGWargs); }
private void BgwSnapshotsFilteringWithSunElevation_ProgressChanged(object sender, ProgressChangedEventArgs e) { ThreadSafeOperations.UpdateProgressBar(prbUniversalProgress, e.ProgressPercentage * 10); }
private void bgwCopier_ProgressChanged(object sender, ProgressChangedEventArgs e) { ThreadSafeOperations.UpdateProgressBar(prbUniversalProgress, e.ProgressPercentage); }