Inheritance: INotifyPropertyChanging, INotifyPropertyChanged
Ejemplo n.º 1
0
        public static void Write(Meter meter, DataGroup waveFormData, FaultLocationData.FaultCurveDataTable faultCurveTable, List<FaultSegment> segments, string originalFilePath, string filePath)
        {
            List<DataSeries> waveFormSeriesList = GetWaveFormSeriesList(waveFormData);
            DataGroup faultLocationData = GetFaultLocationData(meter, faultCurveTable);

            string absoluteFilePath = FilePath.GetAbsolutePath(filePath);

            using (StreamWriter fileStream = new StreamWriter(File.OpenWrite(absoluteFilePath)))
            {
                string originalDirectory;
                string originalRootFileName;
                string originalSchemaFilePath;
                string absoluteOriginalFilePath;
                Schema originalSchema = null;

                string headerRow;

                absoluteOriginalFilePath = FilePath.GetAbsolutePath(originalFilePath);

                if (File.Exists(absoluteOriginalFilePath))
                {
                    originalDirectory = FilePath.GetDirectoryName(absoluteOriginalFilePath);
                    originalRootFileName = FilePath.GetFileNameWithoutExtension(originalFilePath);
                    originalSchemaFilePath = Path.Combine(originalDirectory, originalRootFileName + ".cfg");
                    originalSchema = new Schema(originalSchemaFilePath);
                }

                headerRow = waveFormData.DataSeries
                    .Select(series => GetOriginalChannelName(originalSchema, series))
                    .Concat(faultCurveTable.Select(row => string.Format("Fault Location ({0} Algorithm)", row.Algorithm)))
                    .Aggregate("Time", (s, s1) => s + "," + s1);

                fileStream.WriteLine(headerRow);

                for (int i = 0; i < waveFormData.Samples; i++)
                {
                    DateTime time = waveFormSeriesList[0].DataPoints[i].Time;

                    double[] values = waveFormSeriesList
                        .Select(series => series.DataPoints[i].Value)
                        .Concat(faultLocationData.DataSeries.Select(series => series.DataPoints.Count > i ? series.DataPoints[i].Value : 0.0D))
                        .ToArray();

                    fileStream.WriteLine(values.Aggregate(time.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), (s, d) => s + "," + d));
                }
            }
        }
Ejemplo n.º 2
0
        private static Meter ParseDataSource(DataSourceRecord dataSource)
        {
            Meter meter;
            MeterLocation meterLocation;

            string name = dataSource.DataSourceName;
            Guid vendorID = dataSource.VendorID;
            Guid equipmentID = dataSource.EquipmentID;

            meter = new Meter();
            meter.Name = name;
            meter.AssetKey = name;
            meter.ShortName = name.Substring(0, Math.Min(name.Length, 50));

            meterLocation = new MeterLocation();
            meterLocation.AssetKey = meter.Name;
            meterLocation.Name = string.Format("{0} location", meter.Name);
            meterLocation.ShortName = meterLocation.Name.Substring(0, Math.Min(meterLocation.Name.Length, 50));
            meterLocation.Description = meterLocation.Name;

            if (vendorID != Vendor.None)
                meter.Make = Vendor.ToString(vendorID);

            if (equipmentID != Guid.Empty)
                meter.Model = Equipment.ToString(equipmentID);

            return meter;
        }
 public DataGroup ToDataGroup(Meter meter, byte[] data)
 {
     DataGroup dataGroup = new DataGroup();
     dataGroup.FromData(meter, data);
     return dataGroup;
 }
 partial void DeleteMeter(Meter instance);
 partial void UpdateMeter(Meter instance);
 partial void InsertMeter(Meter instance);
		private void detach_Meters(Meter entity)
		{
			this.SendPropertyChanging();
			entity.MeterLocation = null;
		}
		private void attach_Meters(Meter entity)
		{
			this.SendPropertyChanging();
			entity.MeterLocation = this;
		}
Ejemplo n.º 9
0
        private static DataGroup GetFaultLocationData(Meter meter, FaultLocationData.FaultCurveDataTable faultCurveTable)
        {
            DataGroup faultLocationData = new DataGroup();
            DataGroup parsedGroup = new DataGroup();

            foreach (FaultLocationData.FaultCurveRow faultCurveRow in faultCurveTable)
            {
                parsedGroup.FromData(meter, faultCurveRow.Data);

                foreach (DataSeries series in parsedGroup.DataSeries)
                    faultLocationData.Add(series);
            }

            return faultLocationData;
        }
Ejemplo n.º 10
0
        // Static Methods
        private static Series GetSeriesInfo(MeterInfoDataContext meterInfo, Meter meter, DataGroup dataGroup, string measurementTypeName, string phaseName)
        {
            int lineID;
            string measurementCharacteristicName;
            string seriesTypeName;

            char typeDesignation;
            char phaseDesignation;
            string channelName;

            DataContextLookup<ChannelKey, Channel> channelLookup;
            DataContextLookup<SeriesKey, Series> seriesLookup;
            DataContextLookup<string, MeasurementType> measurementTypeLookup;
            DataContextLookup<string, MeasurementCharacteristic> measurementCharacteristicLookup;
            DataContextLookup<string, Phase> phaseLookup;
            DataContextLookup<string, SeriesType> seriesTypeLookup;

            ChannelKey channelKey;
            SeriesKey seriesKey;

            lineID = dataGroup.Line.ID;
            measurementCharacteristicName = "Instantaneous";
            seriesTypeName = "Values";

            typeDesignation = (measurementTypeName == "Current") ? 'I' : measurementTypeName[0];
            phaseDesignation = (phaseName == "RES") ? 'R' : phaseName[0];
            channelName = string.Concat(typeDesignation, phaseDesignation);

            channelLookup = new DataContextLookup<ChannelKey, Channel>(meterInfo, channel => new ChannelKey(channel))
                .WithFilterExpression(channel => channel.MeterID == meter.ID)
                .WithFilterExpression(channel => channel.LineID == dataGroup.Line.ID);

            seriesLookup = new DataContextLookup<SeriesKey, Series>(meterInfo, series => new SeriesKey(series))
                .WithFilterExpression(series => series.Channel.Meter.ID == meter.ID)
                .WithFilterExpression(series => series.Channel.Line.ID == dataGroup.Line.ID);

            measurementTypeLookup = new DataContextLookup<string, MeasurementType>(meterInfo, measurementType => measurementType.Name);
            measurementCharacteristicLookup = new DataContextLookup<string, MeasurementCharacteristic>(meterInfo, measurementCharacteristic => measurementCharacteristic.Name);
            phaseLookup = new DataContextLookup<string, Phase>(meterInfo, phase => phase.Name);
            seriesTypeLookup = new DataContextLookup<string, SeriesType>(meterInfo, seriesType => seriesType.Name);

            channelKey = new ChannelKey(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName);
            seriesKey = new SeriesKey(channelKey, seriesTypeName);

            return seriesLookup.GetOrAdd(seriesKey, key =>
            {
                SeriesType seriesType = seriesTypeLookup.GetOrAdd(key.SeriesType, name => new SeriesType() { Name = name, Description = name });

                Channel channel = channelLookup.GetOrAdd(channelKey, chKey =>
                {
                    MeasurementType measurementType = measurementTypeLookup.GetOrAdd(chKey.MeasurementType, name => new MeasurementType() { Name = name, Description = name });
                    MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(chKey.MeasurementCharacteristic, name => new MeasurementCharacteristic() { Name = name, Description = name });
                    Phase phase = phaseLookup.GetOrAdd(chKey.Phase, name => new Phase() { Name = name, Description = name });

                    return new Channel()
                    {
                        Meter = meter,
                        Line = dataGroup.Line,
                        MeasurementType = measurementType,
                        MeasurementCharacteristic = measurementCharacteristic,
                        Phase = phase,
                        Name = chKey.Name,
                        SamplesPerHour = dataGroup.SamplesPerHour,
                        PerUnitValue = 0,
                        HarmonicGroup = 0,
                        Description = string.Concat(measurementCharacteristic.Name, " ", measurementType.Name, " ", phase.Name),
                        Enabled = 1
                    };
                });

                return new Series()
                {
                    SeriesType = seriesType,
                    Channel = channel,
                    SourceIndexes = string.Empty
                };
            });
        }