private string ReadLastConcurrentInfo() { DirectoryInfo dir = new DirectoryInfo(DataStoreDirectory); List <FileInfo> lXMLFilesInfo = dir.GetFiles(ConventionalTransitions.ImageConcurrentDataFilesNamesPattern(), SearchOption.AllDirectories) .ToList(); lXMLFilesInfo.Sort((finfo1, finfo2) => finfo1.CreationTimeUtc.CompareTo(finfo2.CreationTimeUtc)); Dictionary <string, object> dictReadXMLfileData = ServiceTools.ReadDictionaryFromXML(lXMLFilesInfo.Last().FullName); DateTime utcNow = DateTime.UtcNow; DateTime concurrentDataDateTime = DateTime.Parse(dictReadXMLfileData["DateTime"] as string); concurrentDataDateTime = concurrentDataDateTime.ToUniversalTime(); string strDataToReport = "Current server date/time UTC: " + utcNow.ToString("dd.MM.yyyy HH:mm:ss") + Environment.NewLine; strDataToReport += "Concurrent data date/time UTC: " + concurrentDataDateTime.ToString("dd.MM.yyyy HH:mm:ss") + Environment.NewLine; strDataToReport += "time elapsed since last shot: " + Math.Round((utcNow - concurrentDataDateTime).TotalSeconds) + "s" + Environment.NewLine; GPSdata gps = new GPSdata((string)dictReadXMLfileData["GPSdata"], GPSdatasources.CloudCamArduinoGPS, concurrentDataDateTime); strDataToReport += "GPS: " + gps.HRString(2) + Environment.NewLine; SPA spaCalcObject = null; AzimuthZenithAngle angle = gps.SunZenithAzimuth(out spaCalcObject); DateTime dtSunriseUTC = utcNow; TimeOfDay todSunriseUTC = new TimeOfDay(spaCalcObject.spa.sunrise); dtSunriseUTC = new DateTime(dtSunriseUTC.Year, dtSunriseUTC.Month, dtSunriseUTC.Day, todSunriseUTC.hour, todSunriseUTC.minute, todSunriseUTC.second, DateTimeKind.Utc); // TimeZoneInfo mowTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time"); TimeZoneInfo mowTimeZone = TimeZoneInfo.Local; DateTime dtSunriseMOW = TimeZoneInfo.ConvertTimeFromUtc(dtSunriseUTC, mowTimeZone); strDataToReport += "Sunrise Moscow time: " + (dtSunriseMOW.TimeOfDay.ToString()) + Environment.NewLine; DateTime dtSunsetUTC = utcNow; TimeOfDay todSunsetUTC = new TimeOfDay(spaCalcObject.spa.sunset); dtSunsetUTC = new DateTime(dtSunsetUTC.Year, dtSunsetUTC.Month, dtSunsetUTC.Day, todSunsetUTC.hour, todSunsetUTC.minute, todSunsetUTC.second, DateTimeKind.Utc); DateTime dtSunsetMOW = TimeZoneInfo.ConvertTimeFromUtc(dtSunsetUTC, mowTimeZone); strDataToReport += "Sunset Moscow time: " + (dtSunsetMOW.TimeOfDay.ToString()) + Environment.NewLine; return(strDataToReport); }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); string CurDir = Directory.GetCurrentDirectory(); string defaultPropertiesXMLfileName = CurDir + "\\settings\\GPSdataCorrectorSettings.xml"; if (!File.Exists(defaultPropertiesXMLfileName)) { return; } defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); rtbPath.Text = (string)defaultProperties["InputDataFilesDirectory"]; rtbVesselNavDataDirectoryPath.Text = (string)defaultProperties["VesselMeteoNavDataPath"]; }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (!File.Exists(defaultPropertiesXMLfileName)) { return; } defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); bool bDefaultPropertiesHasBeenUpdated = false; string CurDir = Directory.GetCurrentDirectory(); currPath2Process = ""; if (defaultProperties.ContainsKey("ImagesBasePath")) { currPath2Process = (string)defaultProperties["ImagesBasePath"]; } else { currPath2Process = CurDir; } if (defaultProperties.ContainsKey("OutputDirectory")) { strOutputDirectory = ((string)defaultProperties["OutputDirectory"]); } else { strOutputDirectory = ""; } if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
//private bool testAnIpAddress(IPAddress testingIPaddr) //{ // bool retVal = false; // Ping ping; // string retStr = "areyouarduino"; // byte[] ret = System.Text.Encoding.ASCII.GetBytes(retStr); // string returnData = ""; // Socket Skt = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); // Skt.EnableBroadcast = false; // Skt.ReceiveTimeout = 10; // Skt.SendTimeout = 10; // //string testingIP = "192.168.192." + i.ToString();//!!!!!!!!!!!!!!!!!!!!!! определить подсеть по текущему IP и маске // //testingIPaddr = IPAddress.Parse(testingIP); // // ping = new Ping(); // PingReply repl = ping.Send(testingIPaddr, 3, new byte[] { 1 }, new PingOptions(1, true)); // // if ((repl.Status == IPStatus.TtlExpired) || (repl.Status == IPStatus.TimedOut) || (repl.Status == IPStatus.TimeExceeded)) // { // returnData = "ping timeout or not reachable"; // retVal = false; // } // else // { // IPEndPoint test = new IPEndPoint(testingIPaddr, 5555); // int sent = Skt.SendTo(ret, test); // // Blocks until a message returns on this socket from a remote host. // Byte[] receiveBytes = new byte[128]; // IPEndPoint sender_ = new IPEndPoint(IPAddress.Any, 0); // EndPoint senderRemote = (EndPoint)sender_; // // try // { // Skt.ReceiveFrom(receiveBytes, ref senderRemote); // returnData = Encoding.UTF8.GetString(receiveBytes).Trim().Replace("\0", string.Empty); // } // catch (Exception ex) // { // returnData = ex.Message; // //throw; // } // } // // SetTextTB(textBox1, "tested ip " + testingIPaddr.ToString() + ": " + returnData.ToString() + Environment.NewLine, true); // Skt.Close(); // if (returnData.ToString() == "YES") retVal = true; else retVal = false; // // return retVal; //} //private void arduinoBoardSearchingWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) //{ // //SetTextTB(textBox1, "Данные датчиков собраны " + e.ProgressPercentage + " раз" + Environment.NewLine, true); // UpdateProgressBar(progressBar1, e.ProgressPercentage); //} private void Form1_Load(object sender, EventArgs e) { string generalSettingsFilename = Directory.GetCurrentDirectory() + "\\settings\\ArduinoUDPconversationAppGeneralSettings2G.xml"; if (!File.Exists(generalSettingsFilename)) { ip2ListenDevID1 = Settings.Default.ArduinoBoardDefaultIP; port2converse = Settings.Default.ArduinoBoardDefaultUDPport; ThreadSafeOperations.SetTextTB(tbDev1IPstr, ip2ListenDevID1, false); } else { Dictionary <string, object> generalSettings = ServiceTools.ReadDictionaryFromXML(generalSettingsFilename); ip2ListenDevID1 = generalSettings["ArduinoBoardID1DefaultIP"] as string; ip2ListenDevID2 = generalSettings["ArduinoBoardID2DefaultIP"] as string; port2converse = Convert.ToInt32(generalSettings["ArduinoBoardDefaultUDPport"]); portBcstRecvng = Convert.ToInt32(generalSettings["UDPBroadcastDefaultListeningPort"]); ThreadSafeOperations.SetTextTB(tbDev1IPstr, ip2ListenDevID1, false); ThreadSafeOperations.SetTextTB(tbDev2IPstr, ip2ListenDevID2, false); } }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (!File.Exists(defaultPropertiesXMLfileName)) { return; } defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); bool bDefaultPropertiesHasBeenUpdated = false; string CurDir = Directory.GetCurrentDirectory(); currPath2Process = ""; if (defaultProperties.ContainsKey("ImagesBasePath")) { currPath2Process = (string)defaultProperties["ImagesBasePath"]; } else { currPath2Process = CurDir; } // SaveControlImagesToPath if (!defaultProperties.ContainsKey("SaveControlImagesToPath")) { defaultProperties.Add("SaveControlImagesToPath", CurDir); bDefaultPropertiesHasBeenUpdated = true; } if (defaultProperties.ContainsKey("OutputDirectory")) { strOutputDirectory = ((string)defaultProperties["OutputDirectory"]); } else { strOutputDirectory = ""; } // maxConcurrentBackgroundWorkers if (defaultProperties.ContainsKey("maxConcurrentBackgroundWorkers")) { maxConcurrentBackgroundWorkers = Convert.ToInt32(defaultProperties["maxConcurrentBackgroundWorkers"]); } else { defaultProperties.Add("maxConcurrentBackgroundWorkers", 8); bDefaultPropertiesHasBeenUpdated = true; //saveDefaultProperties(); } if (defaultProperties.ContainsKey("FilesToProcessMask")) { FilesToProcessMask = ((string)defaultProperties["FilesToProcessMask"]); } else { FilesToProcessMask = currPath2Process + "*.jpg"; defaultProperties.Add("FilesToProcessMask", FilesToProcessMask); bDefaultPropertiesHasBeenUpdated = true; //saveDefaultProperties(); } if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
public void Start(string[] args) { readDefaultProperties(); List <string> argsList = new List <string>(args); if (argsList.Find(str => str == "--recursive") != null) { bEnumerateFilesRecursively = true; } if (argsList.Find(str => str == "-y") != null) { bStartWithoutConfirmation = true; } // --filter-by-observed-cloud-cover-records // bFilterByObservedCloudCoverRecords if (argsList.Find(str => str == "--filter-by-observed-cloud-cover-records") != null) { bFilterByObservedCloudCoverRecords = true; } // sdcFilter if (argsList.Where(str => str.Contains("--sdc=")).Count() > 0) { string foundArg = argsList.Where(str => str.Contains("--sdc=")).ToList()[0]; string strValue = foundArg.Replace("--sdc=", ""); //sdcFilter if (strValue == "none") { sdcFilter = SunDiskCondition.NoSun; } else if (strValue == "0") { sdcFilter = SunDiskCondition.Sun0; } else if (strValue == "1") { sdcFilter = SunDiskCondition.Sun1; } else if (strValue == "2") { sdcFilter = SunDiskCondition.Sun2; } else { sdcFilter = SunDiskCondition.Sun2; } } else { Console.WriteLine("SDC filter is not specified. Filtering by SDC will not applied."); sdcFilter = SunDiskCondition.Undefined; // Не применять фильтрацию } if (argsList.Where(str => str.Contains("--camera-id=")).Count() > 0) { string foundArg = argsList.Where(str => str.Contains("--camera-id=")).ToList()[0]; string strValue = foundArg.Replace("--camera-id=", ""); CamIDtoProcess = Convert.ToInt32(strValue); if ((CamIDtoProcess != 1) && (CamIDtoProcess != 2)) { Console.WriteLine("camera ID out of range detected. I will not filter by camera ID."); CamIDtoProcess = 0; } } else { Console.WriteLine("camera ID out of range detected. I will not filter by camera ID"); CamIDtoProcess = 0; // will not filter } if (!bStartWithoutConfirmation) { Console.Write("Start with the mentioned properties? [y/n] "); string strReply = Console.ReadLine(); if (strReply.ToLower().First() != 'y') { Console.WriteLine("\nWill not proceed due to user interruprion."); Console.WriteLine("===FINISHED==="); Console.ReadKey(); return; } } outputDataFile = strOutputDirectory + Path.GetFileNameWithoutExtension(outputDataFile) + "-" + sdcFilter.ToString() + "-camID" + CamIDtoProcess + ".xml"; string outputCSVfile = strOutputDirectory + Path.GetFileNameWithoutExtension(outputDataFile) + "-" + sdcFilter.ToString() + "-camID" + CamIDtoProcess + ".csv"; Console.WriteLine("getting files list"); #region Enumerating files string directory = Path.GetDirectoryName(inputBasePath); string filemask = "*.jpg"; List <string> filesList = new List <string>(Directory.EnumerateFiles(directory, filemask, bEnumerateFilesRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)); #region filter by camID //...devID1.jpg if (CamIDtoProcess > 0) { string ptrnCamID = "devid" + CamIDtoProcess + ".jpg"; filesList = filesList.Where(fname => fname.ToLower().Contains(ptrnCamID)).ToList(); } #endregion Console.WriteLine("found " + filesList.Count + " images."); #region try to find concurrent and stats data already assembled into a small set of files List <string> assembledDataFilesList = Directory.EnumerateFiles(ConcurrentDataXMLfilesDirectory, "*.xml", SearchOption.TopDirectoryOnly).ToList(); List <ImagesProcessingData> lReadAssembledData = new List <ImagesProcessingData>(); foreach (string strAssembledDataXMlfName in assembledDataFilesList) { try { List <ImagesProcessingData> currFileContent = ServiceTools.ReadObjectFromXML(strAssembledDataXMlfName, typeof(List <ImagesProcessingData>)) as List <ImagesProcessingData>; lReadAssembledData.AddRange(currFileContent); } catch (Exception ex) { continue; } } if (lReadAssembledData.Any()) { Console.WriteLine("Found pre-assembled ImagesProcessingData XML files: "); foreach (string s in assembledDataFilesList) { Console.WriteLine(s); } Console.WriteLine("Read records from this set: " + lReadAssembledData.Count); Console.WriteLine("Images to process originally: " + filesList.Count); Console.WriteLine("Should I use these pre-assembled data? (y/n): "); string ans = Console.ReadKey().KeyChar.ToString(); if (ans == "y") { lStatsProcessing = lReadAssembledData; } } #endregion try to find data already compiled into a small set of files if (!lStatsProcessing.Any()) { #region list, read and map image stats files Console.WriteLine("filtering by ready-to-use GrIxYRGB XML files..."); List <string> statsFilesList = new List <string>(Directory.EnumerateFiles(imageYRGBstatsXMLdataFilesDirectory, ConventionalTransitions.ImageGrIxYRGBstatsFileNamesPattern(), bEnumerateFilesRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)); List <string> statsFilesListWOpath = statsFilesList.ConvertAll(Path.GetFileName); Console.WriteLine("found " + statsFilesList.Count + " XML stats files in directory " + Environment.NewLine + imageYRGBstatsXMLdataFilesDirectory + Environment.NewLine + "by mask " + Environment.NewLine + ConventionalTransitions.ImageGrIxYRGBstatsFileNamesPattern()); int removed = filesList.RemoveAll( fname => !statsFilesListWOpath.Contains(ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(fname, "", false))); Console.WriteLine("removed " + removed + " items (couldn`t find stats data files). Remains " + filesList.Count + " to process."); if (!filesList.Any()) { Console.WriteLine("There is no " + filemask + " files that sutisfy settings specified. Processing will not be started."); return; } lStatsProcessing = filesList.ConvertAll(strImgFname => { ImagesProcessingData retVal = new ImagesProcessingData() { filename = strImgFname }; return(retVal); }); //#if DEBUG // lStatsProcessing = lStatsProcessing.Where((ipd, ind) => ind < 10).ToList(); //#endif Console.WriteLine("started reading and mapping stats data"); int totalFilesCountToRead = lStatsProcessing.Count; int filesRead = 0; int currProgressPerc = 0; foreach (ImagesProcessingData ipdt in lStatsProcessing) { ipdt.grixyrgbStatsXMLfile = statsFilesList.First( statsFname => statsFname.Contains(ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(ipdt.filename, "", false))); ipdt.grixyrgbStats = ServiceTools.ReadObjectFromXML(ipdt.grixyrgbStatsXMLfile, typeof(SkyImageIndexesStatsData)) as SkyImageIndexesStatsData; #region calculate and report progress filesRead++; double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead; if (progress - (double)currProgressPerc > 1.0d) { currProgressPerc = Convert.ToInt32(progress); Console.WriteLine("read " + currProgressPerc + "%"); } #endregion calculate and report progress } #endregion #region list, read and map concurrent data List <ConcurrentData> lConcurrentData = null; List <string> concurrentDataFilesList = Directory.EnumerateFiles(ConcurrentDataXMLfilesDirectory, ConventionalTransitions.ImageConcurrentDataFilesNamesPattern(), bEnumerateFilesRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToList(); #region reading Console.WriteLine("started concurrent data reading"); totalFilesCountToRead = concurrentDataFilesList.Count; filesRead = 0; currProgressPerc = 0; List <Dictionary <string, object> > lDictionariesConcurrentData = new List <Dictionary <string, object> >(); foreach (string strConcDataXMLFile in concurrentDataFilesList) { Dictionary <string, object> currDict = ServiceTools.ReadDictionaryFromXML(strConcDataXMLFile); currDict.Add("XMLfileName", Path.GetFileName(strConcDataXMLFile)); lDictionariesConcurrentData.Add(currDict); #region calculate and report progress filesRead++; double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead; if (progress - (double)currProgressPerc > 1.0d) { currProgressPerc = Convert.ToInt32(progress); Console.WriteLine("read " + currProgressPerc + "%"); } #endregion calculate and report progress } lDictionariesConcurrentData.RemoveAll(dict => dict == null); lConcurrentData = lDictionariesConcurrentData.ConvertAll <ConcurrentData>(dict => { ConcurrentData retVal = null; try { retVal = new ConcurrentData(dict); } catch (Exception ex) { string strError = "couldn`t parse XML file " + dict["XMLfileName"] + " : " + Environment.NewLine + ex.Message; Console.WriteLine(strError); } return(retVal); }); lConcurrentData.RemoveAll(val => val == null); #endregion reading #region mapping // map obtained concurrent data to images by its datetime Console.WriteLine("concurrent data mapping started"); lStatsProcessing = lStatsProcessing.ConvertAll(ipdt => { string currImgFilename = ipdt.filename; currImgFilename = Path.GetFileNameWithoutExtension(currImgFilename); DateTime currImgDT = ConventionalTransitions.DateTimeOfSkyImageFilename(currImgFilename); ConcurrentData nearestConcurrentData = lConcurrentData.Aggregate((cDt1, cDt2) => { TimeSpan tspan1 = new TimeSpan(Math.Abs((cDt1.datetimeUTC - currImgDT).Ticks)); TimeSpan tspan2 = new TimeSpan(Math.Abs((cDt2.datetimeUTC - currImgDT).Ticks)); return((tspan1 <= tspan2) ? (cDt1) : (cDt2)); }); if (new TimeSpan(Math.Abs((nearestConcurrentData.datetimeUTC - currImgDT).Ticks)) >= TimeSpanForConcurrentDataMappingTolerance) { string strError = "couldn`t find close enough concurrent data file for image:" + Environment.NewLine + currImgFilename + Environment.NewLine + "closest concurrent data file is:" + Environment.NewLine + nearestConcurrentData.filename + Environment.NewLine + "with date-time value " + nearestConcurrentData.datetimeUTC.ToString("o"); Console.WriteLine(strError); nearestConcurrentData = null; } ipdt.concurrentData = nearestConcurrentData; if (nearestConcurrentData != null) { ipdt.concurrentDataXMLfile = nearestConcurrentData.filename; } return(ipdt); }); #endregion mapping removed = lStatsProcessing.RemoveAll(ipdt => ipdt.concurrentData == null); Console.WriteLine("removed " + removed + " items (couldn`t find concurrent data). " + lStatsProcessing.Count + " files remains to process."); #endregion list, read and map concurrent data } if (!lStatsProcessing.Any()) { Console.WriteLine("There is no files that sutisfy settings specified and have all required concurrent data (stats or GPS etc.). Processing will not be proceeded."); return; } #region Filter by SDC values predicting it using pre-trained NN parameters #region // //string csvHeader = lStatsProcessing[0].grixyrgbStats.CSVHeader() + // ",SunElevationDeg,SunAzimuthDeg,sunDiskCondition"; //List<string> lCSVheader = csvHeader.Split(',').ToList(); //List<int> columnsToDelete = // lCSVheader.Select((str, idx) => new Tuple<int, string>(idx, str)) // .Where(tpl => tpl.Item2.ToLower().Contains("filename")).ToList().ConvertAll(tpl => tpl.Item1); //List<List<string>> lCalculatedData = lStatsProcessing.ConvertAll(dt => //{ // string currImageALLstatsDataCSVWithConcurrentData = dt.grixyrgbStats.ToCSV() + "," + // dt.concurrentData.gps.SunZenithAzimuth() // .ElevationAngle.ToString() // .Replace(",", ".") + "," + // dt.concurrentData.gps.SunZenithAzimuth() // .Azimuth.ToString() // .Replace(",", "."); // List<string> retVal = currImageALLstatsDataCSVWithConcurrentData.Split(',').ToList(); // retVal = retVal.Where((str, idx) => !columnsToDelete.Contains(idx)).ToList(); // return retVal; //}); //List<DenseVector> lDV_objects_features = // lCalculatedData.ConvertAll( // list => // DenseVector.OfEnumerable(list.ConvertAll<double>(str => Convert.ToDouble(str.Replace(".", ","))))); #endregion DenseVector dvMeans = (DenseVector)((DenseMatrix)ServiceTools.ReadDataFromCSV(NormMeansFile, 0, ",")).Row(0); DenseVector dvRanges = (DenseVector)((DenseMatrix)ServiceTools.ReadDataFromCSV(NormRangeFile, 0, ",")).Row(0); #region // //lDV_objects_features = lDV_objects_features.ConvertAll(dv => //{ // DenseVector dvShifted = dv - dvMeans; // DenseVector dvNormed = (DenseVector)dvShifted.PointwiseDivide(dvRanges); // return dvNormed; //}); //DenseMatrix dmObjectsFeatures = DenseMatrix.OfRowVectors(lDV_objects_features); #endregion DenseVector dvThetaValues = (DenseVector)ServiceTools.ReadDataFromCSV(NNtrainedParametersFile, 0, ","); List <int> NNlayersConfig = new List <double>(((DenseMatrix)ServiceTools.ReadDataFromCSV(NNconfigFile, 0, ",")).Row(0)).ConvertAll (dVal => Convert.ToInt32(dVal)); #region // // List<List<double>> lDecisionProbabilities = null; #endregion List <Tuple <ImagesProcessingData, List <SDCdecisionProbability>, SunDiskCondition> > lTplsPredictedSDClist = new List <Tuple <ImagesProcessingData, List <SDCdecisionProbability>, SunDiskCondition> >(); List <List <double> > SDCdecisionProbabilitiesListDoubles = new List <List <double> >(); List <SunDiskCondition> imagesSDCpredicted = SDCpredictorNN.PredictSDC_NN(lStatsProcessing, NNlayersConfig, dvThetaValues, dvMeans, dvRanges, out SDCdecisionProbabilitiesListDoubles); List <List <SDCdecisionProbability> > SDCdecisionProbabilitiesLists = SDCdecisionProbabilitiesListDoubles.ConvertAll( currSDCdecisionProbabilities => currSDCdecisionProbabilities.Select((dProb, idx) => new SDCdecisionProbability() { sdc = SunDiskConditionData.MatlabSDCenum(idx + 1), sdcDecisionProbability = dProb }).ToList()); lTplsPredictedSDClist = lStatsProcessing.Zip( SDCdecisionProbabilitiesLists.Zip(imagesSDCpredicted, (lDecProb, sdcPredicted) => new Tuple <List <SDCdecisionProbability>, SunDiskCondition>(lDecProb, sdcPredicted)).ToList(), (ipd, tpl) => new Tuple <ImagesProcessingData, List <SDCdecisionProbability>, SunDiskCondition>(ipd, tpl.Item1, tpl.Item2)).ToList(); #region // //foreach (ImagesProcessingData dt in lStatsProcessing) //{ // List<double> currSDCdecisionProbabilities = new List<double>(); // SunDiskCondition currSDC = SDCpredictorNN.PredictSDC_NN(dt.grixyrgbStats, dt.concurrentData, // NNlayersConfig, dvThetaValues, dvMeans, dvRanges, out currSDCdecisionProbabilities); // List<SDCdecisionProbability> currSDCdecisionProbabilitiesList = currSDCdecisionProbabilities.Select((dProb, idx) => new SDCdecisionProbability() // { // sdc = SunDiskConditionData.MatlabSDCenum(idx + 1), // sdcDecisionProbability = dProb // }).ToList(); // lTplsPredictedSDClist.Add( // new Tuple<ImagesProcessingData, List<SDCdecisionProbability>, SunDiskCondition>(dt, // currSDCdecisionProbabilitiesList, currSDC)); //} #endregion #region // //List<int> predictedSDC = // NNclassificatorPredictor.NNpredict(dmObjectsFeatures, dvThetaValues, NNlayersConfig, // out lDecisionProbabilities).ToList(); //List<SunDiskCondition> predictedSDClist = predictedSDC.ConvertAll(sdcInt => //{ // switch (sdcInt) // { // case 4: // return SunDiskCondition.NoSun; // break; // case 1: // return SunDiskCondition.Sun0; // break; // case 2: // return SunDiskCondition.Sun1; // break; // case 3: // return SunDiskCondition.Sun2; // break; // default: // return SunDiskCondition.Defect; // } //}); //List<Tuple<ImagesProcessingData, SunDiskCondition>> lTplsPredictedSDClist = // predictedSDClist.Zip(lStatsProcessing, // (sdc, ipd) => new Tuple<ImagesProcessingData, SunDiskCondition>(ipd, sdc)).ToList(); #endregion #region output obtained SDC data to log file string strToShow = "SDC values probabilities: " + Environment.NewLine + "| NoSun | Sun0 | Sun1 | Sun2 |" + Environment.NewLine; foreach (Tuple <ImagesProcessingData, List <SDCdecisionProbability>, SunDiskCondition> tpl in lTplsPredictedSDClist) { List <SDCdecisionProbability> currSDCdecisionProbabilitiesList = tpl.Item2; strToShow += "|" + String.Format("{0,9}", (currSDCdecisionProbabilitiesList.First( prob => prob.sdc == SunDiskCondition.NoSun).sdcDecisionProbability * 100.0d) .ToString("F2") + "%") + "|" + String.Format("{0,9}", (currSDCdecisionProbabilitiesList.First( prob => prob.sdc == SunDiskCondition.Sun0).sdcDecisionProbability * 100.0d) .ToString("F2") + "%") + "|" + String.Format("{0,9}", (currSDCdecisionProbabilitiesList.First( prob => prob.sdc == SunDiskCondition.Sun1).sdcDecisionProbability * 100.0d) .ToString("F2") + "%") + "|" + String.Format("{0,9}", (currSDCdecisionProbabilitiesList.First( prob => prob.sdc == SunDiskCondition.Sun2).sdcDecisionProbability * 100.0d) .ToString("F2") + "%") + "|" + Environment.NewLine; } ServiceTools.logToTextFile(errorLogFilename, strToShow, true, false); #endregion output obtained SDC data to log file #region filter by SDC value if needed if (sdcFilter != SunDiskCondition.Undefined) { lStatsProcessing = lStatsProcessing.Where((ipd, idx) => lTplsPredictedSDClist[idx].Item3 == sdcFilter).ToList(); Console.WriteLine("Detected " + lStatsProcessing.Count + " images with SDC = " + sdcFilter.ToString()); } #endregion filter by SDC value if needed #endregion Filter by SDC values predicting it using pre-trained NN parameters #region ObservedCloudCoverDataCSVfile if (bFilterByObservedCloudCoverRecords) { Console.WriteLine("Reading observed cloud cover data CSV file..."); if (!File.Exists(ObservedCloudCoverDataCSVfile)) { Console.WriteLine("Unable to read observed data CSV file: " + ObservedCloudCoverDataCSVfile); return; } List <List <string> > lCSVfileContents = ServiceTools.ReadDataFromCSV(ObservedCloudCoverDataCSVfile, 1, true); if (!lCSVfileContents.Any()) { Console.WriteLine("The observed cloud cover CSV file seems to be empty: " + ObservedCloudCoverDataCSVfile); return; } List <ObservedClCoverData> lObservedData = lCSVfileContents.ConvertAll(lStr => new ObservedClCoverData(lStr)); List <SkyImagesDataWith_Concurrent_Stats_CloudCover_SDC> lImagesFilteredByAvailableObservedData = new List <SkyImagesDataWith_Concurrent_Stats_CloudCover_SDC>(); #region filter images by available observed data using DateTimeFilterTolerance Console.WriteLine("Filtering by observed data available..."); foreach (ObservedClCoverData observedData in lObservedData) { DateTime currObservedDatumDateTime = observedData.dt; List <SkyImagesDataWith_Concurrent_Stats_CloudCover_SDC> lImagesCloseToCurrObservedDatum = lStatsProcessing .Where(ipd => { TimeSpan tspan = new TimeSpan( Math.Abs( (ConventionalTransitions.DateTimeOfSkyImageFilename(ipd.filename) - currObservedDatumDateTime).Ticks)); return(tspan <= DateTimeFilterTolerance); }) .ToList() .ConvertAll(ifd => new SkyImagesDataWith_Concurrent_Stats_CloudCover_SDC() { // observedData // ifd skyImageFullFileName = ifd.filename, skyImageFileName = Path.GetFileName(ifd.filename), currImageDateTime = ConventionalTransitions.DateTimeOfSkyImageFilename(ifd.filename), observedCloudCoverData = observedData, concurrentDataXMLfile = ifd.concurrentDataXMLfile, concurrentData = ifd.concurrentData, grixyrgbStatsXMLfile = ifd.grixyrgbStatsXMLfile, grixyrgbStats = ifd.grixyrgbStats, SDCvalue = lTplsPredictedSDClist.First(tpl => tpl.Item1 == ifd).Item3, SDCprobabilities = lTplsPredictedSDClist.First(tpl => tpl.Item1 == ifd).Item2 }); lImagesFilteredByAvailableObservedData.AddRange(lImagesCloseToCurrObservedDatum); } #endregion filter images by available observed data using DateTimeFilterTolerance if (!lImagesFilteredByAvailableObservedData.Any()) { Console.WriteLine( "There is no images remain after filtering using all available data. Output will be empty."); } ServiceTools.WriteObjectToXML(lImagesFilteredByAvailableObservedData, outputDataFile); #region Сформируем и запишем данные в CSV-файл // Здесь есть данные по наблюдаемому CloudCover string csvHeader = lImagesFilteredByAvailableObservedData[0].grixyrgbStats.CSVHeader() + ",SunElevationDeg,SunAzimuthDeg,ObservedTotalCloudCover,ObservedLowerCloudCover,SDC,SDCprobabilityNoSun,SDCprobabilitySun0,SDCprobabilitySun1,SDCprobabilitySun2"; List <string> lCSVoutputData = lImagesFilteredByAvailableObservedData.ConvertAll(ifd => { // все стат. предикторы - как для SDC // данные CloudCover string retVal = ""; //ImagesProcessingData dt = tpl.Item2; //ObservedClCoverData clCov = tpl.Item1; retVal = ifd.grixyrgbStats.ToCSV() + "," + ifd.concurrentData.gps.SunZenithAzimuth().ElevationAngle.ToString().Replace(",", ".") + "," + ifd.concurrentData.gps.SunZenithAzimuth().Azimuth.ToString().Replace(",", ".") + "," + ifd.observedCloudCoverData.CloudCoverTotal.ToString() + "," + ifd.observedCloudCoverData.CloudCoverLower.ToString() + "," + ifd.SDCvalue.ToString() + "," + ifd.SDCprobabilities.First(prob => prob.sdc == SunDiskCondition.NoSun) .sdcDecisionProbability.ToString().Replace(",", ".") + "," + ifd.SDCprobabilities.First(prob => prob.sdc == SunDiskCondition.Sun0) .sdcDecisionProbability.ToString().Replace(",", ".") + "," + ifd.SDCprobabilities.First(prob => prob.sdc == SunDiskCondition.Sun1) .sdcDecisionProbability.ToString().Replace(",", ".") + "," + ifd.SDCprobabilities.First(prob => prob.sdc == SunDiskCondition.Sun2) .sdcDecisionProbability.ToString().Replace(",", "."); return(retVal); }); string strToOutputToCSVfile = string.Join(Environment.NewLine, lCSVoutputData); ServiceTools.logToTextFile(outputCSVfile, csvHeader + Environment.NewLine, true, false); ServiceTools.logToTextFile(outputCSVfile, strToOutputToCSVfile, true, false); #endregion Сформируем и запишем данные в CSV-файл } else { ServiceTools.WriteObjectToXML(lStatsProcessing, outputDataFile); #region Сформируем и запишем данные в CSV-файл // здесь нет данных по наблюдаемому Cloud Cover // не надо нам такое. Оставим все это только в виде XML-файла. #endregion Сформируем и запишем данные в CSV-файл } #endregion ObservedCloudCoverDataCSVfile #endregion Enumerating files and output to XML and CSV file Console.WriteLine("saved output data to file: " + Environment.NewLine + outputDataFile + Environment.NewLine + Environment.NewLine); Console.WriteLine("===FINISHED==="); Console.ReadKey(); }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (!File.Exists(defaultPropertiesXMLfileName)) { return; } defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); bool bDefaultPropertiesHasBeenUpdated = false; string CurDir = Directory.GetCurrentDirectory(); currPath2Process = ""; if (defaultProperties.ContainsKey("ImagesBasePath")) { currPath2Process = (string)defaultProperties["ImagesBasePath"]; } else { currPath2Process = CurDir; defaultProperties.Add("ImagesBasePath", currPath2Process); bDefaultPropertiesHasBeenUpdated = true; } //imageYRGBstatsXMLdataFilesDirectory if (defaultProperties.ContainsKey("imageYRGBstatsXMLdataFilesDirectory")) { imageYRGBstatsXMLdataFilesDirectory = (string)defaultProperties["imageYRGBstatsXMLdataFilesDirectory"]; } else { imageYRGBstatsXMLdataFilesDirectory = CurDir; defaultProperties.Add("imageYRGBstatsXMLdataFilesDirectory", imageYRGBstatsXMLdataFilesDirectory); bDefaultPropertiesHasBeenUpdated = true; //saveDefaultProperties(); } //imageMP5statsXMLdataFilesDirectory if (defaultProperties.ContainsKey("imageMP5statsXMLdataFilesDirectory")) { imageMP5statsXMLdataFilesDirectory = (string)defaultProperties["imageMP5statsXMLdataFilesDirectory"]; } else { imageMP5statsXMLdataFilesDirectory = CurDir; defaultProperties.Add("imageMP5statsXMLdataFilesDirectory", imageMP5statsXMLdataFilesDirectory); bDefaultPropertiesHasBeenUpdated = true; //saveDefaultProperties(); } // maxConcurrentImagesProcessing if (defaultProperties.ContainsKey("maxConcurrentImagesProcessing")) { maxConcurrentImagesProcessing = Convert.ToInt32(defaultProperties["maxConcurrentImagesProcessing"]); } else { defaultProperties.Add("maxConcurrentImagesProcessing", 4); bDefaultPropertiesHasBeenUpdated = true; //saveDefaultProperties(); } if (defaultProperties.ContainsKey("ImagesRoundMasksXMLfilesMappingList")) { ImagesRoundMasksXMLfilesMappingList = (string)defaultProperties["ImagesRoundMasksXMLfilesMappingList"]; } else { ImagesRoundMasksXMLfilesMappingList = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "ImagesRoundMasksXMLfilesMappingList.csv"; defaultProperties.Add("ImagesRoundMasksXMLfilesMappingList", ImagesRoundMasksXMLfilesMappingList); bDefaultPropertiesHasBeenUpdated = true; } if (defaultProperties.ContainsKey("strPerformanceCountersStatsFile")) { strPerformanceCountersStatsFile = (string)defaultProperties["strPerformanceCountersStatsFile"]; } else { strPerformanceCountersStatsFile = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-perf-data.csv"; defaultProperties.Add("strPerformanceCountersStatsFile", strPerformanceCountersStatsFile); bDefaultPropertiesHasBeenUpdated = true; } if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (!File.Exists(defaultPropertiesXMLfileName)) { Console.WriteLine("couldn`t find settings XML file: " + Environment.NewLine + defaultPropertiesXMLfileName); } else { defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); } bool bDefaultPropertiesHasBeenUpdated = false; string CurDir = Directory.GetCurrentDirectory(); // ImagesBasePath if (defaultProperties.ContainsKey("ImagesBasePath")) { ImagesBasePath = (string)defaultProperties["ImagesBasePath"]; } else { ImagesBasePath = CurDir + Path.DirectorySeparatorChar + "images" + Path.DirectorySeparatorChar; defaultProperties.Add("ImagesBasePath", ImagesBasePath); bDefaultPropertiesHasBeenUpdated = true; } // IncomingImagesBasePath if (defaultProperties.ContainsKey("IncomingImagesBasePath")) { IncomingImagesBasePath = (string)defaultProperties["IncomingImagesBasePath"]; } else { IncomingImagesBasePath = CurDir + Path.DirectorySeparatorChar + "IncomingImages" + Path.DirectorySeparatorChar; defaultProperties.Add("IncomingImagesBasePath", IncomingImagesBasePath); ServiceTools.CheckIfDirectoryExists(IncomingImagesBasePath); bDefaultPropertiesHasBeenUpdated = true; } // ConcurrentDataXMLfilesBasePath if (defaultProperties.ContainsKey("ConcurrentDataXMLfilesBasePath")) { ConcurrentDataXMLfilesBasePath = (string)defaultProperties["ConcurrentDataXMLfilesBasePath"]; } else { ConcurrentDataXMLfilesBasePath = ""; defaultProperties.Add("ConcurrentDataXMLfilesBasePath", ConcurrentDataXMLfilesBasePath); bDefaultPropertiesHasBeenUpdated = true; } // YRGBstatsXMLdataFilesDirectory if (defaultProperties.ContainsKey("YRGBstatsXMLdataFilesDirectory")) { YRGBstatsXMLdataFilesDirectory = (string)defaultProperties["YRGBstatsXMLdataFilesDirectory"]; } else { YRGBstatsXMLdataFilesDirectory = ""; defaultProperties.Add("YRGBstatsXMLdataFilesDirectory", YRGBstatsXMLdataFilesDirectory); bDefaultPropertiesHasBeenUpdated = true; } //RadiometersDataPath if (defaultProperties.ContainsKey("RadiometersDataPath")) { RadiometersDataPath = (string)defaultProperties["RadiometersDataPath"]; } else { RadiometersDataPath = @"C:\Program Files (x86)\Theodor Friedrichs\Comgraph32\"; defaultProperties.Add("RadiometersDataPath", RadiometersDataPath); bDefaultPropertiesHasBeenUpdated = true; } // tgrm_token if (defaultProperties.ContainsKey("tgrm_token")) { tgrm_token = (string)defaultProperties["tgrm_token"]; } else { tgrm_token = ""; defaultProperties.Add("tgrm_token", tgrm_token); bDefaultPropertiesHasBeenUpdated = true; } // R2SLufftUMBappPath if (defaultProperties.ContainsKey("R2SLufftUMBappPath")) { R2SLufftUMBappPath = (string)defaultProperties["R2SLufftUMBappPath"]; } else { R2SLufftUMBappPath = ""; defaultProperties.Add("R2SLufftUMBappPath", R2SLufftUMBappPath); bDefaultPropertiesHasBeenUpdated = true; } // VentusLufftUMBappPath if (defaultProperties.ContainsKey("VentusLufftUMBappPath")) { VentusLufftUMBappPath = (string)defaultProperties["VentusLufftUMBappPath"]; } else { VentusLufftUMBappPath = ""; defaultProperties.Add("VentusLufftUMBappPath", VentusLufftUMBappPath); bDefaultPropertiesHasBeenUpdated = true; } // WSLufftUMBappPath if (defaultProperties.ContainsKey("WSLufftUMBappPath")) { WSLufftUMBappPath = (string)defaultProperties["WSLufftUMBappPath"]; } else { WSLufftUMBappPath = ""; defaultProperties.Add("WSLufftUMBappPath", WSLufftUMBappPath); bDefaultPropertiesHasBeenUpdated = true; } if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
private void bgwCopier_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker SelfWorker = sender as BackgroundWorker; object[] bgwArgs = e.Argument as object[]; string fromPath = bgwArgs[0] as string; string concurrentDataFilesPath = bgwArgs[1] as string; string toPath = bgwArgs[2] as string; string imagesStatsXMLfilesDir = bgwArgs[3] as string; DirectoryInfo dir = new DirectoryInfo(fromPath); String destDirectory = toPath + ((toPath.Last() == Path.DirectorySeparatorChar) ? ("") : (Path.DirectorySeparatorChar.ToString())); if (!dir.Exists) { theLogWindow = ServiceTools.LogAText(theLogWindow, "Операция не выполнена. Не найдена директория:" + Environment.NewLine + fromPath + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, "Операция не выполнена. Не найдена директория:" + Environment.NewLine + fromPath + Environment.NewLine, true); return; } FileInfo[] FileList2Process = dir.GetFiles("*.jpg", SearchOption.AllDirectories); List <Tuple <string, string> > imagesStatsXMLfiles = new List <Tuple <string, string> >(); if (Directory.Exists(imagesStatsXMLfilesDir)) { imagesStatsXMLfiles = (new DirectoryInfo(imagesStatsXMLfilesDir)).EnumerateFiles( ConventionalTransitions.ImageGrIxYRGBstatsFileNamesPattern(), SearchOption.AllDirectories) .ToList() .ConvertAll(fInfo => new Tuple <string, string>(fInfo.Name, fInfo.FullName)); } DirectoryInfo dirConcurrentDataFiles = new DirectoryInfo(concurrentDataFilesPath); List <Tuple <string, DateTime> > lConcurrentDataFiles = dirConcurrentDataFiles.EnumerateFiles(ConventionalTransitions.ImageConcurrentDataFilesNamesPattern(), SearchOption.AllDirectories).ToList().ConvertAll(fInfo => { // data-2015-12-15T06-12-56.0590302Z.xml string strDateTimeOfFile = Path.GetFileNameWithoutExtension(fInfo.Name).Substring(5, 28); strDateTimeOfFile = strDateTimeOfFile.Substring(0, 11) + strDateTimeOfFile.Substring(11).Replace('-', ':'); DateTime currFileDT = DateTime.Parse(strDateTimeOfFile, null, System.Globalization.DateTimeStyles.AdjustToUniversal); currFileDT = DateTime.SpecifyKind(currFileDT, DateTimeKind.Utc); return(new Tuple <string, DateTime>(fInfo.FullName, currFileDT)); }); int filesCount = FileList2Process.Length; theLogWindow = ServiceTools.LogAText(theLogWindow, "searching in directory: " + dir.FullName + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, "searching in directory: " + dir.FullName + Environment.NewLine, true); theLogWindow = ServiceTools.LogAText(theLogWindow, "files found count: " + filesCount + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, "files found count: " + filesCount + Environment.NewLine, true); String usedDateTimes = ""; List <DateTime> listUsedHours = new List <DateTime>(); int counter = 0; foreach (FileInfo fileInfo in FileList2Process) { if (SelfWorker.CancellationPending) { break; } counter++; double percCounter = (double)counter * 1000.0d / (double)filesCount; SelfWorker.ReportProgress(Convert.ToInt32(percCounter)); Image anImage = Image.FromFile(fileInfo.FullName); ImageInfo newIInfo = new ImageInfo(anImage); //ThreadSafeOperations.SetTextTB(tbLog, "processing file " + fileInfo.Name + Environment.NewLine, true); //String curDateTime = ""; int minute = 0; //String dateTime = (String)newIInfo.getValueByKey("DateTime"); String strDateTimeEXIF = (String)newIInfo.getValueByKey("ExifDTOrig"); if (strDateTimeEXIF == null) { //попробуем вытащить из имени файла string strDateTime = fileInfo.Name; strDateTime = strDateTime.Substring(4, 19); strDateTimeEXIF = strDateTime; } //curDateTime = dateTime; DateTime curImgDateTime; DateTime theHour = RoundToHour(DateTime.UtcNow); try { //curImgDateTime = DateTimeOfString(strDateTimeEXIF); curImgDateTime = ConventionalTransitions.DateTimeOfSkyImageFilename(fileInfo.Name); theHour = RoundToHour(curImgDateTime); } catch (Exception ex) { continue; } //minute = Convert.ToInt32(strDateTimeEXIF.Substring(14, 2)); //if ((minute == 0) && (!listUsedHours.Contains(theHour))) if (new TimeSpan(Math.Abs((theHour - curImgDateTime).Ticks)) <= filterTolerance) { #region copy the image file itself listUsedHours.Add(theHour); string dateDirectorySuffix = curImgDateTime.ToString("yyyy-MM-dd"); string currDateDestDirectory = destDirectory + dateDirectorySuffix + Path.DirectorySeparatorChar; if (!ServiceTools.CheckIfDirectoryExists(currDateDestDirectory)) { currDateDestDirectory = destDirectory; } String newFileName = currDateDestDirectory + fileInfo.Name; File.Copy(fileInfo.FullName, newFileName); theLogWindow = ServiceTools.LogAText(theLogWindow, "COPY: " + fileInfo.FullName + " >>> " + newFileName + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, "COPY: " + fileInfo.FullName + " >>> " + newFileName + Environment.NewLine, true); #endregion copy the image file itself #region find and copy the GrIx,YRGB stats data file if (imagesStatsXMLfiles.Any()) { string xmlStatsFileName = ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(fileInfo.FullName, "", false); Tuple <string, string> foundXMLfile = imagesStatsXMLfiles.Find(tpl => tpl.Item1 == xmlStatsFileName); if (foundXMLfile != null) { string sStatsXMLfilename = foundXMLfile.Item2; string newStatsXMLfilename = currDateDestDirectory + foundXMLfile.Item1; File.Copy(sStatsXMLfilename, newStatsXMLfilename); theLogWindow = ServiceTools.LogAText(theLogWindow, "COPY: " + sStatsXMLfilename + " >>> " + newStatsXMLfilename + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, // "COPY: " + sStatsXMLfilename + " >>> " + newStatsXMLfilename + Environment.NewLine, // true); } else { theLogWindow = ServiceTools.LogAText(theLogWindow, "========== ERROR: couldn`t find GrIx,YRGB stats XML file" + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, // "========== ERROR: couldn`t find GrIx,YRGB stats XML file" + Environment.NewLine, true); } } #endregion find and copy the GrIx,YRGB stats data file #region find and copy concurrent data XML file if (lConcurrentDataFiles.Any()) { //найдем ближайший по времени List <Tuple <string, TimeSpan> > lCurrFileConcurrentDataNearest = lConcurrentDataFiles.ConvertAll( tpl => new Tuple <string, TimeSpan>(tpl.Item1, new TimeSpan(Math.Abs((tpl.Item2 - curImgDateTime).Ticks)))); lCurrFileConcurrentDataNearest.Sort(new Comparison <Tuple <string, TimeSpan> >((tpl1, tpl2) => { if (tpl1 == null) { if (tpl2 == null) { return(0); } else { return(-1); } } else { if (tpl2 == null) { return(1); } else { return(tpl1.Item2.CompareTo(tpl2.Item2)); } } })); GPSdata gps = new GPSdata(); Tuple <string, TimeSpan> nearestConcurrentDataFile = null; int concurrentDataFileIdx = 0; while (!gps.validGPSdata) { nearestConcurrentDataFile = lCurrFileConcurrentDataNearest[concurrentDataFileIdx]; Dictionary <string, object> dictSavedData = ServiceTools.ReadDictionaryFromXML(nearestConcurrentDataFile.Item1); gps = new GPSdata((string)dictSavedData["GPSdata"], GPSdatasources.CloudCamArduinoGPS, DateTime.Parse((string)dictSavedData["GPSDateTimeUTC"], null, System.Globalization.DateTimeStyles.RoundtripKind)); concurrentDataFileIdx++; } string currValidConcurrentDataFile = nearestConcurrentDataFile.Item1; string currValidConcurrentDataFileToCopyTo = currDateDestDirectory + "data-" + Path.GetFileNameWithoutExtension(fileInfo.FullName) + ".xml"; File.Copy(currValidConcurrentDataFile, currValidConcurrentDataFileToCopyTo); theLogWindow = ServiceTools.LogAText(theLogWindow, "COPY: " + currValidConcurrentDataFile + " >>> " + currValidConcurrentDataFileToCopyTo + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, // "COPY: " + currValidConcurrentDataFile + " >>> " + currValidConcurrentDataFileToCopyTo + // Environment.NewLine, true); } else { theLogWindow = ServiceTools.LogAText(theLogWindow, "========== ERROR: couldn`t find concurrent data file for " + fileInfo.FullName + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, "========== ERROR: couldn`t find concurrent data file for " + fileInfo.FullName + Environment.NewLine, true); } #endregion find and copy concurrent data XML file theLogWindow.ClearLog(); } } }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (File.Exists(defaultPropertiesXMLfileName)) { defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); } bool bDefaultPropertiesHasBeenUpdated = false; string CurDir = Directory.GetCurrentDirectory(); currPath2Process = ""; if (defaultProperties.ContainsKey("ImagesBasePath")) { currPath2Process = (string)defaultProperties["ImagesBasePath"]; } else { currPath2Process = CurDir; defaultProperties.Add("ImagesBasePath", currPath2Process); bDefaultPropertiesHasBeenUpdated = true; } //imageYRGBstatsXMLdataFilesDirectory if (defaultProperties.ContainsKey("imageYRGBstatsXMLdataFilesDirectory")) { imageYRGBstatsXMLdataFilesDirectory = (string)defaultProperties["imageYRGBstatsXMLdataFilesDirectory"]; } else { imageYRGBstatsXMLdataFilesDirectory = CurDir; defaultProperties.Add("imageYRGBstatsXMLdataFilesDirectory", imageYRGBstatsXMLdataFilesDirectory); bDefaultPropertiesHasBeenUpdated = true; //saveDefaultProperties(); } // strConcurrentGPSdataXMLfilesPath if (defaultProperties.ContainsKey("strConcurrentGPSdataXMLfilesPath")) { strConcurrentGPSdataXMLfilesPath = (string)defaultProperties["strConcurrentGPSdataXMLfilesPath"]; } else { strConcurrentGPSdataXMLfilesPath = CurDir; defaultProperties.Add("strConcurrentGPSdataXMLfilesPath", strConcurrentGPSdataXMLfilesPath); bDefaultPropertiesHasBeenUpdated = true; } // strOverallImagesConcurrentDataDirectory if (defaultProperties.ContainsKey("strSkyImagesDataWithConcurrentStatsCloudCoverAndSDCDirectory")) { strSkyImagesDataWithConcurrentStatsCloudCoverAndSDCDirectory = (string)defaultProperties["strSkyImagesDataWithConcurrentStatsCloudCoverAndSDCDirectory"]; } else { strSkyImagesDataWithConcurrentStatsCloudCoverAndSDCDirectory = CurDir; defaultProperties.Add("strSkyImagesDataWithConcurrentStatsCloudCoverAndSDCDirectory", strSkyImagesDataWithConcurrentStatsCloudCoverAndSDCDirectory); bDefaultPropertiesHasBeenUpdated = true; } if (defaultProperties.ContainsKey("SunDiskConditionXMLdataFilesDirectory")) { SunDiskConditionXMLdataFilesDirectory = (string)defaultProperties["SunDiskConditionXMLdataFilesDirectory"]; } else { SunDiskConditionXMLdataFilesDirectory = CurDir; defaultProperties.Add("SunDiskConditionXMLdataFilesDirectory", SunDiskConditionXMLdataFilesDirectory); bDefaultPropertiesHasBeenUpdated = true; //saveDefaultProperties(); } // IoffeMeteoNavFilesDirectory if (defaultProperties.ContainsKey("IoffeMeteoNavFilesDirectory")) { IoffeMeteoNavFilesDirectory = (string)defaultProperties["IoffeMeteoNavFilesDirectory"]; } else { IoffeMeteoNavFilesDirectory = CurDir; defaultProperties.Add("IoffeMeteoNavFilesDirectory", IoffeMeteoNavFilesDirectory); bDefaultPropertiesHasBeenUpdated = true; } // strObservationsReportCSVfile if (defaultProperties.ContainsKey("strObservationsReportCSVfile")) { strObservationsReportCSVfile = (string)defaultProperties["strObservationsReportCSVfile"]; } else { strObservationsReportCSVfile = CurDir + Path.DirectorySeparatorChar + "meteo-report.csv"; defaultProperties.Add("strObservationsReportCSVfile", strObservationsReportCSVfile); bDefaultPropertiesHasBeenUpdated = true; } if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
private void btnCorrectGPSdata_Click(object sender, EventArgs e) { string infoFilesPath = rtbPath.Text; string navdataFilesPath = rtbVesselNavDataDirectoryPath.Text; infoFilesPath += ((infoFilesPath.Substring(infoFilesPath.Length - 1) == "\\") ? ("") : ("\\")); string bcpFilesPath = infoFilesPath + "backup\\"; if (infoFilesPath == "") { return; } if (!Directory.Exists(infoFilesPath)) { return; } if (navdataFilesPath == "") { return; } if (!Directory.Exists(navdataFilesPath)) { return; } DirectoryInfo dirConcurrentDataFiles = new DirectoryInfo(infoFilesPath); FileInfo[] concurrentDataFilesList = dirConcurrentDataFiles.GetFiles("*.xml", SearchOption.TopDirectoryOnly); //string[] sConcurrentInfoFilenames = Directory.GetFiles(rtbPath.Text, "*.xml"); if (!concurrentDataFilesList.Any()) { return; } if (!ServiceTools.CheckIfDirectoryExists(bcpFilesPath)) { return; } CultureInfo provider = CultureInfo.InvariantCulture; foreach (FileInfo concurrentInfoFileInfo in concurrentDataFilesList) { Dictionary <string, object> dictSavedData = ServiceTools.ReadDictionaryFromXML(concurrentInfoFileInfo.FullName); DateTime computerDateTime = DateTime.ParseExact((string)dictSavedData["DateTime"], "o", provider).ToUniversalTime(); DateTime gpsDateTime = DateTime.ParseExact((string)dictSavedData["GPSDateTimeUTC"], "o", provider).ToUniversalTime(); if (Math.Abs((gpsDateTime - computerDateTime).TotalSeconds) > 300) { //надо корректировать по данным судовой навигации File.Copy(concurrentInfoFileInfo.FullName, bcpFilesPath + concurrentInfoFileInfo.Name); dictSavedData["GPSdata"] = "$GPGGA," + computerDateTime.Hour.ToString("D02") + computerDateTime.Minute.ToString("D02") + computerDateTime.Second.ToString("D02") + ".00"; IoffeVesselDualNavDataConverted ioffeNavdata = IoffeVesselNavDataReader.GetNavDataByDatetime(navdataFilesPath, computerDateTime); if (ioffeNavdata == null) { theLogWindow = ServiceTools.LogAText(theLogWindow, "couldn`t find vessel nav data for file: " + Environment.NewLine + concurrentInfoFileInfo.FullName); continue; } dictSavedData["GPSLat"] = ioffeNavdata.gps.Lat; dictSavedData["GPSLon"] = ioffeNavdata.gps.Lon; dictSavedData["GPSDateTimeUTC"] = ioffeNavdata.gps.dateTimeUTC.ToString("o"); ServiceTools.WriteDictionaryToXml(dictSavedData, concurrentInfoFileInfo.FullName); } } }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (File.Exists(defaultPropertiesXMLfileName)) { defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); } bool bDefaultPropertiesHasBeenUpdated = false; string curDir = Directory.GetCurrentDirectory(); #region ImagesBaseSourcePath if (defaultProperties.ContainsKey("ImagesBaseSourcePath")) { ImagesBaseSourcePath = (string)defaultProperties["ImagesBaseSourcePath"]; } else { ImagesBaseSourcePath = curDir; defaultProperties.Add("ImagesBaseSourcePath", ImagesBaseSourcePath); bDefaultPropertiesHasBeenUpdated = true; } ThreadSafeOperations.SetTextTB(rtbImagesBaseSourcePath, ImagesBaseSourcePath, false); #endregion ImagesBaseSourcePath #region ConcurrentAndStatsXMLfilesDir if (defaultProperties.ContainsKey("ConcurrentAndStatsXMLfilesDir")) { ConcurrentAndStatsXMLfilesDir = (string)defaultProperties["ConcurrentAndStatsXMLfilesDir"]; } else { ConcurrentAndStatsXMLfilesDir = curDir; defaultProperties.Add("ConcurrentAndStatsXMLfilesDir", ConcurrentAndStatsXMLfilesDir); bDefaultPropertiesHasBeenUpdated = true; } ThreadSafeOperations.SetTextTB(rtbConcurrentAndStatsXMLfilesDir, ConcurrentAndStatsXMLfilesDir, false); #endregion ConcurrentAndStatsXMLfilesDir #region ObservedDataCSVfile if (defaultProperties.ContainsKey("ObservedDataCSVfile")) { ObservedDataCSVfile = (string)defaultProperties["ObservedDataCSVfile"]; } else { ObservedDataCSVfile = curDir; defaultProperties.Add("ObservedDataCSVfile", ObservedDataCSVfile); bDefaultPropertiesHasBeenUpdated = true; } ThreadSafeOperations.SetTextTB(rtbObservedDataCSVfile, ObservedDataCSVfile, false); #endregion ObservedDataCSVfile #region DestinationPath if (defaultProperties.ContainsKey("DestinationPath")) { DestinationPath = (string)defaultProperties["DestinationPath"]; } else { DestinationPath = curDir; defaultProperties.Add("DestinationPath", DestinationPath); bDefaultPropertiesHasBeenUpdated = true; } ThreadSafeOperations.SetTextTB(rtbDestinationPath, DestinationPath, false); #endregion DestinationPath #region DateTimeFilterTolerance if (defaultProperties.ContainsKey("DateTimeFilterTolerance")) { DateTimeFilterTolerance = TimeSpan.Parse((string)defaultProperties["DateTimeFilterTolerance"]); } else { defaultProperties.Add("DateTimeFilterTolerance", DateTimeFilterTolerance.ToString()); bDefaultPropertiesHasBeenUpdated = true; } #endregion DateTimeFilterTolerance if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + "\\settings\\SeaTripdataAnalysisApp-Settings.xml"; if (!File.Exists(defaultPropertiesXMLfileName)) { defaultProperties = new Dictionary <string, object>(); defaultProperties.Add("DefaultExportDestinationDirectory", Directory.GetCurrentDirectory()); saveDefaultProperties(); } defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); string CurDir = Directory.GetCurrentDirectory(); string currExportDirectoryPath = ""; if (defaultProperties.ContainsKey("DefaultExportDestinationDirectory")) { currExportDirectoryPath = (string)defaultProperties["DefaultExportDestinationDirectory"]; } else { currExportDirectoryPath = CurDir + "\\data-export\\"; } ThreadSafeOperations.SetTextTB(rtbExportDestinationDirectoryPath, currExportDirectoryPath, false); if (defaultProperties.ContainsKey("InitialLogFilesDirectory")) { tbLogFilesPath.Text = (string)defaultProperties["InitialLogFilesDirectory"]; strLogFilesDirectory = (string)defaultProperties["InitialLogFilesDirectory"]; } else { defaultProperties.Add("InitialLogFilesDirectory", ""); saveDefaultProperties(); } if (defaultProperties.ContainsKey("ProcessedDataOutputDirectory")) { tbOutputDirectoryValue.Text = (string)defaultProperties["ProcessedDataOutputDirectory"]; strOutputDirectory = (string)defaultProperties["ProcessedDataOutputDirectory"]; } else { defaultProperties.Add("ProcessedDataOutputDirectory", ""); saveDefaultProperties(); } if (defaultProperties.ContainsKey("SourceDataDirectory")) { tbSourceDirectoryValue.Text = (string)defaultProperties["SourceDataDirectory"]; strSourceDirectory = (string)defaultProperties["SourceDataDirectory"]; } else { defaultProperties.Add("SourceDataDirectory", ""); saveDefaultProperties(); } }
private void BgwSnapshotsFilteringWithSunElevation_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker selfWorker = sender as BackgroundWorker; object[] bgwArgs = e.Argument as object[]; string SnapshotsBasePath = bgwArgs[0] as string; string concurrentDataFilesPath = bgwArgs[1] as string; string directoryToMoveFilesTo = bgwArgs[2] as string; DirectoryInfo srcDir = new DirectoryInfo(SnapshotsBasePath); if (!srcDir.Exists) { theLogWindow = ServiceTools.LogAText(theLogWindow, "Операция не выполнена. Не найдена директория:" + Environment.NewLine + SnapshotsBasePath + Environment.NewLine); //ThreadSafeOperations.SetTextTB(tbLog, "Операция не выполнена. Не найдена директория:" + Environment.NewLine + fromPath + Environment.NewLine, true); return; } List <FileInfo> lFileList2Process = srcDir.GetFiles("*.jpg", SearchOption.AllDirectories).ToList(); List <FileInfoWithSnapshotDateTime> lSnapshotsInfos = lFileList2Process.ConvertAll(finfo => new FileInfoWithSnapshotDateTime(finfo)); #region read concurrent data from XML files theLogWindow = ServiceTools.LogAText(theLogWindow, "started concurrent data reading"); List <Tuple <string, ConcurrentData> > lImagesConcurrentData = new List <Tuple <string, ConcurrentData> >(); List <string> filesListConcurrentData = new List <string>(Directory.EnumerateFiles(concurrentDataFilesPath, ConventionalTransitions.ImageConcurrentDataFilesNamesPattern(), SearchOption.AllDirectories)); int totalFilesCountToRead = filesListConcurrentData.Count; int filesRead = 0; int currProgressPerc = 0; selfWorker.ReportProgress(0); List <Dictionary <string, object> > lDictionariesConcurrentData = new List <Dictionary <string, object> >(); foreach (string strConcDataXMLFile in filesListConcurrentData) { Dictionary <string, object> currDict = ServiceTools.ReadDictionaryFromXML(strConcDataXMLFile); currDict.Add("XMLfileName", Path.GetFileName(strConcDataXMLFile)); lDictionariesConcurrentData.Add(currDict); #region calculate and report progress filesRead++; double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead; if (progress - (double)currProgressPerc > 1.0d) { currProgressPerc = Convert.ToInt32(progress); selfWorker.ReportProgress(currProgressPerc); } if (selfWorker.CancellationPending) { return; } #endregion calculate and report progress } lDictionariesConcurrentData.RemoveAll(dict => dict == null); List <ConcurrentData> lConcurrentData = lDictionariesConcurrentData.ConvertAll <ConcurrentData>(dict => { ConcurrentData retVal = null; try { retVal = new ConcurrentData(dict); GPSdata gpsOfGPSstring = new GPSdata((string)dict["GPSdata"], GPSdatasources.CloudCamArduinoGPS, retVal.datetimeUTC.Date); if (!gpsOfGPSstring.validGPSdata) { throw new Exception("invalid GPS data"); } } catch (Exception ex) { string strError = "couldn`t parse XML file " + dict["XMLfileName"] + " : " + Environment.NewLine + ex.Message; return(null); } if (retVal.gps.validGPSdata) { return(retVal); } else { return(null); } }); lConcurrentData.RemoveAll(val => val == null); // map obtained concurrent data to images by its datetime theLogWindow = ServiceTools.LogAText(theLogWindow, "started concurrent data mapping"); int totalrecordsToMap = lSnapshotsInfos.Count; int recordsMapped = 0; currProgressPerc = 0; selfWorker.ReportProgress(0); foreach (FileInfoWithSnapshotDateTime info in lSnapshotsInfos) { DateTime currImgDT = info.dateTime; ConcurrentData nearestConcurrentData = lConcurrentData.Aggregate((cDt1, cDt2) => { TimeSpan tspan1 = new TimeSpan(Math.Abs((cDt1.datetimeUTC - currImgDT).Ticks)); TimeSpan tspan2 = new TimeSpan(Math.Abs((cDt2.datetimeUTC - currImgDT).Ticks)); return((tspan1 <= tspan2) ? (cDt1) : (cDt2)); }); if (new TimeSpan(Math.Abs((nearestConcurrentData.datetimeUTC - currImgDT).Ticks)) <= TimeSpanForConcurrentDataMappingTolerance) { info.concurrentData = nearestConcurrentData; } #region calculate and report progress recordsMapped++; double progress = 100.0d * (double)recordsMapped / (double)totalrecordsToMap; if (progress - (double)currProgressPerc > 1.0d) { currProgressPerc = Convert.ToInt32(progress); selfWorker.ReportProgress(currProgressPerc); } if (selfWorker.CancellationPending) { return; } #endregion calculate and report progress } #endregion read concurrent data from XML files List <FileInfo> filesToMove = new List <FileInfo>(); filesToMove.AddRange( lSnapshotsInfos.Where(inf => inf.concurrentData == null).ToList().ConvertAll(inf => inf.finfo)); lSnapshotsInfos.RemoveAll(inf => inf.concurrentData == null); filesToMove.AddRange(lSnapshotsInfos.Where(inf => { GPSdata currGPS = new GPSdata(inf.concurrentData.GPSdata, GPSdatasources.CloudCamArduinoGPS, inf.dateTime.Date); var spa = currGPS.SunZenithAzimuth(); return(spa.ZenithAngle >= 85.0); }).ToList().ConvertAll(inf => inf.finfo)); totalFilesCountToRead = filesToMove.Count; filesRead = 0; currProgressPerc = 0; selfWorker.ReportProgress(0); foreach (FileInfo inf in filesToMove) { #region calculate and report progress filesRead++; double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead; if (progress - (double)currProgressPerc > 1.0d) { currProgressPerc = Convert.ToInt32(progress); selfWorker.ReportProgress(currProgressPerc); } if (selfWorker.CancellationPending) { return; } #endregion calculate and report progress string strFilenameMoveTo = directoryToMoveFilesTo + ((directoryToMoveFilesTo.Last() == Path.DirectorySeparatorChar) ? ("") : (Path.DirectorySeparatorChar.ToString())); string currImgFilenameRelPath = ConventionalTransitions.MakeRelativePath(inf.FullName, SnapshotsBasePath); strFilenameMoveTo += currImgFilenameRelPath; theLogWindow = ServiceTools.LogAText(theLogWindow, "moving " + inf.FullName); if (!ServiceTools.CheckIfDirectoryExists(strFilenameMoveTo)) { theLogWindow = ServiceTools.LogAText(theLogWindow, "Unable to move file " + Environment.NewLine + inf.FullName + Environment.NewLine + "to:" + Environment.NewLine + strFilenameMoveTo + Environment.NewLine + "Directory couldn`t be located or created"); continue; } File.Move(inf.FullName, strFilenameMoveTo); } selfWorker.ReportProgress(0); }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (File.Exists(defaultPropertiesXMLfileName)) { defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); } bool bDefaultPropertiesHasBeenUpdated = false; if (defaultProperties.ContainsKey("CopyImagesFrom_Path")) { CopyImagesFrom_Path = (string)defaultProperties["CopyImagesFrom_Path"]; } else { CopyImagesFrom_Path = ""; defaultProperties.Add("CopyImagesFrom_Path", CopyImagesFrom_Path); bDefaultPropertiesHasBeenUpdated = true; } ThreadSafeOperations.SetTextTB(rtbFromPath, CopyImagesFrom_Path, false); if (defaultProperties.ContainsKey("CopyImagesAndDataTo_Path")) { CopyImagesAndDataTo_Path = (string)defaultProperties["CopyImagesAndDataTo_Path"]; } else { CopyImagesAndDataTo_Path = ""; defaultProperties.Add("CopyImagesAndDataTo_Path", CopyImagesAndDataTo_Path); bDefaultPropertiesHasBeenUpdated = true; } ThreadSafeOperations.SetTextTB(rtbToPath, CopyImagesAndDataTo_Path, false); if (defaultProperties.ContainsKey("ConcurrentDataXMLfilesPath")) { ConcurrentDataXMLfilesPath = (string)defaultProperties["ConcurrentDataXMLfilesPath"]; } else { ConcurrentDataXMLfilesPath = ""; defaultProperties.Add("ConcurrentDataXMLfilesPath", ConcurrentDataXMLfilesPath); bDefaultPropertiesHasBeenUpdated = true; } ThreadSafeOperations.SetTextTB(rtbConcurrentDataDir, ConcurrentDataXMLfilesPath, false); if (defaultProperties.ContainsKey("GrIxYRGBstatsXMLfilesPath")) { GrIxYRGBstatsXMLfilesPath = (string)defaultProperties["GrIxYRGBstatsXMLfilesPath"]; } else { GrIxYRGBstatsXMLfilesPath = ""; defaultProperties.Add("GrIxYRGBstatsXMLfilesPath", GrIxYRGBstatsXMLfilesPath); bDefaultPropertiesHasBeenUpdated = true; } ThreadSafeOperations.SetTextTB(rtbGrIxYRGBstatsDir, GrIxYRGBstatsXMLfilesPath, false); if (defaultProperties.ContainsKey("filterTolerance")) { filterTolerance = TimeSpan.Parse((string)defaultProperties["filterTolerance"]); } else { defaultProperties.Add("filterTolerance", filterTolerance.ToString()); bDefaultPropertiesHasBeenUpdated = true; } //TimeSpanForConcurrentDataMappingTolerance if (defaultProperties.ContainsKey("TimeSpanForConcurrentDataMappingTolerance")) { TimeSpanForConcurrentDataMappingTolerance = TimeSpan.Parse((string)defaultProperties["TimeSpanForConcurrentDataMappingTolerance"]); } else { TimeSpanForConcurrentDataMappingTolerance = new TimeSpan(0, 0, 30); defaultProperties.Add("TimeSpanForConcurrentDataMappingTolerance", TimeSpanForConcurrentDataMappingTolerance.ToString()); bDefaultPropertiesHasBeenUpdated = true; } if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
//private void ImageProcessing(ImagesProcessingData ipdt) //{ //} private void EnumerateFilesToProcess() { string directory = Path.GetDirectoryName(inputBasePath); string filemask = "*.jpg"; List <string> filesList = new List <string>(Directory.EnumerateFiles(directory, filemask, bEnumerateFilesRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)); #region filter by camID //...devID1.jpg string ptrnCamID = "devid" + CamIDtoProcess + ".jpg"; filesList = filesList.Where(fname => fname.ToLower().Contains(ptrnCamID)).ToList(); #endregion Console.WriteLine("found " + filesList.Count + " images."); #region list, read and map image stats files Console.WriteLine("filtering by ready-to-use GrIxYRGB XML files..."); List <string> statsFilesList = new List <string>(Directory.EnumerateFiles(imageYRGBstatsXMLdataFilesDirectory, ConventionalTransitions.ImageGrIxYRGBstatsFileNamesPattern(), bEnumerateFilesRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)); List <string> statsFilesListWOpath = statsFilesList.ConvertAll(Path.GetFileName); Console.WriteLine("found " + statsFilesList.Count + " XML stats files in directory " + Environment.NewLine + imageYRGBstatsXMLdataFilesDirectory + Environment.NewLine + "by mask " + Environment.NewLine + ConventionalTransitions.ImageGrIxYRGBstatsFileNamesPattern()); int removed = filesList.RemoveAll( fname => !statsFilesListWOpath.Contains(ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(fname, "", false))); Console.WriteLine("removed " + removed + " items (couldn`t find stats data files). Remains " + filesList.Count + " to process."); if (!filesList.Any()) { Console.WriteLine("There is no " + filemask + " files that sutisfy settings specified. Processing will not be started."); return; } lStatsProcessing = filesList.ConvertAll(strImgFname => { ImagesProcessingData retVal = new ImagesProcessingData() { filename = strImgFname }; return(retVal); }); #if DEBUG //lStatsProcessing = lStatsProcessing.Where((ipd, ind) => ind < 10).ToList(); #endif Console.WriteLine("started reading and mapping stats data"); int totalFilesCountToRead = lStatsProcessing.Count; int filesRead = 0; int currProgressPerc = 0; foreach (ImagesProcessingData ipdt in lStatsProcessing) { ipdt.grixyrgbStatsXMLfile = statsFilesList.First( statsFname => statsFname.Contains(ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(ipdt.filename, "", false))); ipdt.grixyrgbStats = ServiceTools.ReadObjectFromXML(ipdt.grixyrgbStatsXMLfile, typeof(SkyImageIndexesStatsData)) as SkyImageIndexesStatsData; #region calculate and report progress filesRead++; double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead; if (progress - (double)currProgressPerc > 1.0d) { currProgressPerc = Convert.ToInt32(progress); Console.WriteLine("read " + currProgressPerc + "%"); } #endregion calculate and report progress } #endregion #region list, read and map concurrent data List <string> concurrentDataFilesList = Directory.EnumerateFiles(ConcurrentDataXMLfilesDirectory, ConventionalTransitions.ImageConcurrentDataFilesNamesPattern(), bEnumerateFilesRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToList(); List <ConcurrentData> lConcurrentData = null; #region reading Console.WriteLine("started concurrent data reading"); totalFilesCountToRead = concurrentDataFilesList.Count; filesRead = 0; currProgressPerc = 0; List <Dictionary <string, object> > lDictionariesConcurrentData = new List <Dictionary <string, object> >(); foreach (string strConcDataXMLFile in concurrentDataFilesList) { Dictionary <string, object> currDict = ServiceTools.ReadDictionaryFromXML(strConcDataXMLFile); currDict.Add("XMLfileName", Path.GetFileName(strConcDataXMLFile)); lDictionariesConcurrentData.Add(currDict); #region calculate and report progress filesRead++; double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead; if (progress - (double)currProgressPerc > 1.0d) { currProgressPerc = Convert.ToInt32(progress); Console.WriteLine("read " + currProgressPerc + "%"); } #endregion calculate and report progress } lDictionariesConcurrentData.RemoveAll(dict => dict == null); lConcurrentData = lDictionariesConcurrentData.ConvertAll <ConcurrentData>(dict => { ConcurrentData retVal = null; try { retVal = new ConcurrentData(dict); } catch (Exception ex) { string strError = "couldn`t parse XML file " + dict["XMLfileName"] + " : " + Environment.NewLine + ex.Message; Console.WriteLine(strError); } return(retVal); }); lConcurrentData.RemoveAll(val => val == null); #endregion reading #region mapping // map obtained concurrent data to images by its datetime Console.WriteLine("concurrent data mapping started"); lStatsProcessing = lStatsProcessing.ConvertAll(ipdt => { string currImgFilename = ipdt.filename; currImgFilename = Path.GetFileNameWithoutExtension(currImgFilename); string ptrn = @"(devID\d)"; Regex rgxp = new Regex(ptrn, RegexOptions.IgnoreCase); string strCurrImgDT = rgxp.Replace(currImgFilename.Substring(4), ""); //2015-12-16T06-01-38 strCurrImgDT = strCurrImgDT.Substring(0, 11) + strCurrImgDT.Substring(11).Replace("-", ":"); DateTime currImgDT = DateTime.Parse(strCurrImgDT, null, System.Globalization.DateTimeStyles.AdjustToUniversal); ConcurrentData nearestConcurrentData = lConcurrentData.Aggregate((cDt1, cDt2) => { TimeSpan tspan1 = new TimeSpan(Math.Abs((cDt1.datetimeUTC - currImgDT).Ticks)); TimeSpan tspan2 = new TimeSpan(Math.Abs((cDt2.datetimeUTC - currImgDT).Ticks)); return((tspan1 <= tspan2) ? (cDt1) : (cDt2)); }); if (new TimeSpan(Math.Abs((nearestConcurrentData.datetimeUTC - currImgDT).Ticks)) >= TimeSpanForConcurrentDataMappingTolerance) { string strError = "couldn`t find close enough concurrent data file for image:" + Environment.NewLine + currImgFilename + Environment.NewLine + "closest concurrent data file is:" + Environment.NewLine + nearestConcurrentData.filename + Environment.NewLine + "with date-time value " + nearestConcurrentData.datetimeUTC.ToString("o"); Console.WriteLine(strError); nearestConcurrentData = null; } ipdt.concurrentData = nearestConcurrentData; if (nearestConcurrentData != null) { ipdt.concurrentDataXMLfile = nearestConcurrentData.filename; } return(ipdt); }); #endregion mapping removed = lStatsProcessing.RemoveAll(ipdt => ipdt.concurrentData == null); Console.WriteLine("removed " + removed + " items (couldn`t find concurrent data). " + lStatsProcessing.Count + " files remains to process."); #endregion list, read and map concurrent data if (!lStatsProcessing.Any()) { Console.WriteLine("There is no files that sutisfy settings specified and have all required concurrent data (stats or GPS etc.). Processing will not be proceeded."); return; } #region Predict SDC values using pre-trained NN parameters string csvHeader = lStatsProcessing[0].grixyrgbStats.CSVHeader() + ",SunElevationDeg,SunAzimuthDeg,sunDiskCondition"; List <string> lCSVheader = csvHeader.Split(',').ToList(); List <int> columnsToDelete = lCSVheader.Select((str, idx) => new Tuple <int, string>(idx, str)) .Where(tpl => tpl.Item2.ToLower().Contains("filename")).ToList().ConvertAll(tpl => tpl.Item1); List <List <string> > lCalculatedData = lStatsProcessing.ConvertAll(dt => { string currImageALLstatsDataCSVWithConcurrentData = dt.grixyrgbStats.ToCSV() + "," + dt.concurrentData.gps.SunZenithAzimuth() .ElevationAngle.ToString() .Replace(",", ".") + "," + dt.concurrentData.gps.SunZenithAzimuth() .Azimuth.ToString() .Replace(",", "."); List <string> retVal = currImageALLstatsDataCSVWithConcurrentData.Split(',').ToList(); retVal = retVal.Where((str, idx) => !columnsToDelete.Contains(idx)).ToList(); return(retVal); }); List <DenseVector> lDV_objects_features = lCalculatedData.ConvertAll( list => DenseVector.OfEnumerable(list.ConvertAll <double>(str => Convert.ToDouble(str.Replace(".", ","))))); DenseVector dvMeans = (DenseVector)((DenseMatrix)ServiceTools.ReadDataFromCSV(NormMeansFile, 0, ",")).Row(0); DenseVector dvRanges = (DenseVector)((DenseMatrix)ServiceTools.ReadDataFromCSV(NormRangeFile, 0, ",")).Row(0); lDV_objects_features = lDV_objects_features.ConvertAll(dv => { DenseVector dvShifted = dv - dvMeans; DenseVector dvNormed = (DenseVector)dvShifted.PointwiseDivide(dvRanges); return(dvNormed); }); DenseMatrix dmObjectsFeatures = DenseMatrix.OfRowVectors(lDV_objects_features); DenseVector dvThetaValues = (DenseVector)ServiceTools.ReadDataFromCSV(NNtrainedParametersFile, 0, ","); List <int> NNlayersConfig = new List <double>(((DenseMatrix)ServiceTools.ReadDataFromCSV(NNconfigFile, 0, ",")).Row(0)).ConvertAll (dVal => Convert.ToInt32(dVal)); List <List <double> > lDecisionProbabilities = null; List <SunDiskCondition> predictedSDClist = NNclassificatorPredictor <SunDiskCondition> .NNpredict(dmObjectsFeatures, dvThetaValues, NNlayersConfig, out lDecisionProbabilities, SunDiskConditionData.MatlabEnumeratedSDCorderedList()).ToList(); //List<SunDiskCondition> predictedSDClist = predictedSDC.ConvertAll(sdcInt => //{ // switch (sdcInt) // { // case 4: // return SunDiskCondition.NoSun; // break; // case 1: // return SunDiskCondition.Sun0; // break; // case 2: // return SunDiskCondition.Sun1; // break; // case 3: // return SunDiskCondition.Sun2; // break; // default: // return SunDiskCondition.Defect; // } //}); string strToShow = "SDC values probabilities: " + Environment.NewLine + "| No Sun | Sun_0 | Sun_1 | Sun_2 | Detected |" + Environment.NewLine; foreach (List <double> lDecisionProbability in lDecisionProbabilities) { strToShow += "| " + lDecisionProbability[3].ToString("F4") + " | " + lDecisionProbability[0].ToString("F4") + " | " + lDecisionProbability[1].ToString("F4") + " | " + lDecisionProbability[2].ToString("F4") + " |" + predictedSDClist[lDecisionProbabilities.IndexOf(lDecisionProbability)] + "|" + Environment.NewLine; } ServiceTools.logToTextFile(errorLogFilename, strToShow, true, false); #endregion //lStatsProcessing = // lStatsProcessing.Where((ipd, idx) => predictedSDClist[idx] == SunDiskCondition.Sun2).ToList(); lStatsProcessing = lStatsProcessing.Where((ipd, idx) => predictedSDClist[idx] == sdcFilter).ToList(); Console.WriteLine("Detected " + lStatsProcessing.Count + " images with SDC = " + sdcFilter.ToString()); if (!lStatsProcessing.Any()) { Console.WriteLine("There is no files with SDC = Sun2. Processing will not be proceeded."); return; } Console.WriteLine("finished enumerating and filtering files. Files to process: " + lStatsProcessing.Count); }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; defaultProperties = new Dictionary <string, object>(); if (File.Exists(defaultPropertiesXMLfileName)) { defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); } bool bDefaultPropertiesHasBeenUpdated = false; string CurDir = Directory.GetCurrentDirectory(); #region inputBasePath if (defaultProperties.ContainsKey("inputBasePath")) { inputBasePath = (string)defaultProperties["inputBasePath"]; } else { inputBasePath = CurDir + Path.DirectorySeparatorChar + "input" + Path.DirectorySeparatorChar; defaultProperties.Add("inputBasePath", inputBasePath); bDefaultPropertiesHasBeenUpdated = true; } #endregion inputBasePath #region OutputDirectory if (defaultProperties.ContainsKey("OutputDirectory")) { strOutputDirectory = ((string)defaultProperties["OutputDirectory"]); } else { strOutputDirectory = CurDir + Path.DirectorySeparatorChar + "output" + Path.DirectorySeparatorChar; defaultProperties.Add("OutputDirectory", strOutputDirectory); bDefaultPropertiesHasBeenUpdated = true; } #endregion OutputDirectory #region NN parameters // NNconfigFile if (defaultProperties.ContainsKey("NNconfigFile")) { NNconfigFile = ((string)defaultProperties["NNconfigFile"]); } else { NNconfigFile = CurDir + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "NNconfig.csv"; defaultProperties.Add("NNconfigFile", NNconfigFile); bDefaultPropertiesHasBeenUpdated = true; } //NNtrainedParametersFile if (defaultProperties.ContainsKey("NNtrainedParametersFile")) { NNtrainedParametersFile = ((string)defaultProperties["NNtrainedParametersFile"]); } else { NNtrainedParametersFile = CurDir + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "NNtrainedParameters.csv"; defaultProperties.Add("NNtrainedParametersFile", NNtrainedParametersFile); bDefaultPropertiesHasBeenUpdated = true; } // NormMeansFile if (defaultProperties.ContainsKey("NormMeansFile")) { NormMeansFile = ((string)defaultProperties["NormMeansFile"]); } else { NormMeansFile = CurDir + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "NormMeans.csv"; defaultProperties.Add("NormMeansFile", NormMeansFile); bDefaultPropertiesHasBeenUpdated = true; } // NormRangeFile if (defaultProperties.ContainsKey("NormRangeFile")) { NormRangeFile = ((string)defaultProperties["NormRangeFile"]); } else { NormRangeFile = CurDir + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "NormRange.csv"; defaultProperties.Add("NormRangeFile", NormRangeFile); bDefaultPropertiesHasBeenUpdated = true; } #endregion NN parameters // StartWithoutConfirmation if (defaultProperties.ContainsKey("StartWithoutConfirmation")) { bStartWithoutConfirmation = ((string)defaultProperties["StartWithoutConfirmation"]).ToLower() == "true"; } //imageYRGBstatsXMLdataFilesDirectory if (defaultProperties.ContainsKey("imageYRGBstatsXMLdataFilesDirectory")) { imageYRGBstatsXMLdataFilesDirectory = (string)defaultProperties["imageYRGBstatsXMLdataFilesDirectory"]; } else { imageYRGBstatsXMLdataFilesDirectory = CurDir; defaultProperties.Add("imageYRGBstatsXMLdataFilesDirectory", imageYRGBstatsXMLdataFilesDirectory); bDefaultPropertiesHasBeenUpdated = true; } //TimeSpanForConcurrentDataMappingTolerance if (defaultProperties.ContainsKey("TimeSpanForConcurrentDataMappingTolerance")) { TimeSpanForConcurrentDataMappingTolerance = TimeSpan.Parse((string)defaultProperties["TimeSpanForConcurrentDataMappingTolerance"]); } else { TimeSpanForConcurrentDataMappingTolerance = new TimeSpan(0, 0, 30); defaultProperties.Add("TimeSpanForConcurrentDataMappingTolerance", TimeSpanForConcurrentDataMappingTolerance.ToString()); bDefaultPropertiesHasBeenUpdated = true; } //ConcurrentDataXMLfilesDirectory if (defaultProperties.ContainsKey("ConcurrentDataXMLfilesDirectory")) { ConcurrentDataXMLfilesDirectory = (string)defaultProperties["ConcurrentDataXMLfilesDirectory"]; } else { ConcurrentDataXMLfilesDirectory = CurDir; defaultProperties.Add("ConcurrentDataXMLfilesDirectory", ConcurrentDataXMLfilesDirectory); bDefaultPropertiesHasBeenUpdated = true; } //IncludeGPSandSunAltitudeData if (defaultProperties.ContainsKey("IncludeGPSandSunAltitudeData")) { bIncludeGPSandSunAltitudeData = (((string)defaultProperties["IncludeGPSandSunAltitudeData"]).ToLower() == "true"); } else { bIncludeGPSandSunAltitudeData = true; defaultProperties.Add("IncludeGPSandSunAltitudeData", bIncludeGPSandSunAltitudeData); bDefaultPropertiesHasBeenUpdated = true; } if (defaultProperties.ContainsKey("ImagesRoundMasksXMLfilesMappingList")) { ImagesRoundMasksXMLfilesMappingList = (string)defaultProperties["ImagesRoundMasksXMLfilesMappingList"]; } else { ImagesRoundMasksXMLfilesMappingList = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "ImagesRoundMasksXMLfilesMappingList.csv"; defaultProperties.Add("ImagesRoundMasksXMLfilesMappingList", ImagesRoundMasksXMLfilesMappingList); bDefaultPropertiesHasBeenUpdated = true; } // maxConcurrentProcessingThreads if (defaultProperties.ContainsKey("maxConcurrentProcessingThreads")) { maxConcurrentProcessingThreads = Convert.ToInt32((string)defaultProperties["maxConcurrentProcessingThreads"]); } else { maxConcurrentProcessingThreads = 8; defaultProperties.Add("maxConcurrentProcessingThreads", maxConcurrentProcessingThreads); bDefaultPropertiesHasBeenUpdated = true; } if (CommonTools.console_present()) { CommonTools.PrintDictionaryToConsole(defaultProperties, "Effective settings."); } if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
/// <summary> /// Reads the default properties. /// </summary> private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (File.Exists(defaultPropertiesXMLfileName)) { defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); } bool bDefaultPropertiesHasBeenUpdated = false; string CurDir = Directory.GetCurrentDirectory(); FilesBasePath = ""; #region FilesBasePath if (defaultProperties.ContainsKey("FilesBasePath")) { FilesBasePath = (string)defaultProperties["FilesBasePath"]; } else { FilesBasePath = CurDir; defaultProperties.Add("FilesBasePath", FilesBasePath); bDefaultPropertiesHasBeenUpdated = true; } #endregion ImagesBasePath #region bSearchFilesTopDirectoryOnly if (defaultProperties.ContainsKey("bSearchFilesTopDirectoryOnly")) { bSearchFilesTopDirectoryOnly = (((string)defaultProperties["bSearchFilesTopDirectoryOnly"]).ToLower() == "true"); } else { bSearchFilesTopDirectoryOnly = false; defaultProperties.Add("bSearchFilesTopDirectoryOnly", bSearchFilesTopDirectoryOnly); bDefaultPropertiesHasBeenUpdated = true; } #endregion #region outputBaseDirectory // outputBaseDirectory if (defaultProperties.ContainsKey("outputBaseDirectory")) { outputBaseDirectory = (string)defaultProperties["outputBaseDirectory"]; } else { outputBaseDirectory = CurDir; defaultProperties.Add("outputBaseDirectory", outputBaseDirectory); bDefaultPropertiesHasBeenUpdated = true; } #endregion outputNetCDFfilesDirectory #region OutputSubdirectoriesPrefix //OutputSubdirectoriesPrefix if (defaultProperties.ContainsKey("OutputSubdirectoriesPrefix")) { OutputSubdirectoriesPrefix = (string)defaultProperties["OutputSubdirectoriesPrefix"]; } else { OutputSubdirectoriesPrefix = ""; defaultProperties.Add("OutputSubdirectoriesPrefix", OutputSubdirectoriesPrefix); bDefaultPropertiesHasBeenUpdated = true; } #endregion if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (File.Exists(defaultPropertiesXMLfileName)) { defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); } bool bDefaultPropertiesHasBeenUpdated = false; string CurDir = Directory.GetCurrentDirectory(); ImagesBasePath = ""; #region ImagesBasePath if (defaultProperties.ContainsKey("ImagesBasePath")) { ImagesBasePath = (string)defaultProperties["ImagesBasePath"]; } else { ImagesBasePath = CurDir; defaultProperties.Add("ImagesBasePath", ImagesBasePath); bDefaultPropertiesHasBeenUpdated = true; } #endregion ImagesBasePath #region SearchImagesTopDirectoryOnly if (defaultProperties.ContainsKey("SearchImagesTopDirectoryOnly")) { bSearchImagesTopDirectoryOnly = (((string)defaultProperties["SearchImagesTopDirectoryOnly"]).ToLower() == "true"); } else { bSearchImagesTopDirectoryOnly = false; defaultProperties.Add("SearchImagesTopDirectoryOnly", bSearchImagesTopDirectoryOnly); bDefaultPropertiesHasBeenUpdated = true; } #endregion #region imageYRGBstatsXMLdataFilesDirectory // imageYRGBstatsXMLdataFilesDirectory if (defaultProperties.ContainsKey("imageYRGBstatsXMLdataFilesDirectory")) { imageYRGBstatsXMLdataFilesDirectory = (string)defaultProperties["imageYRGBstatsXMLdataFilesDirectory"]; } else { imageYRGBstatsXMLdataFilesDirectory = CurDir; defaultProperties.Add("imageYRGBstatsXMLdataFilesDirectory", imageYRGBstatsXMLdataFilesDirectory); bDefaultPropertiesHasBeenUpdated = true; } #endregion imageYRGBstatsXMLdataFilesDirectory #region outputNetCDFfilesDirectory // outputNetCDFfilesDirectory if (defaultProperties.ContainsKey("outputNetCDFfilesDirectory")) { outputNetCDFfilesDirectory = (string)defaultProperties["outputNetCDFfilesDirectory"]; } else { outputNetCDFfilesDirectory = CurDir; defaultProperties.Add("outputNetCDFfilesDirectory", outputNetCDFfilesDirectory); bDefaultPropertiesHasBeenUpdated = true; } #endregion outputNetCDFfilesDirectory #region ImagesRoundMasksXMLfilesMappingList if (defaultProperties.ContainsKey("ImagesRoundMasksXMLfilesMappingList")) { ImagesRoundMasksXMLfilesMappingList = (string)defaultProperties["ImagesRoundMasksXMLfilesMappingList"]; } else { ImagesRoundMasksXMLfilesMappingList = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "ImagesRoundMasksXMLfilesMappingList.csv"; defaultProperties.Add("ImagesRoundMasksXMLfilesMappingList", ImagesRoundMasksXMLfilesMappingList); bDefaultPropertiesHasBeenUpdated = true; } #endregion ImagesRoundMasksXMLfilesMappingList #region strPerformanceCountersStatsFile if (defaultProperties.ContainsKey("strPerformanceCountersStatsFile")) { strPerformanceCountersStatsFile = (string)defaultProperties["strPerformanceCountersStatsFile"]; } else { strPerformanceCountersStatsFile = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-perf-data.csv"; defaultProperties.Add("strPerformanceCountersStatsFile", strPerformanceCountersStatsFile); bDefaultPropertiesHasBeenUpdated = true; } #endregion strPerformanceCountersStatsFile if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }
private void readDefaultProperties() { defaultProperties = new Dictionary <string, object>(); defaultPropertiesXMLfileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + "-Settings.xml"; if (File.Exists(defaultPropertiesXMLfileName)) { defaultProperties = ServiceTools.ReadDictionaryFromXML(defaultPropertiesXMLfileName); } bool bDefaultPropertiesHasBeenUpdated = false; string CurDir = Directory.GetCurrentDirectory(); // NNconfigFile if (defaultProperties.ContainsKey("NNconfigFile")) { NNconfigFile = ((string)defaultProperties["NNconfigFile"]); } else { NNconfigFile = CurDir + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "NNconfig.csv"; defaultProperties.Add("NNconfigFile", NNconfigFile); bDefaultPropertiesHasBeenUpdated = true; } //NNtrainedParametersFile if (defaultProperties.ContainsKey("NNtrainedParametersFile")) { NNtrainedParametersFile = ((string)defaultProperties["NNtrainedParametersFile"]); } else { NNtrainedParametersFile = CurDir + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "NNtrainedParameters.csv"; defaultProperties.Add("NNtrainedParametersFile", NNtrainedParametersFile); bDefaultPropertiesHasBeenUpdated = true; } // NormMeansFile if (defaultProperties.ContainsKey("NormMeansFile")) { NormMeansFile = ((string)defaultProperties["NormMeansFile"]); } else { NormMeansFile = CurDir + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "NormMeans.csv"; defaultProperties.Add("NormMeansFile", NormMeansFile); bDefaultPropertiesHasBeenUpdated = true; } // NormRangeFile if (defaultProperties.ContainsKey("NormRangeFile")) { NormRangeFile = ((string)defaultProperties["NormRangeFile"]); } else { NormRangeFile = CurDir + Path.DirectorySeparatorChar + "settings" + Path.DirectorySeparatorChar + "NormRange.csv"; defaultProperties.Add("NormRangeFile", NormRangeFile); bDefaultPropertiesHasBeenUpdated = true; } if (bDefaultPropertiesHasBeenUpdated) { saveDefaultProperties(); } }