示例#1
0
        private DataToBeWritten _convertDataToBeWritten(List <Signal> signals)
        {
            DataToBeWritten data = new DataToBeWritten();

            if (signals.Count != 0)
            {
                var firstTimeStamp = DateTime.FromOADate(signals.FirstOrDefault().TimeStampNumber.FirstOrDefault()).ToString(@"yyyyMMdd_HHmmss");
                var firstDateTime  = DateTime.ParseExact(firstTimeStamp, "yyyyMMdd_HHmmss", null, System.Globalization.DateTimeStyles.None).ToOADate();// - new DateTime(0001, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                var timeArr        = signals.FirstOrDefault().TimeStampNumber.ToArray();
                //var firstTimeStamp2 = DateTime.FromOADate(InputSignals.FirstOrDefault().TimeStampNumber.FirstOrDefault()).ToString(@"yyyyMMdd_HHmmss.ffffff");
                //Data = Matrix<double>.Build.Dense(timeArr.Count(), 1, (i, j) => (double)i / (double)InputSignals.FirstOrDefault().SamplingRate);
                data.Data = Matrix <double> .Build.Dense(timeArr.Count(), 1, (i, j) => (timeArr[i] - firstDateTime) * 86400);

                var orderedSignal = signals.OrderBy(x => x.PMUName);
                foreach (var signal in orderedSignal)
                {
                    data.NameRowList.Add(signal.SignalName);
                    data.TypeRowList.Add(_typeConverter(signal.TypeAbbreviation));
                    _unitConverter(signal.Data, signal.Unit, out Vector <double> dataInVector, out string unit);
                    data.UnitRowList.Add(unit);
                    data.PMUList.Add(signal.PMUName);
                    data.Data = data.Data.InsertColumn(data.Data.ColumnCount, dataInVector);
                }
            }
            return(data);
        }
示例#2
0
        public void WriteJSISCSV(List <Signal> signals, string filename)
        {
            var dir = Path.GetDirectoryName(filename);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            DataToBeWritten data = _convertDataToBeWritten(signals);

            using (StreamWriter outputFile = new StreamWriter(filename))
            {
                outputFile.WriteLine(String.Join(",", data.NameRowList));
                outputFile.WriteLine(String.Join(",", data.TypeRowList));
                outputFile.WriteLine(String.Join(",", data.UnitRowList));
                outputFile.WriteLine(String.Join(",", data.PMUList));
                for (int index = 0; index < data.Data.RowCount; index++)
                {
                    outputFile.WriteLine(string.Join(",", data.Data.Row(index).ToArray()));
                }
            }
        }