public void PushDataTo(CycleDataSet cycleDataSet) { CycleData cycleData; Cycle[] cycles; CycleDataGroup[] cycleDataGroups; cycleDataGroups = new CycleDataGroup[] { VA, VB, VC, IA, IB, IC }; cycles = new Cycle[cycleDataGroups.Length]; for (int i = 0; i < VA.ToDataGroup().Samples; i++) { cycleData = new CycleData(); cycles[0] = cycleData.AN.V; cycles[1] = cycleData.BN.V; cycles[2] = cycleData.CN.V; cycles[3] = cycleData.AN.I; cycles[4] = cycleData.BN.I; cycles[5] = cycleData.CN.I; for (int j = 0; j < cycles.Length; j++) { cycles[j].RMS = cycleDataGroups[j].RMS[i].Value; cycles[j].Phase = cycleDataGroups[j].Phase[i].Value; cycles[j].Peak = cycleDataGroups[j].Peak[i].Value; cycles[j].Error = cycleDataGroups[j].Error[i].Value; } cycleDataSet[i] = cycleData; } }
private void ProcessFile(string fileName) { DateTime timeStarted; DateTime timeProcessed; string rootFileName; ICollection <Device> devices; FaultLocationDataSet faultDataSet; Device disturbanceRecorder; ICollection <DisturbanceFile> disturbanceFiles; ICollection <Tuple <Line, FaultLocationDataSet> > lineDataSets; List <double> largestCurrentDistances; List <double> boundedDistances; timeStarted = DateTime.UtcNow; m_currentLogger = null; rootFileName = null; try { rootFileName = FilePath.GetFileNameWithoutExtension(fileName); if (m_debugLevel >= 1) { m_currentLogger = Logger.Open(string.Format("{0}{1}.log", m_debugFolder, rootFileName)); } OnStatusMessage(string.Format("Processing {0}...", fileName)); // Make sure device definitions exist, and attempt to load them if they don't devices = m_devices; if ((object)devices == null) { devices = CreateDevices(m_deviceDefinitionsFile); foreach (IFaultResultsWriter resultsWriter in m_resultsWriters.Adapters) { if (resultsWriter.Enabled) { TryWriteConfiguration(resultsWriter, devices); } } m_devices = devices; } // Get the definition for the device that captured this event disturbanceRecorder = GetDevice(devices, rootFileName); disturbanceFiles = CreateDisturbanceFiles(rootFileName); lineDataSets = new Collection <Tuple <Line, FaultLocationDataSet> >(); if ((object)disturbanceRecorder == null) { throw new InvalidOperationException(string.Format("No device record found for \"{0}\" in configuration.", fileName)); } foreach (Line line in disturbanceRecorder.Lines) { try { // Provide status information about which line is being processed OnStatusMessage("Detecting faults on line {0}...", line.Name); // Get the fault data set for this line faultDataSet = GetFaultDataSet(fileName, line); // Get the maximum rated current from the line definition faultDataSet.RatedCurrent = line.Rating50F; // Export data to CSV for validation if (m_debugLevel >= 1) { MeasurementDataSet.ExportToCSV(FilePath.GetAbsolutePath(string.Format("{0}{1}.{2}_measurementData.csv", m_debugFolder, rootFileName, line.ID)), faultDataSet.Voltages, faultDataSet.Currents); CycleDataSet.ExportToCSV(FilePath.GetAbsolutePath(string.Format("{0}{1}.{2}_cycleData.csv", m_debugFolder, rootFileName, line.ID)), faultDataSet.Cycles); } // Run fault trigger, type, and location algorithms if (ExecuteFaultTriggerAlgorithm(line.FaultAlgorithmsSet.FaultTriggerAlgorithm, faultDataSet, line.FaultAlgorithmsSet.FaultTriggerParameters)) { faultDataSet.FaultType = ExecuteFaultTypeAlgorithm(line.FaultAlgorithmsSet.FaultTypeAlgorithm, faultDataSet, line.FaultAlgorithmsSet.FaultTypeParameters); faultDataSet.FaultDistances = line.FaultAlgorithmsSet.FaultLocationAlgorithms.ToDictionary(algorithm => algorithm.Method.Name, algorithm => ExecuteFaultLocationAlgorithm(algorithm, faultDataSet, null)); // Get the set of distance calculations for the cycle with the largest current largestCurrentDistances = faultDataSet.FaultDistances.Values .Select(distances => distances[faultDataSet.Cycles.GetLargestCurrentIndex()]) .OrderBy(dist => dist) .ToList(); // Filter the set down to the distance values that are reasonable boundedDistances = largestCurrentDistances .Where(dist => dist >= 0.0D && dist <= faultDataSet.LineDistance) .ToList(); // Get the representative fault distance as the median of the bounded distances, // falling back on the median of the unbounded distances if there are no bounded ones faultDataSet.FaultDistance = (boundedDistances.Count > 0) ? boundedDistances[boundedDistances.Count / 2] : largestCurrentDistances[largestCurrentDistances.Count / 2]; OnStatusMessage("Distance to fault: {0} {1}", faultDataSet.FaultDistance, m_lengthUnits); // Add the line-specific parameters to the faultResultsWriter lineDataSets.Add(Tuple.Create(line, faultDataSet)); } else { OnStatusMessage("No fault detected."); } } catch (Exception ex) { string message = string.Format("Error detecting faults on line {0}: {1}", line.Name, ex.Message); OnProcessException(new Exception(message, ex)); } } try { // Write results to the output source if (lineDataSets.Count > 0) { timeProcessed = DateTime.UtcNow; foreach (DisturbanceFile disturbanceFile in disturbanceFiles) { disturbanceFile.FLETimeStarted = timeStarted; disturbanceFile.FLETimeProcessed = timeProcessed; } foreach (IFaultResultsWriter resultsWriter in m_resultsWriters.Adapters) { if (resultsWriter.Enabled) { TryWriteResults(resultsWriter, disturbanceRecorder, disturbanceFiles, lineDataSets); } } } } catch (Exception ex) { string errorMessage = string.Format("Unable to write results for file \"{0}\" due to exception: {1}", fileName, ex.Message); OnProcessException(new InvalidOperationException(errorMessage, ex)); } } catch (Exception ex) { string errorMessage = string.Format("Unable to process file \"{0}\" due to exception: {1}", fileName, ex.Message); OnProcessException(new InvalidOperationException(errorMessage, ex)); } try { if ((object)m_currentLogger != null) { m_currentLogger.Close(); m_currentLogger = null; } } catch (Exception ex) { OnProcessException(ex); } try { if ((object)rootFileName != null) { // Get a list of processed files based on file prefix List <string> processedFiles = FilePath.GetFileList(string.Format("{0}{1}.*", m_dropFolder, rootFileName)) .Concat(FilePath.GetFileList(string.Format("{0}{1}_*", m_dropFolder, rootFileName))) .ToList(); // Delete processed files from the drop folder foreach (string file in processedFiles) { File.Delete(file); } } } catch (Exception ex) { OnProcessException(ex); } OnStatusMessage(""); }
/// <summary> /// Creates a new instance of the <see cref="FaultLocationDataSet"/> class. /// </summary> public FaultLocationDataSet() { m_voltages = new MeasurementDataSet(); m_currents = new MeasurementDataSet(); m_cycles = new CycleDataSet(); m_frequency = 60.0D; m_values = new Dictionary<string, object>(); }