public static PairedData CreatePairedData(int numberOfCurves, int numberOfVals)
        {
            List <double>         ordinates = new List <double>();
            List <List <double> > temp      = new List <List <double> >();
            List <double[]>       vals      = new List <double[]>();

            for (int i = 0; i < numberOfCurves; i++)
            {
                temp.Add(new List <double>());
            }
            for (int i = 0; i < numberOfVals; i++)
            {
                ordinates.Add(i + 3);
            }
            for (int i = 0; i < numberOfCurves; i++)
            {
                for (int j = 0; j < numberOfVals; j++)
                {
                    temp[i].Add(j * i);
                }
            }
            for (int i = 0; i < numberOfCurves; i++)
            {
                vals.Add(temp[i].ToArray());
            }

            var pd = new PairedData(ordinates.ToArray(), vals);

            pd.Path             = new DssPath("a", "b", "c", "", "e", "f");
            pd.UnitsIndependent = "unit 1";
            pd.UnitsDependent   = "unit 2";
            pd.TypeIndependent  = "type 1";
            pd.TypeDependent    = "type 2";
            return(pd);
        }
        public void WritePairedData()
        {
            var fn = "test_write_paired_data.dss";

            File.Delete(fn);
            using (var w = new DssWriter(fn))
            {
                var x = new double[] { 1.0, 2.0, 3.0 };
                var y = new double[] { 10.0, 20.0, 30.0 };

                PairedData pd = new PairedData();
                pd.Ordinates = x;
                pd.Values    = new List <double[]>();
                pd.Values.Add(y);


                PairedData pd2 = new PairedData(
                    new double[] { 1.0, 2.0, 3.0 }, new double[] { 10.0, 20.0, 30.0 });

                var myList = new List <double[]>(3);
                myList.Add(new double[] { 10.0, 20.0, 30.0 });
                myList.Add(new double[] { 100.0, 200.0, 300.0 });
                myList.Add(new double[] { 1000.0, 2000.0, 3000.0 });

                PairedData pd3 = new PairedData(new double[] { 1.0, 2.0, 3.0 }, myList, new List <string>(), "", "", "", "", "/a/b/stage-flow//e/f/");

                w.Write(pd3);
            }
        }
Пример #3
0
 public void Write(PairedData record, string sheet)
 {
     if (!SheetExists(sheet))
     {
         AddSheet(sheet);
     }
     ClearSheet(sheet);
     SetPathInExcelFile(sheet, record.Path);
     SetUnitsAndDataTypeInExcelFile(sheet, record);
     SetOrdinateColumnInExcelFile(sheet, record, (int)PathLayout.StandardPath + (int)UnitsAndTypes.PD_UnitsAndTypes, 0);
     SetPairedDataValueColumnsInExcelFile(sheet, record, (int)PathLayout.StandardPath + (int)UnitsAndTypes.PD_UnitsAndTypes, 1);
     if (workbook.FullName.EndsWith(".xls"))
     {
         workbook.SaveAs(workbook.FullName, FileFormat.Excel8);
     }
     else if (workbook.FullName.EndsWith(".xlsx"))
     {
         workbook.SaveAs(workbook.FullName, FileFormat.OpenXMLWorkbook);
     }
     else
     {
         var name = Path.GetDirectoryName(workbook.FullName) + "\\" +
                    Path.GetFileNameWithoutExtension(workbook.FullName) + ".xlsx";
         workbook.SaveAs(name, FileFormat.OpenXMLWorkbook);
     }
 }
Пример #4
0
        private void ViewCatalogSelection(object sender, RoutedEventArgs e)
        {
            if (!_canExecute())
            {
                return;
            }

            DssPath           dssPath = (DssPath)dataGrid.SelectedItem;
            DssCatalogTableVM catalog = (DssCatalogTableVM)DataContext;

            if (dssPath.RecordType == RecordType.RegularTimeSeries || dssPath.RecordType == RecordType.IrregularTimeSeries)
            {
                TimeSeries       ts       = catalog.File.GetTimeSeries(dssPath, compression: catalogProperties.compression);
                TimeSeriesWindow tsWindow = new TimeSeriesWindow(ts, catalogProperties, dssFile);
                tsWindow.DisableEditFeatures();
                tsWindow.Show();
            }
            else if (dssPath.RecordType == RecordType.PairedData)
            {
                PairedData       pd       = catalog.File.GetPairedData(dssPath);
                PairedDataWindow pdWindow = new PairedDataWindow(pd, catalogProperties, dssFile);
                pdWindow.DisableEditFeatures();
                pdWindow.Show();
            }
            else if (dssPath.RecordType == RecordType.LocationInfo)
            {
                LocationInformation li       = catalog.File.GetLocationInformation(dssPath);
                LocationInfoWindow  liWindow = new LocationInfoWindow(li, catalogProperties);
                liWindow.Show();
            }
        }
Пример #5
0
 private void SetOrdinateColumnInExcelFile(string sheet, PairedData record, int rowOffset, int colOffset)
 {
     workbook.Worksheets[sheet].Cells[rowOffset, colOffset].Value = "Ordinates";
     for (int i = 0 + rowOffset + 1; i < record.Ordinates.Length + rowOffset + 1; i++)
     {
         workbook.Worksheets[sheet].Cells[i, colOffset].Value = record.Ordinates[i - rowOffset - 1];
     }
 }
 public DssDataTableVM(PairedData pd, CatalogProperties catalogProperties)
 {
     Record             = pd;
     _catalogProperties = catalogProperties;
     _table             = pd.ToDataTable();
     RoundValues(pd, catalogProperties);
     NotifyPropertyChanged(nameof(Table));
 }
        public PairedDataWindow(PairedData pd, CatalogProperties catalogProperties, DssFile dssFile)
        {
            InitializeComponent();
            DataContext = new DssDataTableVM(pd, catalogProperties);
            this.Title  = pd.Path;

            PdSaveEvent += dssFile.PdSave;
        }
Пример #8
0
        private void SetUnitsAndDataTypeInExcelFile(string sheet, PairedData record)
        {
            workbook.Worksheets[sheet].Cells[(int)PathLayout.StandardPath, 0].Value     = "Unit 1";
            workbook.Worksheets[sheet].Cells[(int)PathLayout.StandardPath + 1, 0].Value = "Unit 2";
            workbook.Worksheets[sheet].Cells[(int)PathLayout.StandardPath + 2, 0].Value = "Data Type 1";
            workbook.Worksheets[sheet].Cells[(int)PathLayout.StandardPath + 3, 0].Value = "Data Type 2";

            workbook.Worksheets[sheet].Cells[(int)PathLayout.StandardPath, 1].Value     = record.UnitsIndependent;
            workbook.Worksheets[sheet].Cells[(int)PathLayout.StandardPath + 1, 1].Value = record.UnitsDependent;
            workbook.Worksheets[sheet].Cells[(int)PathLayout.StandardPath + 2, 1].Value = record.TypeIndependent;
            workbook.Worksheets[sheet].Cells[(int)PathLayout.StandardPath + 3, 1].Value = record.TypeDependent;
        }
Пример #9
0
        private void GetPairedDataOrdinates(PairedData pd, string worksheet)
        {
            var vals   = Values(worksheet);
            var temp   = new List <double>();
            int column = 0;

            for (int i = ActiveSheetInfo.DataStartRowIndex; i < ActiveSheetInfo.SmallestColumnRowCount; i++)
            {
                temp.Add(vals[i, column].Number);
            }
            pd.Ordinates = temp.ToArray();
        }
Пример #10
0
        private void ImportPairedData(string destination, string worksheet)
        {
            string fileName = destination;

            File.Delete(fileName);
            PairedData pd = GetPairedData(worksheet);

            using (DssWriter w = new DssWriter(fileName))
            {
                w.Write(pd);
            }
        }
Пример #11
0
        private void GetPairedDataUnitsAndTypes(PairedData pd, string worksheet)
        {
            var info = ActiveSheetInfo;

            if (info.UnitsAndTypes == UnitsAndTypes.PD_UnitsAndTypes) // Time series has units and types
            {
                pd.UnitsIndependent = CellToString(workbook.Worksheets[worksheet].Cells[info.PathEndRowIndex + 1, 1]);
                pd.UnitsDependent   = CellToString(workbook.Worksheets[worksheet].Cells[info.PathEndRowIndex + 2, 1]);
                pd.TypeIndependent  = CellToString(workbook.Worksheets[worksheet].Cells[info.PathEndRowIndex + 3, 1]);
                pd.TypeDependent    = CellToString(workbook.Worksheets[worksheet].Cells[info.PathEndRowIndex + 4, 1]);
            }
        }
Пример #12
0
        private void GetPairedDataLabels(PairedData pd, string worksheet)
        {
            if (!HasLabels())
            {
                return;
            }

            pd.Labels = new List <string>();
            for (int i = ActiveSheetInfo.ValueStartColumnIndex; i < ActiveSheetInfo.ColumnCount; i++)
            {
                pd.Labels.Add(CellToString(workbook.Worksheets[worksheet].Cells[ActiveSheetInfo.DataStartRowIndex - 1, i]));
            }
        }
Пример #13
0
        public PairedData GetPairedData(string worksheet)
        {
            double[]        ordinates = GetPairedDataOrdinates(worksheet);
            List <double[]> vals      = GetPairedDataValues(worksheet);
            PairedData      pd        = new PairedData(ordinates, vals, new List <string>(), "", "", "", "", "/excel/import/plugin//e/pairedData" + RandomString(3));

            pd.UnitsDependent   = "unit1";
            pd.UnitsIndependent = "unit2";
            pd.TypeDependent    = "type1";
            pd.TypeIndependent  = "type2";
            pd.Labels           = new List <string>();
            return(pd);
        }
Пример #14
0
        private void SetPairedDataValueColumnsInExcelFile(string sheet, PairedData pd, int rowOffset, int colOffset)
        {
            for (int i = 0 + colOffset; i < pd.YCount + colOffset; i++)
            {
                workbook.Worksheets[sheet].Cells[rowOffset, i].Value = "Value " + (i - colOffset + 1).ToString();
            }

            for (int i = 0 + colOffset; i < pd.YCount + colOffset; i++)
            {
                for (int j = 0 + rowOffset + 1; j < pd.XCount + rowOffset + 1; j++)
                {
                    workbook.Worksheets[sheet].Cells[j, i].Value = pd.Values[i - colOffset][j - rowOffset - 1];
                }
            }
        }
Пример #15
0
        private void GetPairedDataPath(PairedData pd, string worksheet)
        {
            if (!ActiveSheetInfo.HasPath)
            {
                GetRandomPairedDataPath(pd, worksheet);
                return;
            }

            int column = 1;

            GetPath(pd, worksheet, column, ActiveSheetInfo.PathLayout);
            if (!PathPartsAreValid(pd.Path))
            {
                GetRandomPairedDataPath(pd, worksheet);
            }
        }
Пример #16
0
        public PairedData GetPairedData(string worksheet)
        {
            ActiveSheetInfo = SetActiveSheetInfo(worksheet);
            if (!isPairedData(worksheet))
            {
                return(new PairedData());
            }

            PairedData pd = new PairedData();

            GetPairedDataOrdinates(pd, worksheet);
            GetPairedDataValues(pd, worksheet);
            GetPairedDataPath(pd, worksheet);
            GetPairedDataUnitsAndTypes(pd, worksheet);
            GetPairedDataLabels(pd, worksheet);
            return(pd);
        }
Пример #17
0
        private void GetPairedDataValues(PairedData pd, string worksheet)
        {
            var vals = Values(worksheet);
            var temp = new List <double>();

            pd.Values = new List <double[]>();
            var offset = ActiveSheetInfo.HasIndex ? 2 : 1;

            for (int i = offset; i < ActiveSheetInfo.ColumnCount; i++)
            {
                for (int j = ActiveSheetInfo.DataStartRowIndex; j < ActiveSheetInfo.SmallestColumnRowCount; j++)
                {
                    temp.Add(vals[j, i].Number);
                }
                pd.Values.Add(temp.ToArray());
                temp.Clear();
            }
        }
Пример #18
0
        public void WriteTest()
        {
            var         filename = TestUtility.OutputPath + "write-test.xlsx";
            PairedData  pd1      = TestUtility.CreatePairedData(3, 10);
            ExcelWriter w        = new ExcelWriter(filename);

            w.Write(pd1, "Sheet1");

            ExcelReader r   = new ExcelReader(filename);
            PairedData  pd2 = r.GetPairedData("Sheet1");

            Assert.IsTrue(Enumerable.SequenceEqual(pd1.Ordinates, pd2.Ordinates));
            Assert.IsTrue(Enumerable.SequenceEqual(pd1.Values[0], pd2.Values[0]));
            Assert.IsTrue(Enumerable.SequenceEqual(pd1.Values[1], pd2.Values[1]));
            Assert.IsTrue(Enumerable.SequenceEqual(pd1.Values[2], pd2.Values[2]));

            File.Delete(filename);
        }
Пример #19
0
 private void GetPath(PairedData pd, string worksheet, int column, PathLayout pathLayout)
 {
     pd.Path = new DssPath();
     if (pathLayout == PathLayout.StandardPath)
     {
         pd.Path.Apart = CellToString(workbook.Worksheets[worksheet].Cells[0, column]);
         pd.Path.Bpart = CellToString(workbook.Worksheets[worksheet].Cells[1, column]);
         pd.Path.Cpart = CellToString(workbook.Worksheets[worksheet].Cells[2, column]);
         pd.Path.Epart = CellToString(workbook.Worksheets[worksheet].Cells[4, column]);
         pd.Path.Fpart = CellToString(workbook.Worksheets[worksheet].Cells[5, column]);
     }
     else if (pathLayout == PathLayout.PathWithoutDPart)
     {
         pd.Path.Apart = CellToString(workbook.Worksheets[worksheet].Cells[0, column]);
         pd.Path.Bpart = CellToString(workbook.Worksheets[worksheet].Cells[1, column]);
         pd.Path.Cpart = CellToString(workbook.Worksheets[worksheet].Cells[2, column]);
         pd.Path.Epart = CellToString(workbook.Worksheets[worksheet].Cells[3, column]);
         pd.Path.Fpart = CellToString(workbook.Worksheets[worksheet].Cells[4, column]);
     }
 }
Пример #20
0
 public string POST(string url, PairedData pData, string referer)
 {
     return Navigate("POST", url, pData.ToPOSTStr(), referer, true);
 }
 public void PdSave(PairedData pd)
 {
     _writer.Write(pd);
 }
Пример #22
0
        //private void GetPairedDataTypes(PairedData pd, string worksheet)
        //{
        //    string typeI = "Independent Type";
        //    string typeD = "Dependent Type";
        //    if (HasTypes())
        //    {
        //        int adjustment1 = 2;
        //        int adjustment2 = 1;
        //        int typeIIndex = (int)ActiveSheetInfo.PathLayout - adjustment1;
        //        int typeDIndex = (int)ActiveSheetInfo.PathLayout - adjustment2;
        //        int column = 1;
        //        typeI = CellToString(workbook.Worksheets[worksheet].Cells[typeIIndex, column]);
        //        typeD = CellToString(workbook.Worksheets[worksheet].Cells[typeDIndex, column]);
        //    }
        //    pd.TypeIndependent = typeI;
        //    pd.TypeDependent = typeD;
        //}

        //private void GetPairedDataUnits(PairedData pd, string worksheet)
        //{
        //    string unitI = "Independent Unit";
        //    string unitD = "Dependent Unit";
        //    if (HasUnits())
        //    {
        //        int adjustment1 = 2;
        //        int adjustment2 = 1;
        //        if (HasTypes())
        //        {
        //            adjustment1 = 4;
        //            adjustment2 = 3;
        //        }
        //        int unitIIndex = (int)ActiveSheetInfo.PathLayout - adjustment1;
        //        int unitDIndex = (int)ActiveSheetInfo.PathLayout - adjustment2;
        //        int column = 1;
        //        unitI = CellToString(workbook.Worksheets[worksheet].Cells[unitIIndex, column]);
        //        unitD = CellToString(workbook.Worksheets[worksheet].Cells[unitDIndex, column]);
        //    }
        //    pd.UnitsIndependent = unitI;
        //    pd.UnitsDependent = unitD;
        //}

        private DssPath GetRandomPairedDataPath(PairedData pd, string worksheet)
        {
            return(new DssPath("import", Path.GetFileNameWithoutExtension(workbook.FullName), worksheet, "", "excel", "pairedData" + ExcelTools.RandomString(3)));
        }
Пример #23
0
 public void Write(PairedData record, int sheetIndex)
 {
     Write(record, workbook.Worksheets[sheetIndex].Name);
 }
Пример #24
0
 public string POST(string url, PairedData pData)
 {
     return Navigate("POST", url, pData.ToPOSTStr(), null, true);
 }
Пример #25
0
        private void ImportPairedData(ExcelReader reader)
        {
            PairedData pd = reader.GetPairedData(reader.workbook.ActiveWorksheet.Name);

            WriteRecord(pd);
        }