Exemple #1
0
        public override void Execute(MeterDataSet meterDataSet)
        {
            Log.Info("Executing operation to load trending summary data into the openHistorian...");

            using (Historian historian = new Historian(m_historianSettings.Server, m_historianSettings.InstanceName))
            {
                Dictionary <Channel, List <TrendingDataSummaryResource.TrendingDataSummary> > trendingDataSummaries = meterDataSet.GetResource <TrendingDataSummaryResource>().TrendingDataSummaries;

                foreach (KeyValuePair <Channel, List <TrendingDataSummaryResource.TrendingDataSummary> > channelSummaries in trendingDataSummaries)
                {
                    // Reduce data set to valid summaries
                    IEnumerable <TrendingDataSummaryResource.TrendingDataSummary> validSummaries = channelSummaries.Value.Where(summary => summary.IsValid);
                    int channelID = channelSummaries.Key.ID;

                    foreach (TrendingDataSummaryResource.TrendingDataSummary summary in validSummaries)
                    {
                        // Write minimum series value
                        if (!summary.IsDuplicate)
                        {
                            historian.Write(channelID, SeriesID.Minimum, summary.Time, summary.Minimum);
                        }

                        // Write maximum series value
                        if (!summary.IsDuplicate)
                        {
                            historian.Write(channelID, SeriesID.Maximum, summary.Time, summary.Maximum);
                        }

                        // Write average series value
                        if (!summary.IsDuplicate)
                        {
                            historian.Write(channelID, SeriesID.Average, summary.Time, summary.Average);
                        }
                    }
                }

                // Wait for queue
                // to be processed
                historian.Flush();
            }
        }
Exemple #2
0
        public override void Execute(MeterDataSet meterDataSet)
        {
            Log.Info("Executing operation to load trending summary data into the openHistorian...");

            ImportedMeasurementsTable importedMeasurementsTable = null;

            if ((m_historianSettings.SecurePassword?.Length ?? 0) > 0)
            {
                string url      = m_historianSettings.URL;
                string username = m_historianSettings.InstanceName;
                string password = m_historianSettings.Password;
                importedMeasurementsTable = new ImportedMeasurementsTable(url, username, password);
            }

            using (Historian historian = new Historian(m_historianSettings.Server, m_historianSettings.InstanceName))
            {
                Dictionary <Channel, List <TrendingDataSummaryResource.TrendingDataSummary> > trendingDataSummaries = meterDataSet.GetResource <TrendingDataSummaryResource>().TrendingDataSummaries;

                // Import measurement metadata into the historian metadata container
                if ((object)importedMeasurementsTable != null)
                {
                    List <ImportedMeasurement> measurements = new List <ImportedMeasurement>();

                    foreach (Channel channel in trendingDataSummaries.Keys)
                    {
                        int channelID = channel.ID;

                        foreach (SeriesID seriesID in Enum.GetValues(typeof(SeriesID)))
                        {
                            long pointID = ToPointID(channelID, seriesID);
                            ImportedMeasurement measurement = importedMeasurementsTable.FindByID(pointID).FirstOrDefault();

                            if ((object)measurement == null)
                            {
                                Func <string, int, string> truncate = (str, len) => (str.Length > len) ? str.Substring(0, len) : str;

                                Meter         meter         = meterDataSet.Meter;
                                MeterLocation meterLocation = meter.MeterLocation;

                                string measurementType           = channel.MeasurementType.Name;
                                string measurementCharacteristic = channel.MeasurementCharacteristic.Name;
                                string phase      = channel.Phase.Name;
                                string seriesType = seriesID.ToString();

                                string pointTag          = $"{meter.AssetKey}:{measurementCharacteristic}";
                                string alternateTag      = channel.Name;
                                string signalTypeAcronym = measurementCharacteristic.ToUpper();
                                string signalReference   = $"{meter.AssetKey}-{measurementCharacteristic}";

                                measurement = new ImportedMeasurement()
                                {
                                    SignalID          = Guid.NewGuid(),
                                    PointID           = pointID,
                                    PointTag          = truncate($"{meter.AssetKey}:{measurementCharacteristic}", 200),
                                    AlternateTag      = truncate(channel.Name, 200),
                                    SignalTypeAcronym = truncate(measurementCharacteristic, 4).ToUpper(),
                                    SignalReference   = truncate($"{meter.AssetKey}-{measurementCharacteristic}", 200),
                                    ProtocolAcronym   = "TREND",
                                    ProtocolType      = "Trending",
                                    Phase             = phase[0],
                                    Description       = $"{seriesType} {measurementCharacteristic} ({phase} {measurementType})",
                                    Enabled           = true
                                };

                                if (meterLocation.Latitude != 0.0D && meterLocation.Longitude != 0.0D)
                                {
                                    measurement.Longitude = meterLocation.Longitude;
                                    measurement.Latitude  = meterLocation.Latitude;
                                }

                                measurements.Add(measurement);
                            }
                        }
                    }

                    importedMeasurementsTable.ImportMeasurements(measurements);
                }

                foreach (KeyValuePair <Channel, List <TrendingDataSummaryResource.TrendingDataSummary> > channelSummaries in trendingDataSummaries)
                {
                    // Reduce data set to valid summaries
                    IEnumerable <TrendingDataSummaryResource.TrendingDataSummary> validSummaries = channelSummaries.Value.Where(summary => summary.IsValid);
                    int channelID = channelSummaries.Key.ID;

                    foreach (TrendingDataSummaryResource.TrendingDataSummary summary in validSummaries)
                    {
                        // Write minimum series value
                        if (!summary.IsDuplicate)
                        {
                            historian.Write(channelID, SeriesID.Minimum, summary.Time, summary.Minimum);
                        }

                        // Write maximum series value
                        if (!summary.IsDuplicate)
                        {
                            historian.Write(channelID, SeriesID.Maximum, summary.Time, summary.Maximum);
                        }

                        // Write average series value
                        if (!summary.IsDuplicate)
                        {
                            historian.Write(channelID, SeriesID.Average, summary.Time, summary.Average);
                        }
                    }
                }

                // Wait for queue
                // to be processed
                historian.Flush();
            }
        }